登录 注册
当前位置:主页 > 资源下载 > 28 > C#.net PLC通讯下载

C#.net PLC通讯下载

  • 更新:2024-05-20 14:46:38
  • 大小:1.28MB
  • 推荐:★★★★★
  • 来源:网友上传分享
  • 类别:C# - 后端
  • 格式:ZIP

资源介绍

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;