资源介绍
byte[] dd = { 0x10, 0x02, 0x00, 0x5C, 0x5E, 0x16 };
// serialPort1.Write(dd, 0, dd.Length);
axMSComm1.Output = dd;
System.Threading.Thread.Sleep(100);
string q = q8 + q7 + q6 + q5 + q4+ q3 + q2+ q1;
int dataer = Convert.ToInt32(q, 2);//二进制转十进制
string datah = Convert.ToString(dataer, 16);//十进制转十六进制
while (datah.Length < 2) datah = "0"+datah;
string temp = "02007C320100000000000E00050501120A1002000100008200000000040008"+datah;
int sum = 0;
for (int i = 0; i < (temp.Length / 2); i++)//求校验
{
int c=Convert .ToInt32 (temp.Substring ((i*2),2),16);
sum = sum + c;
}
string check = Convert.ToString(sum, 16);
string checkdata = check.Substring(check.Length - 2, 2);//校验和后两位
//textBox1.Text = checkdata;
checkdata = checkdata.ToUpper();
temp = "68202068"+temp+checkdata+"16" ;
byte[] outdata3 = new byte[38];
for (int i = 0; i < (temp.Length / 2); i++)
{
outdata3[i] = Convert.ToByte((temp.Substring(i * 2, 2)), 16);
}
//serialPort1.Write(outdata3, 0, outdata3.Length);
axMSComm1.Output = outdata3;
- 上一篇: java笔试题以及答案
- 下一篇: C#使用S7.Net,Sharp7连接读写PLC