using PCHMI;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
using static System.Net.Mime.MediaTypeNames;

namespace CowainHmi
{
    public class StringHelper
    {
        /// <summary>
        /// 写西门子字符串
        /// </summary>
        public static void SendSiemensString(int pid, string address, byte maxLen, string val)
        {
            var addr = new VAR().GADDR(pid, address);  //获取真实地址
            string text = addr.Substring(0, 1);
            int num8;
            if (addr.Substring(0, 2) == "DB")
            {
                string[] array2 = addr.Split(new char[] { '.' });
                text = array2[0] + ".";
                num8 = Convert.ToInt32(array2[1]);
            }
            else
            {
                num8 = Convert.ToInt32(addr.Substring(1, addr.Length - 1));
            }

            ushort result = BitConverter.ToUInt16(new byte[]
                            {
                                (byte)new PClass().GetLength(val),  //实际字符串长度
                                maxLen   //最大字符串长度
                            }, 0);
            PCHMI.RT.SEND_UINT16(pid, addr, result); //把最大字符串长度，实际字符串长度发送给PLC
            DCON.Send_Control(pid, text + (num8 + 2).ToString(), "字符串写入", val);
        }


    }
}
