Files
6150-HMI/CowainHmi/Helper/StringHelper.cs
2026-01-15 15:06:36 +08:00

45 lines
1.4 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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);
}
}
}