If MyStatus = 0 Then
STATUS.Text = \串口忙,请稍侯\ Else
show_status (MyStatus) End If End Sub
'Process the Slave Read Response Message 'Modbus_Master SlaveReadResponse Event Handler
Private Sub MbMasterV71_SlaveReadResponse(ByVal hConnect As Long) Dim MyData As Long Dim i As Integer
' Read the data returned from the slave ' and update the text controls For i = 0 To Length - 1
MyStatus = MbMasterV71.ReadResults(hConnect, Slave, Cmd, Address + i, MyData)
show_status (MyStatus) If MyStatus = 0 Then 'Text1(i).Text = MyData
If i = 0 Or i = 8 Or i = 16 Then Text1(i).Text = MyData * 系数 End If
If i = 2 Or i = 10 Or i = 18 Then Text1(i).Text = MyData * 系数 End If
If i = 4 Or i = 12 Or i = 20 Or i = 6 Or i = 14 Or i = 22 Then Text1(i).Text = MyData * 系数 End If
If i = 28 Or i = 30 Then '3P,3Q
Text1(i).Text = MyData * 系数 End If
If i = 29 Then 'cosq
Text1(i).Text = MyData * 系数 End If
If i = 27 Then 'F
Text1(i).Text = MyData * 系数 End If
If i = 1 Or i = 5 Or i = 7 Or i = 9 Or i = 13 Or i = 15 Or i = 17 Or i = 21 Or i = 23 Or i = 25 Or i = 23 Or i = 26 Or i = 31 Then Text1(i).Text = 0 '没有测量的量默认为0 End If ' Else
' Text1(i).Text = \ End If Next i End Sub
Private Sub WRITEMODBUS_Click() Dim IsRegister As Boolean Dim i As Integer Dim junk As Integer
Slave = NODEADDRESS.Text Address = WRITEADDRESS.Text
Length = WRITELENGTH.Text If Length > 200 Then Length = 200 End If
For i = 0 To Length - 1
junk = MbMasterV71.FillWriteBuffer(MyHandle, i, PATTERN.Text) Next i
If POINTTYPE.Text < 2 Then If Length = 1 Then
Cmd = 5 'write single coil Else
Cmd = 15 'write multiple coils End If Else
If Length = 1 Then
Cmd = 6 'write single register Else
Cmd = 16 'write multiple registers End If End If
MyStatus = MbMasterV71.WRITEMODBUS(MyHandle, Slave, Cmd, Address, Length)
' Make sure the write request was transmitted If MyStatus = 0 Then
STATUS.Text = \串口忙,请稍侯\ Else
show_status (MyStatus) End If
End Sub
'Process the Slave Write Response Message 'Modbus_Master SlaveWriteResponse Event Handler
Private Sub MbMasterV71_SlaveWriteResponse(ByVal hConnect As Long) 'read the results of the write request
MyStatus = MbMasterV71.WriteResults(hConnect, Slave, Cmd, Address, Length)
' and update the status display show_status (MyStatus) End Sub
Private Sub LoopBackTst_Click() Slave = NODEADDRESS.Text Cmd = 8
MyStatus = MbMasterV71.FillUserMsgBuffer(MyHandle, 0, Slave) MyStatus = MbMasterV71.FillUserMsgBuffer(MyHandle, 1, Cmd) MyStatus = MbMasterV71.FillUserMsgBuffer(MyHandle, 2, 0) MyStatus = MbMasterV71.FillUserMsgBuffer(MyHandle, 3, 0) MyStatus = MbMasterV71.FillUserMsgBuffer(MyHandle, 4, 0) MyStatus = MbMasterV71.FillUserMsgBuffer(MyHandle, 5, 0)
MyStatus = MbMasterV71.SendUserMsg(MyHandle, 6) 'Check the status to make sure the request went out. If MyStatus = 0 Then
STATUS.Text = \串口忙,请稍侯\ Else
show_status (MyStatus)
End If End Sub
Private Sub MbMasterV71_UserMsgResponse(ByVal hConnect As Long, ByVal NumberOfBytes As Long) Dim temp As Integer
If NumberOfBytes > 0 Then
For i = 0 To NumberOfBytes - 1
MyStatus = MbMasterV71.ReadUserMsgResponse(hConnect, i, temp)
LoopbackMsg(i) = temp Next i
STATUS.Text = LoopbackMsg End If End Sub

