|
|
|
|
@ -27,6 +27,38 @@ namespace Khd.Core.Plc
|
|
|
|
|
plc.Write(address, GetValue(len, valueString));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 写入RFID
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="plc"> plc </param>
|
|
|
|
|
/// <param name="address"> 读取地址 </param>
|
|
|
|
|
/// <param name="len"> 长度 </param>
|
|
|
|
|
/// <returns> 读取到的RFID </returns>
|
|
|
|
|
public static void WriteRFID(this Plc.S7.Plc plc, string address, string value,int len = 15)
|
|
|
|
|
{
|
|
|
|
|
string[] adds = address.Split(".");
|
|
|
|
|
int db = int.Parse(adds[0].Replace("DB", ""));
|
|
|
|
|
int startByteAdr = int.Parse(adds[1].Replace("DBX", ""));
|
|
|
|
|
|
|
|
|
|
// 将 value 转换为字节数组,确保其长度符合要求
|
|
|
|
|
byte[] byteArray = Encoding.ASCII.GetBytes(value);
|
|
|
|
|
if (byteArray.Length > len)
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentException($"Value length exceeds the specified length of {len} bytes.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 填充字节数组到指定长度
|
|
|
|
|
byte[] dataToWrite = new byte[len];
|
|
|
|
|
Array.Copy(byteArray, dataToWrite, byteArray.Length);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
plc.Write(S7.DataType.DataBlock, db, startByteAdr, dataToWrite);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 读取RFID
|
|
|
|
|
/// </summary>
|
|
|
|
|
|