16,722
社区成员




serialPort1.NewLine = "\r";
serialPort1.Open();
serialPort1.WriteLine("%01#WCSR00011**");//控制开关R0001的打开
System.Threading.Thread.Sleep(100);
serialPort1.WriteLine("%01#WCSR00010**");//控制开关R0001的关闭
Dim Spiecal_Text_1 As String = "%01#WCSR030" & (i + 1).ToString & "1"
Dim Spiecal_Text_0 As String = "%01#WCSR030" & (i + 1).ToString & "0"
Dim PLC_Command_1 As String = Spiecal_Text_1 & calculate_for_plc(Spiecal_Text_1) & vbCr
Dim PLC_Command_0 As String = Spiecal_Text_0 & calculate_for_plc(Spiecal_Text_0) & vbCr
SerialPort1.WriteLine(PLC_Command_1)
Thread.Sleep(10)
SerialPort1.WriteLine(PLC_Command_0)
'将asc码后转换成16进制后相与
Function calculate_for_plc(ByVal str)
Dim s As String = Nothing
For i As Integer = 1 To Len(str)
s = s Xor AscW(Mid(str, i, 1))
Next
Return Hex(s)
End Function