嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300
本次赞助数额为: 2 元微信扫码支付:2 元
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
c#利用modbus rtu协议通讯实现RFID的读写
//读取标签数据
public bool ReadFRIDLabelData(out string value)
{
bool flag = false;
value = "";
try
{
byte[] req = new byte[8];
req[0] = 0x02;
req[1] = 0x03;
req[2] = 0x00;
req[3] = 0x0A;
req[4] = 0x00;
req[5] = 0x04;
ushort crc = AIDACrc.crc16(req, 6);
req[6] = (byte)(crc >> 8);
req[7] = (byte)(crc & 0x00FF);
if (this.Com.IsOpen)
{
flag = this.Write(req, req.Length);
}
if (flag)
{
int timeout = 500;
byte repdatacount = 0x08;
byte[] rep_head = new byte[13];
flag = this.Read(timeout, rep_head , rep_head .Length);
if (flag)
{
if (repdatacount == rep_head[2])
{
byte[] rep_value = new byte[8];
for (var i = 0; i < rep_value.Length; i )
{
rep_value[i] = rep_head[i 3];
value = rep_value[i].ToString("X2");
}
}
}
}
}
catch
{
throw;
}
return flag;
}
public bool ReadFRIDLabelDataTest(out string value, byte addr)
{
bool flag = false;
value = "";
try
{
byte[] req = new byte[8];
req[0] = 0x02;
req[1] = 0x03;
req[2] = 0x00;
req[3] = addr;
req[4] = 0x00;
req[5] = 0x04;
ushort crc = AIDACrc.crc16(req, 6);
req[6] = (byte)(crc >> 8);
req[7] = (byte)(crc & 0x00FF);
if (this.Com.IsOpen)
{
flag = this.Write(req, req.Length);
}
if (flag)
{
int timeout = 500;
byte repdatacount = 0x08;
byte[] rep_head = new byte[13];
flag = this.Read(timeout, rep_head, rep_head.Length);
if (flag)
{
if (repdatacount == rep_head[2])
{
byte[] rep_value = new byte[8];
for (var i = 0; i < rep_value.Length; i )
{
rep_value[i] = rep_head[i 3];
value = rep_value[i].ToString("X2");
}
}
}
}
}
catch
{
throw;
}
return flag;
}