4
« on: July 17, 2014, 01:53:23 PM »
There are some small tweaks necessary to the ModbusRTUCom.vb to use it with the Horner OCS HE-XT102:
In SendData:
If Not InternalRequest Or (DLL(MyDLLInstance).SendQueDepth < 10) Then
DLL(MyDLLInstance).SendRTUFrame(FinsF)
'Added for Horner
Threading.Thread.Sleep(100)
'End of add for Horner
Return True
Else
Return False
End If
In Write function:
Dim PDU As New ModbusPDUFrame(address.WriteFunctionCode, address, dataPacket.ToArray)
Dim RTUPacket As MfgControl.AdvancedHMI.Drivers.ModbusRTU.ModbusRTUFrame
'Modified to work with the Horner
If address.BitsPerElement = 16 Then
PDU.EncapsulatedData(2) = PDU.EncapsulatedData(5)
PDU.EncapsulatedData(3) = PDU.EncapsulatedData(6)
Else
PDU.EncapsulatedData(2) = PDU.EncapsulatedData(5)
End If
'End of Horner modification
RTUPacket = New ModbusRTUFrame(m_StationAddress, PDU, CurrentTNS)
SendData(RTUPacket, address.InternallyRequested)
Return New String() {"0"}
'End SyncLock
End Function
Then in the Horner put in the following attached 2 rungs:
I used VB.Net 2013 and the components (integer and boolean) work. Also, the following commands work:
Dim strResult(4) As String
strResult = ModbusRTUCom2.Read("43901", 1) 'reads %R901
strResult = ModbusRTUCom2.Read("03009", 1) 'reads %M9
ModbusRTUCom2.Write("43902", "12345") 'writes %R902
ModbusRTUCom2.Write("03017", "0") 'writes %M17
Archie probably has a cleaner approach but this works.