緣分2013
級別: 探索解密
|
RT,小弟由于剛接觸VB不久,用VB6.0與FX2N通訊,向PLC的D寫入值老是不對,不知道是不是格式不對,我是利用MSComm控件通訊的。。。outstring = Chr(&O2) + "1" + CStr(qiuhe) + "02" + CStr(xieru) + Chr(&O3) + hejiaoyan |
---|---|
|
tk758
級別: 略有小成
|
Private Sub Command1_Click() '寫入D0=0 Dim Address As String Dim SenData As String MSComm1.Settings = "9600,E,7,1" MSComm1.InputMode = comInputModeText Address = "1" + "1000" + "02" + "0000" + Chr(3) SenData = Chr(2) & Address & SumChk(Address) MSComm1.PortOpen = True MSComm1.Output = SenData End Sub Private Function SumChk(Dats$) As String 'CheckSum Dim i& Dim CHK& For i = 1 To Len(Dats) CHK = CHK + Asc(Mid(Dats, i, 1)) Next i SumChk = Right(Hex$(CHK), 2) End Function |
---|---|
|
tk758
級別: 略有小成
|
寫入的數據16進制數據, 是先寫低字節, .再寫高字節. 因此如寫"1"進去PLC, 應寫成"0100", 寫"255"進去PLC, 應寫成"FF00" |
---|---|
|