byte[]dd={0x10,0x02,0x00,0x5C,0x5E,0x16};//serialPort1.Write(dd,0,dd.Length);axMSComm1.Output=dd;System.Threading.Thread.Sleep(100);stringq=q8+q7+q6+q5+q4+q3+q2+q1;intdataer=Convert.ToInt32(q,2);//二进制转十进制stringdatah=Convert.ToString(dataer,16);//十进制转十六进制while(datah.Length<2)datah="0"+datah;stringtemp="02007C320100000000000E00050501120A1002000100008200000000040008"+datah;intsum=0;for(inti=0;i<(temp.Length/2);i++)//求校验{intc=Convert.ToInt32(temp.Substring((i*2),2),16);sum=sum+c;}stringcheck=Convert.ToString(sum,16);stringcheckdata=check.Substring(check.Length-2,2);//校验和后两位//textBox1.Text=checkdata;checkdata=checkdata.ToUpper();temp="68202068"+temp+checkdata+"16";byte[]outdata3=newbyte[38];for(inti=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;
2023/8/29 15:31:55
1.28MB
PLC通讯
1