ParsePacket() works

This commit is contained in:
Jonny007-MKD 2014-05-30 15:14:33 +00:00
parent 010e10f567
commit 95304c9216
21 changed files with 803 additions and 700 deletions

View file

@ -1,17 +1,17 @@
;CANoe Version |4|7|1|55220 ModbusNet ;CANoe Version |4|7|1|38833 ModbusNet
Version: 8.2.40 Build 40 Version: 8.2.40 Build 40
32 PRO 32 PRO
10 10
APPDIR Vector.CANoe.SignalGenerators.DLL
Vector.CANoe.SignalGenerators, Version=8.2.40.0, Culture=neutral, PublicKeyToken=null
Vector.CANoe.SignalGenerators.ComponentWrapper
1
1.0.1
APPDIR Vector.CANoe.Debugger.DLL APPDIR Vector.CANoe.Debugger.DLL
Vector.CANoe.Debugger, Version=8.2.40.0, Culture=neutral, PublicKeyToken=null Vector.CANoe.Debugger, Version=8.2.40.0, Culture=neutral, PublicKeyToken=null
Vector.CANoe.Debugger.DebuggerComponent Vector.CANoe.Debugger.DebuggerComponent
2 1
1.0.0 1.0.0
APPDIR Vector.CANoe.SignalGenerators.DLL
Vector.CANoe.SignalGenerators, Version=8.2.40.0, Culture=neutral, PublicKeyToken=null
Vector.CANoe.SignalGenerators.ComponentWrapper
2
1.0.1
VGlobalConfiguration 1 Begin_Of_Object VGlobalConfiguration 1 Begin_Of_Object
17 17
VGlobalParameters 2 Begin_Of_Object VGlobalParameters 2 Begin_Of_Object
@ -742,15 +742,15 @@ Begin_Of_Multi_Line_String
Copyright (c) 2001-2006 Actipro Software LLC. All rights reserved. Copyright (c) 2001-2006 Actipro Software LLC. All rights reserved.
http://www.ActiproSoftware.com/Products/DotNet/ http://www.ActiproSoftware.com/Products/DotNet/
--><ToolWindowLayout Version="1.0"><LayoutData><HostContainerControl><ToolWindowContainer Dock="Right" Size="645, 393" SelectedToolWindowGuid="859d3aae-7aff-47f2-8ca4-bb7d01f32282"><ToolWindow Key="{224229E5-10CA-425F-8B6F-C213CD04C44F}" Guid="859d3aae-7aff-47f2-8ca4-bb7d01f32282" DockedSize="682, 358" FloatingLocation="347, 323" FloatingSize="890, 483" HasOptions="False" ImageIndex="-1" Text="Simulationsaufbau" TitleBarText="Simulationsaufbau"><AutoHideStateInfo RootDock="Right" /><DockedInsideHostStateInfo RootDock="Right" IsAttached="False"><DockedBy Guid="ac9be154-bd12-4ff9-b255-03e05277dbe2" RootDock="Bottom" DockOperationType="TopOuter" IsTopMost="True" /><DockedBy Guid="7f29b491-3ada-4572-b140-b422651d6fed" RootDock="Top" DockOperationType="BottomOuter" IsTopMost="True" /></DockedInsideHostStateInfo><DockedOutsideHostStateInfo IsAttached="False" /></ToolWindow></ToolWindowContainer><ToolWindowContainer Dock="Left" Size="448, 393" SelectedToolWindowGuid="87323901-fe96-4011-a82f- --><ToolWindowLayout Version="1.0"><LayoutData><HostContainerControl><ToolWindowContainer Dock="Right" Size="645, 393" SelectedToolWindowGuid="859d3aae-7aff-47f2-8ca4-bb7d01f32282"><ToolWindow Key="{224229E5-10CA-425F-8B6F-C213CD04C44F}" Guid="859d3aae-7aff-47f2-8ca4-bb7d01f32282" DockedSize="641, 358" FloatingLocation="347, 323" FloatingSize="890, 483" HasOptions="False" ImageIndex="-1" Text="Simulationsaufbau" TitleBarText="Simulationsaufbau"><AutoHideStateInfo RootDock="Right" /><DockedInsideHostStateInfo RootDock="Right" IsAttached="False"><DockedBy Guid="ac9be154-bd12-4ff9-b255-03e05277dbe2" RootDock="Bottom" DockOperationType="TopOuter" IsTopMost="True" /><DockedBy Guid="7f29b491-3ada-4572-b140-b422651d6fed" RootDock="Top" DockOperationType="BottomOuter" IsTopMost="True" /></DockedInsideHostStateInfo><DockedOutsideHostStateInfo IsAttached="False" /></ToolWindow></ToolWindowContainer><ToolWindowContainer Dock="Left" Size="448, 393" SelectedToolWindowGuid="87323901-fe96-4011-a82f-
kPersistNoLineBreak kPersistNoLineBreak
0e1b8627507a"><ToolWindow Key="{E6849C53-63F6-4A32-9B1C-7018D50DDE09}" Guid="87323901-fe96-4011-a82f-0e1b8627507a" DockedSize="472, 161" FloatingLocation="6, 66" FloatingSize="677, 213" HasOptions="False" ImageIndex="-1" Text="Daten" TitleBarText="Daten"><AutoHideStateInfo RootDock="Left" /><DockedInsideHostStateInfo RootDock="Left" IsAttached="False"><DockedBy Guid="ac9be154-bd12-4ff9-b255-03e05277dbe2" RootDock="Bottom" DockOperationType="TopOuter" IsTopMost="True" /><DockedBy Guid="7f29b491-3ada-4572-b140-b422651d6fed" RootDock="Top" DockOperationType="BottomOuter" IsTopMost="True" /></DockedInsideHostStateInfo><DockedOutsideHostStateInfo IsAttached="False" /></ToolWindow></ToolWindowContainer><ToolWindowContainer Dock="Bottom" Size="1192, 285" SelectedToolWindowGuid="ac9be154-bd12-4ff9-b255-03e05277dbe2"><ToolWindow Key="{28077F35-C142-4ACC-B040-1BF0AB026C11}" Guid="ac9be154-bd12-4ff9-b255-03e05277dbe2" DockedSize="201, 281" FloatingLocation="111, 442" FloatingSize="1192, 514" Has 0e1b8627507a"><ToolWindow Key="{E6849C53-63F6-4A32-9B1C-7018D50DDE09}" Guid="87323901-fe96-4011-a82f-0e1b8627507a" DockedSize="444, 161" FloatingLocation="6, 66" FloatingSize="677, 213" HasOptions="False" ImageIndex="-1" Text="Daten" TitleBarText="Daten"><AutoHideStateInfo RootDock="Left" /><DockedInsideHostStateInfo RootDock="Left" IsAttached="False"><DockedBy Guid="ac9be154-bd12-4ff9-b255-03e05277dbe2" RootDock="Bottom" DockOperationType="TopOuter" IsTopMost="True" /><DockedBy Guid="7f29b491-3ada-4572-b140-b422651d6fed" RootDock="Top" DockOperationType="BottomOuter" IsTopMost="True" /></DockedInsideHostStateInfo><DockedOutsideHostStateInfo IsAttached="False" /></ToolWindow></ToolWindowContainer><ToolWindowContainer Dock="Bottom" Size="1192, 285" SelectedToolWindowGuid="ac9be154-bd12-4ff9-b255-03e05277dbe2"><ToolWindow Key="{28077F35-C142-4ACC-B040-1BF0AB026C11}" Guid="ac9be154-bd12-4ff9-b255-03e05277dbe2" DockedSize="201, 281" FloatingLocation="111, 442" FloatingSize="1192, 514" Has
kPersistNoLineBreak kPersistNoLineBreak
Options="False" ImageIndex="-1" Text="Trace" TitleBarText="Trace"><AutoHideStateInfo RootDock="Bottom" /><DockedInsideHostStateInfo RootDock="Bottom" IsAttached="False" /><DockedOutsideHostStateInfo IsAttached="False" /></ToolWindow></ToolWindowContainer><ToolWindowContainer Dock="Top" Size="1192, 227" SelectedToolWindowGuid="7f29b491-3ada-4572-b140-b422651d6fed"><ToolWindow Key="{8F3DFCAC-9CCB-45C2-AF10-5DEC039B5956}" Guid="7f29b491-3ada-4572-b140-b422651d6fed" DockedSize="201, 223" FloatingLocation="6, 433" FloatingSize="300, 180" HasOptions="False" ImageIndex="-1" Text="Write" TitleBarText="Write"><AutoHideStateInfo RootDock="Top" /><DockedInsideHostStateInfo RootDock="Top" IsAttached="False" /><DockedOutsideHostStateInfo IsAttached="False" /></ToolWindow></ToolWindowContainer></HostContainerControl><AutoHide Dock="Left" /><AutoHide Dock="Right" /><AutoHide Dock="Top" /><AutoHide Dock="Bottom" /><TabbedDocuments Orientation="Horizontal" /><FloatingContainers /><Hidden><ToolWindow K Options="False" ImageIndex="-1" Text="Trace" TitleBarText="Trace"><AutoHideStateInfo RootDock="Bottom" /><DockedInsideHostStateInfo RootDock="Bottom" IsAttached="False" /><DockedOutsideHostStateInfo IsAttached="False" /></ToolWindow></ToolWindowContainer><ToolWindowContainer Dock="Top" Size="1192, 227" SelectedToolWindowGuid="7f29b491-3ada-4572-b140-b422651d6fed"><ToolWindow Key="{8F3DFCAC-9CCB-45C2-AF10-5DEC039B5956}" Guid="7f29b491-3ada-4572-b140-b422651d6fed" DockedSize="201, 223" FloatingLocation="6, 433" FloatingSize="300, 180" HasOptions="False" ImageIndex="-1" Text="Write" TitleBarText="Write"><AutoHideStateInfo RootDock="Top" /><DockedInsideHostStateInfo RootDock="Top" IsAttached="False" /><DockedOutsideHostStateInfo IsAttached="False" /></ToolWindow></ToolWindowContainer></HostContainerControl><AutoHide Dock="Left" /><AutoHide Dock="Right" /><AutoHide Dock="Top" /><AutoHide Dock="Bottom" /><TabbedDocuments Orientation="Horizontal" /><FloatingContainers /><Hidden><ToolWindow K
kPersistNoLineBreak kPersistNoLineBreak
ey="{F5E09530-AAE7-48d9-B925-CEF5027AA97D}" Guid="b2726676-2b89-4fee-b1a3-2be7bfbdec73" State="DockableInsideHost" DockedSize="176, 228" FloatingLocation="53, 379" FloatingSize="325, 380" HasOptions="False" ImageIndex="-1" Text="Symbol Explorer" TitleBarText="Symbol Explorer"><AutoHideStateInfo RootDock="Left" /><DockedInsideHostStateInfo RootDock="Left" IsAttached="False"><DockedBy Guid="87323901-fe96-4011-a82f-0e1b8627507a" RootDock="Left" DockOperationType="RightOuter" IsTopMost="True" /><DockedBy Guid="ac9be154-bd12-4ff9-b255-03e05277dbe2" RootDock="Bottom" DockOperationType="TopOuter" IsTopMost="True" /><DockedBy Guid="7f29b491-3ada-4572-b140-b422651d6fed" RootDock="Top" DockOperationType="BottomOuter" IsTopMost="True" /></DockedInsideHostStateInfo><DockedOutsideHostStateInfo IsAttached="False" /></ToolWindow><ToolWindow Key="{49714911-9568-49CC-A9CE-3B0905658C4A}" Guid="db27ffca-d17e-40f0-a70b-be70fe5eb4ec" State="DockableInsideHost" DockedSize="381, 0" FloatingLocation="1151, 7 ey="{F5E09530-AAE7-48d9-B925-CEF5027AA97D}" Guid="b2726676-2b89-4fee-b1a3-2be7bfbdec73" State="DockableInsideHost" DockedSize="176, 228" FloatingLocation="53, 379" FloatingSize="325, 380"><AutoHideStateInfo RootDock="Left" /><DockedInsideHostStateInfo RootDock="Left" IsAttached="False"><DockedBy Guid="87323901-fe96-4011-a82f-0e1b8627507a" RootDock="Left" DockOperationType="RightOuter" IsTopMost="True" /><DockedBy Guid="ac9be154-bd12-4ff9-b255-03e05277dbe2" RootDock="Bottom" DockOperationType="TopOuter" IsTopMost="True" /><DockedBy Guid="7f29b491-3ada-4572-b140-b422651d6fed" RootDock="Top" DockOperationType="BottomOuter" IsTopMost="True" /></DockedInsideHostStateInfo><DockedOutsideHostStateInfo IsAttached="False" /></ToolWindow><ToolWindow Key="{49714911-9568-49CC-A9CE-3B0905658C4A}" Guid="db27ffca-d17e-40f0-a70b-be70fe5eb4ec" State="DockableInsideHost" DockedSize="381, 0" FloatingLocation="1151, 79" FloatingSize="300, 180"><AutoHideStateInfo RootDock="Right" /><DockedInsideHostStateIn
kPersistNoLineBreak kPersistNoLineBreak
9" FloatingSize="300, 180"><AutoHideStateInfo RootDock="Right" /><DockedInsideHostStateInfo RootDock="Right" IsAttached="False" /><DockedOutsideHostStateInfo IsAttached="False" /></ToolWindow></Hidden></LayoutData><CustomData /></ToolWindowLayout> fo RootDock="Right" IsAttached="False" /><DockedOutsideHostStateInfo IsAttached="False" /></ToolWindow></Hidden></LayoutData><CustomData /></ToolWindowLayout>
End_Of_Serialized_Data 3 End_Of_Serialized_Data 3
End_Of_Object VDesktop 3 End_Of_Object VDesktop 3
VDesktop 3 Begin_Of_Object VDesktop 3 Begin_Of_Object
@ -1596,7 +1596,10 @@ End_Of_Serialized_Data 14
16 16
0 0
17 17
0 1
14
ver=2: FT
End_Of_Serialized_Data 14
18 18
0 0
19 19
@ -1611,29 +1614,29 @@ End_Of_Serialized_Data 14
22 22
1 1
14 14
ver=2: FF ver=2: FT
End_Of_Serialized_Data 14 End_Of_Serialized_Data 14
23 23
1 1
14 14
ver=2: FF ver=2: FT
End_Of_Serialized_Data 14 End_Of_Serialized_Data 14
24 24
1 1
14 14
ver=2: FF ver=2: FT
End_Of_Serialized_Data 14 End_Of_Serialized_Data 14
25 25
0 0
26 26
1 1
14 14
ver=2: FF ver=2: FT
End_Of_Serialized_Data 14 End_Of_Serialized_Data 14
27 27
1 1
14 14
ver=2: FF ver=2: FT
End_Of_Serialized_Data 14 End_Of_Serialized_Data 14
0 0
2 2
@ -3462,7 +3465,7 @@ VTraceControlFixedModeExpansionItems 15 Begin_Of_Object
0 0
End_Of_Object VTraceControlFixedModeExpansionItems 15 End_Of_Object VTraceControlFixedModeExpansionItems 15
14 14
J:\HsKA\NB7\Bachelorthesis\CANoe\Modbus J:\HsKA\NB7\Bachelorthesis\CANoe\Modbus-DLL
End_Of_Serialized_Data 14 End_Of_Serialized_Data 14
14 14
Trace Window Trace Window
@ -4599,7 +4602,7 @@ End_Of_Object VGrMnBox 3
VDOLocalInfoStruct 3 Begin_Of_Object VDOLocalInfoStruct 3 Begin_Of_Object
3 3
1 1
195 199
VDAOBus 4 Begin_Of_Object VDAOBus 4 Begin_Of_Object
1 1
1 1
@ -4621,7 +4624,7 @@ VConfigurationRoot 8 Begin_Of_Object
End_Of_Object VConfigurationRoot 8 End_Of_Object VConfigurationRoot 8
<VFileName V4 QL> 1 "include\CAPL\ModbusClient.can" <VFileName V4 QL> 1 "include\CAPL\ModbusClient.can"
1 1
J:\HsKA\NB7\Bachelorthesis\CANoe\Modbus\include\CAPL\ModbusClient.cbf J:\HsKA\NB7\Bachelorthesis\CANoe\Modbus-DLL\include\CAPL\ModbusClient.cbf
Client_2 Client_2
Modbus Modbus
5 5
@ -4711,7 +4714,7 @@ End_Of_Object VIPBStackSetting 8
NDebugger::VDebuggerHost 8 Begin_Of_Object NDebugger::VDebuggerHost 8 Begin_Of_Object
2 2
0 0
26 27
NDebugger::VFile 9 Begin_Of_Object NDebugger::VFile 9 Begin_Of_Object
1 1
<VFileName V4 QL> 1 "ModbusTcpCommon.cin" <VFileName V4 QL> 1 "ModbusTcpCommon.cin"
@ -4842,6 +4845,11 @@ NDebugger::VFile 9 Begin_Of_Object
<VFileName V4 QL> 1 "include\CAPL\include\UdpCommon.cin" <VFileName V4 QL> 1 "include\CAPL\include\UdpCommon.cin"
41 41
End_Of_Object NDebugger::VFile 9 End_Of_Object NDebugger::VFile 9
NDebugger::VFile 9 Begin_Of_Object
1
<VFileName V4 QL> 1 "include\CAPL\include\ModbusStructs.cin"
42
End_Of_Object NDebugger::VFile 9
VNETStandaloneComponent 9 Begin_Of_Object VNETStandaloneComponent 9 Begin_Of_Object
1 1
VNETControlBox 10 Begin_Of_Object VNETControlBox 10 Begin_Of_Object
@ -5114,7 +5122,7 @@ VBoxRoot 9 Begin_Of_Object
1 1
3 3
1 1 1 1 0 166 -8 -30 61 86 1093 577 1 1 1 1 0 166 -8 -30 61 86 1093 577
Ethernet Packet Builder
1 1
MDI_DOCK_INFO_END MDI_DOCK_INFO_END
@ -5192,11 +5200,105 @@ EOF_MBSSDATA
1 1
0 1 0 1
<IPPlugIn.PacketBuilder DefaultBusProtocolId="256" DefaultDestMacIdSelection="107" DefaultDestinationIPAddress="192 . 168 . 1 . 100" DefaultDestinationIPv6Address="0:0:0:0:0:0:0:0" DefaultDestinationMacId="FF:FF:FF:FF:FF:FF" DefaultDestinationPort="502" DefaultSourceIPAddress="192 . 168 . 1 . 10" DefaultSourceIPv6Address="0:0:0:0:0:0:0:0" DefaultSourceMacId="02:00:4C:4F:4F:50" DefaultSourcePort="2000" DefaultSrcMacIdSelection="1" Name="Ethernet Packet Builder"> <IPPlugIn.PacketBuilder DefaultBusProtocolId="256" DefaultDestMacIdSelection="107" DefaultDestinationIPAddress="192 . 168 . 1 . 100" DefaultDestinationIPv6Address="0:0:0:0:0:0:0:0" DefaultDestinationMacId="FF:FF:FF:FF:FF:FF" DefaultDestinationPort="502" DefaultSourceIPAddress="192 . 168 . 1 . 10" DefaultSourceIPv6Address="0:0:0:0:0:0:0:0" DefaultSourceMacId="02:00:4C:4F:4F:50" DefaultSourcePort="2000" DefaultSrcMacIdSelection="1" Name="Ethernet Packet Builder">
<IPPlugIn.VPersistentFrameWrapper AssignedChannelId="Eth 1" DestMacIdConfStateSel="111" FrameDescription="MB/UDP" FrameIsValid="1" InitialPacketType="5" PDBData="5 0 1651797619 1 9 1 1651797619 1 5 1 1651797619 1 4 0 1651797619 1 11 0 1651797619 1 8 0 1651797619 1 3 0 1651797619 1 10 1 1651797619 1 3 1 1651797619 1 " RawFrameData=" 0-30-de- 7-9a-fd- 0-19-db-cb-83-dd- 8- 0-45- 0- 0-27- 0- 0- 0- 0-40-11-f7-72-c0-a8- 1- 1-c0-a8- 1- 2-d5-66- 1-f6- 0-13-67-b5-30-30- 0- 0- 0- 5-ff-2b- e- 1- 0- 0- 0- 2- 0- 0- 0- 6-" RawFrameLength="60" SrcMacIdConfStateSel="105" WlanAddr1MacIdConfStateSel="111" WlanAddr2MacIdConfStateSel="111" WlanAddr3MacIdConfStateSel="111" WlanAddr4MacIdConfStateSel="111"/> <IPPlugIn.VPersistentFrameWrapper AssignedChannelId="Eth 1" DestMacIdConfStateSel="111" FrameDescription="MB/UDP" FrameIsValid="1" InitialPacketType="5" PDBData="3 0 1651797619 1 3 1 1651797619 1 10 1 1651797619 1 8 0 1651797619 1 11 0 1651797619 1 4 0 1651797619 1 5 0 1651797619 1 5 1 1651797619 1 9 1 1651797619 1 " RawFrameData=" 0-30-de- 7-9a-fd- 0-19-db-cb-83-dd- 8- 0-45- 0- 0-27- 0- 0- 0- 0-40-11-f7-72-c0-a8- 1- 1-c0-a8- 1- 2-d5-66- 1-f6- 0-13-67-b5-30-30- 0- 0- 0- 5-ff-2b- e- 1- 0- 0- 0- 2- 0- 0- 0- 6-" RawFrameLength="60" SrcMacIdConfStateSel="105" WlanAddr1MacIdConfStateSel="111" WlanAddr2MacIdConfStateSel="111" WlanAddr3MacIdConfStateSel="111" WlanAddr4MacIdConfStateSel="111"/>
<IPPlugIn.SE id="5" intVal="0" key="1702391908"/> <IPPlugIn.SE id="102" intVal="0" key="1919247220"/>
<IPPlugIn.SE id="5" index="1" intVal="0" key="1702391908"/> <IPPlugIn.SE id="102" index="1" intVal="986" key="1919247220"/>
<IPPlugIn.SE id="5" index="2" intVal="0" key="1702391908"/> <IPPlugIn.SE id="102" index="2" intVal="0" key="1919247220"/>
<IPPlugIn.SE id="5" index="3" intVal="0" key="1702391908"/> <IPPlugIn.SE id="102" index="3" intVal="507" key="1919247220"/>
<IPPlugIn.SE id="102" intVal="1" key="1702391908"/>
<IPPlugIn.SE id="102" intVal="199" key="1936292453"/>
<IPPlugIn.SE id="102" intVal="437" key="1920231791"/>
<IPPlugIn.SE id="1004" intVal="1145393987" key="1952540511"/>
<IPPlugIn.SE id="1004" intVal="1" key="1986622303"/>
<IPPlugIn.SE id="1004" intVal="218" key="2003072104"/>
<IPPlugIn.SE id="1004" index="1" intVal="1397708114" key="1952540511"/>
<IPPlugIn.SE id="1004" index="1" intVal="1" key="1986622303"/>
<IPPlugIn.SE id="1004" index="1" intVal="156" key="2003072104"/>
<IPPlugIn.SE id="1004" index="2" intVal="1145394004" key="1952540511"/>
<IPPlugIn.SE id="1004" index="2" intVal="1" key="1986622303"/>
<IPPlugIn.SE id="1004" index="2" intVal="156" key="2003072104"/>
<IPPlugIn.SE id="1004" index="3" intVal="1347571540" key="1952540511"/>
<IPPlugIn.SE id="1004" index="3" intVal="1" key="1986622303"/>
<IPPlugIn.SE id="1005" index="18" intVal="1" key="1633907830"/>
<IPPlugIn.SE id="1005" index="19" intVal="0" key="1633907830"/>
<IPPlugIn.SE id="1005" index="20" intVal="1" key="1633907830"/>
<IPPlugIn.SE id="1005" index="20" intVal="1" key="1702391908"/>
<IPPlugIn.SE id="1005" index="19" intVal="1" key="1702391908"/>
<IPPlugIn.SE id="1005" index="18" intVal="1" key="1702391908"/>
<IPPlugIn.SE id="1004" index="3" intVal="125" key="2003072104"/>
<IPPlugIn.SE id="1004" index="4" intVal="1397316165" key="1952540511"/>
<IPPlugIn.SE id="1004" index="4" intVal="1" key="1986622303"/>
<IPPlugIn.SE id="1004" index="4" intVal="108" key="2003072104"/>
<IPPlugIn.SE id="1004" index="5" intVal="1348029508" key="1952540511"/>
<IPPlugIn.SE id="1004" index="5" intVal="1" key="1986622303"/>
<IPPlugIn.SE id="1004" index="5" intVal="108" key="2003072104"/>
<IPPlugIn.SE id="1004" intVal="0" key="1886352249"/>
<IPPlugIn.SE id="1004" intVal="0" key="1886352248"/>
<IPPlugIn.SE id="1004" intVal="0" key="7499639"/>
<IPPlugIn.SE id="125" intVal="0" key="7562604"/>
<IPPlugIn.SE id="102" index="1" intVal="1" key="1702391908"/>
<IPPlugIn.SE id="102" index="1" intVal="531" key="1936292453"/>
<IPPlugIn.SE id="102" index="1" intVal="397" key="1920231791"/>
<IPPlugIn.SE id="1005" intVal="0" key="1886352249"/>
<IPPlugIn.SE id="1005" intVal="0" key="1886352248"/>
<IPPlugIn.SE id="1005" intVal="1" key="1702391908"/>
<IPPlugIn.SE id="1005" intVal="0" key="1633907830"/>
<IPPlugIn.SE id="1005" index="1" intVal="1" key="1702391908"/>
<IPPlugIn.SE id="1005" index="1" intVal="1" key="1633907830"/>
<IPPlugIn.SE id="2" intVal="0" key="1702391908"/>
<IPPlugIn.SE id="2" index="1" intVal="0" key="1702391908"/>
<IPPlugIn.SE id="2" index="2" intVal="0" key="1702391908"/>
<IPPlugIn.SE id="1005" index="2" intVal="1" key="1702391908"/>
<IPPlugIn.SE id="1005" index="2" intVal="0" key="1633907830"/>
<IPPlugIn.SE id="1005" index="3" intVal="1" key="1702391908"/>
<IPPlugIn.SE id="1005" index="3" intVal="0" key="1633907830"/>
<IPPlugIn.SE id="1005" index="4" intVal="1" key="1702391908"/>
<IPPlugIn.SE id="1005" index="4" intVal="0" key="1633907830"/>
<IPPlugIn.SE id="1005" index="5" intVal="1" key="1702391908"/>
<IPPlugIn.SE id="1005" index="5" intVal="0" key="1633907830"/>
<IPPlugIn.SE id="1005" index="6" intVal="1" key="1702391908"/>
<IPPlugIn.SE id="1005" index="6" intVal="0" key="1633907830"/>
<IPPlugIn.SE id="1005" index="7" intVal="1" key="1702391908"/>
<IPPlugIn.SE id="1005" index="7" intVal="0" key="1633907830"/>
<IPPlugIn.SE id="1005" index="8" intVal="1" key="1702391908"/>
<IPPlugIn.SE id="1005" index="8" intVal="0" key="1633907830"/>
<IPPlugIn.SE id="1005" index="9" intVal="0" key="1702391908"/>
<IPPlugIn.SE id="1005" index="9" intVal="0" key="1633907830"/>
<IPPlugIn.SE id="3" intVal="0" key="1702391908"/>
<IPPlugIn.SE id="3" index="1" intVal="0" key="1702391908"/>
<IPPlugIn.SE id="3" index="2" intVal="0" key="1702391908"/>
<IPPlugIn.SE id="3" index="3" intVal="0" key="1702391908"/>
<IPPlugIn.SE id="3" index="4" intVal="0" key="1702391908"/>
<IPPlugIn.SE id="3" index="5" intVal="0" key="1702391908"/>
<IPPlugIn.SE id="3" index="6" intVal="0" key="1702391908"/>
<IPPlugIn.SE id="3" index="7" intVal="0" key="1702391908"/>
<IPPlugIn.SE id="3" index="8" intVal="0" key="1702391908"/>
<IPPlugIn.SE id="3" index="9" intVal="0" key="1702391908"/>
<IPPlugIn.SE id="3" index="10" intVal="0" key="1702391908"/>
<IPPlugIn.SE id="3" index="11" intVal="0" key="1702391908"/>
<IPPlugIn.SE id="1005" index="10" intVal="1" key="1702391908"/>
<IPPlugIn.SE id="1005" index="10" intVal="0" key="1633907830"/>
<IPPlugIn.SE id="1005" index="11" intVal="1" key="1702391908"/>
<IPPlugIn.SE id="1005" index="11" intVal="1" key="1633907830"/>
<IPPlugIn.SE id="1005" index="12" intVal="1" key="1702391908"/>
<IPPlugIn.SE id="1005" index="12" intVal="0" key="1633907830"/>
<IPPlugIn.SE id="1005" index="13" intVal="1" key="1702391908"/>
<IPPlugIn.SE id="1005" index="13" intVal="0" key="1633907830"/>
<IPPlugIn.SE id="1005" index="14" intVal="0" key="1702391908"/>
<IPPlugIn.SE id="1005" index="14" intVal="0" key="1633907830"/>
<IPPlugIn.SE id="1005" index="15" intVal="1" key="1702391908"/>
<IPPlugIn.SE id="1005" index="15" intVal="0" key="1633907830"/>
<IPPlugIn.SE id="1005" index="16" intVal="1" key="1702391908"/>
<IPPlugIn.SE id="1005" index="16" intVal="0" key="1633907830"/>
<IPPlugIn.SE id="1005" index="17" intVal="1" key="1702391908"/>
<IPPlugIn.SE id="1005" index="17" intVal="0" key="1633907830"/>
<IPPlugIn.SE id="102" index="2" intVal="1" key="1702391908"/>
<IPPlugIn.SE id="102" index="2" intVal="219" key="1936292453"/>
<IPPlugIn.SE id="102" index="2" intVal="164" key="1920231791"/>
<IPPlugIn.SE id="127" intVal="0" key="1651534958"/>
<IPPlugIn.SE id="1003" intVal="0" key="1886352249"/>
<IPPlugIn.SE id="1003" intVal="0" key="1886352248"/>
<IPPlugIn.SE id="1003" intVal="0" key="2003072104"/>
<IPPlugIn.SE id="4" intVal="0" key="1702391908"/> <IPPlugIn.SE id="4" intVal="0" key="1702391908"/>
<IPPlugIn.SE id="4" index="1" intVal="0" key="1702391908"/> <IPPlugIn.SE id="4" index="1" intVal="0" key="1702391908"/>
<IPPlugIn.SE id="4" index="2" intVal="0" key="1702391908"/> <IPPlugIn.SE id="4" index="2" intVal="0" key="1702391908"/>
@ -5207,104 +5309,10 @@ EOF_MBSSDATA
<IPPlugIn.SE id="4" index="7" intVal="0" key="1702391908"/> <IPPlugIn.SE id="4" index="7" intVal="0" key="1702391908"/>
<IPPlugIn.SE id="4" index="8" intVal="0" key="1702391908"/> <IPPlugIn.SE id="4" index="8" intVal="0" key="1702391908"/>
<IPPlugIn.SE id="4" index="9" intVal="0" key="1702391908"/> <IPPlugIn.SE id="4" index="9" intVal="0" key="1702391908"/>
<IPPlugIn.SE id="1003" intVal="0" key="2003072104"/> <IPPlugIn.SE id="5" intVal="0" key="1702391908"/>
<IPPlugIn.SE id="1003" intVal="0" key="1886352248"/> <IPPlugIn.SE id="5" index="1" intVal="0" key="1702391908"/>
<IPPlugIn.SE id="1003" intVal="0" key="1886352249"/> <IPPlugIn.SE id="5" index="2" intVal="0" key="1702391908"/>
<IPPlugIn.SE id="127" intVal="0" key="1651534958"/> <IPPlugIn.SE id="5" index="3" intVal="0" key="1702391908"/>
<IPPlugIn.SE id="3" intVal="0" key="1702391908"/>
<IPPlugIn.SE id="3" index="1" intVal="0" key="1702391908"/>
<IPPlugIn.SE id="102" index="2" intVal="164" key="1920231791"/>
<IPPlugIn.SE id="102" index="2" intVal="219" key="1936292453"/>
<IPPlugIn.SE id="102" index="2" intVal="1" key="1702391908"/>
<IPPlugIn.SE id="3" index="2" intVal="0" key="1702391908"/>
<IPPlugIn.SE id="3" index="3" intVal="0" key="1702391908"/>
<IPPlugIn.SE id="3" index="4" intVal="0" key="1702391908"/>
<IPPlugIn.SE id="3" index="5" intVal="0" key="1702391908"/>
<IPPlugIn.SE id="3" index="6" intVal="0" key="1702391908"/>
<IPPlugIn.SE id="3" index="7" intVal="0" key="1702391908"/>
<IPPlugIn.SE id="3" index="8" intVal="0" key="1702391908"/>
<IPPlugIn.SE id="3" index="9" intVal="0" key="1702391908"/>
<IPPlugIn.SE id="1005" index="10" intVal="0" key="1633907830"/>
<IPPlugIn.SE id="1005" index="11" intVal="1" key="1633907830"/>
<IPPlugIn.SE id="1005" index="12" intVal="0" key="1633907830"/>
<IPPlugIn.SE id="1005" index="13" intVal="0" key="1633907830"/>
<IPPlugIn.SE id="1005" index="14" intVal="0" key="1633907830"/>
<IPPlugIn.SE id="1005" index="15" intVal="0" key="1633907830"/>
<IPPlugIn.SE id="1005" index="16" intVal="0" key="1633907830"/>
<IPPlugIn.SE id="1005" index="17" intVal="0" key="1633907830"/>
<IPPlugIn.SE id="1005" index="17" intVal="1" key="1702391908"/>
<IPPlugIn.SE id="1005" index="16" intVal="1" key="1702391908"/>
<IPPlugIn.SE id="1005" index="15" intVal="1" key="1702391908"/>
<IPPlugIn.SE id="1005" index="14" intVal="0" key="1702391908"/>
<IPPlugIn.SE id="1005" index="13" intVal="1" key="1702391908"/>
<IPPlugIn.SE id="1005" index="12" intVal="1" key="1702391908"/>
<IPPlugIn.SE id="1005" index="11" intVal="1" key="1702391908"/>
<IPPlugIn.SE id="1005" index="10" intVal="1" key="1702391908"/>
<IPPlugIn.SE id="3" index="10" intVal="0" key="1702391908"/>
<IPPlugIn.SE id="3" index="11" intVal="0" key="1702391908"/>
<IPPlugIn.SE id="2" intVal="0" key="1702391908"/>
<IPPlugIn.SE id="2" index="1" intVal="0" key="1702391908"/>
<IPPlugIn.SE id="1005" index="2" intVal="0" key="1633907830"/>
<IPPlugIn.SE id="1005" index="3" intVal="0" key="1633907830"/>
<IPPlugIn.SE id="1005" index="4" intVal="0" key="1633907830"/>
<IPPlugIn.SE id="1005" index="5" intVal="0" key="1633907830"/>
<IPPlugIn.SE id="1005" index="6" intVal="0" key="1633907830"/>
<IPPlugIn.SE id="1005" index="7" intVal="0" key="1633907830"/>
<IPPlugIn.SE id="1005" index="8" intVal="0" key="1633907830"/>
<IPPlugIn.SE id="1005" index="9" intVal="0" key="1633907830"/>
<IPPlugIn.SE id="1005" index="9" intVal="0" key="1702391908"/>
<IPPlugIn.SE id="1005" index="8" intVal="1" key="1702391908"/>
<IPPlugIn.SE id="1005" index="7" intVal="1" key="1702391908"/>
<IPPlugIn.SE id="1005" index="6" intVal="1" key="1702391908"/>
<IPPlugIn.SE id="1005" index="5" intVal="1" key="1702391908"/>
<IPPlugIn.SE id="1005" index="4" intVal="1" key="1702391908"/>
<IPPlugIn.SE id="1005" index="3" intVal="1" key="1702391908"/>
<IPPlugIn.SE id="1005" index="2" intVal="1" key="1702391908"/>
<IPPlugIn.SE id="2" index="2" intVal="0" key="1702391908"/>
<IPPlugIn.SE id="1005" intVal="0" key="1633907830"/>
<IPPlugIn.SE id="1005" index="1" intVal="1" key="1633907830"/>
<IPPlugIn.SE id="1005" index="1" intVal="1" key="1702391908"/>
<IPPlugIn.SE id="1005" intVal="1" key="1702391908"/>
<IPPlugIn.SE id="1005" intVal="0" key="1886352248"/>
<IPPlugIn.SE id="1005" intVal="0" key="1886352249"/>
<IPPlugIn.SE id="125" intVal="0" key="7562604"/>
<IPPlugIn.SE id="102" index="1" intVal="397" key="1920231791"/>
<IPPlugIn.SE id="102" index="1" intVal="531" key="1936292453"/>
<IPPlugIn.SE id="102" index="1" intVal="1" key="1702391908"/>
<IPPlugIn.SE id="1004" intVal="0" key="7499639"/>
<IPPlugIn.SE id="1004" intVal="0" key="1886352248"/>
<IPPlugIn.SE id="1004" intVal="0" key="1886352249"/>
<IPPlugIn.SE id="1004" intVal="218" key="2003072104"/>
<IPPlugIn.SE id="1004" index="1" intVal="156" key="2003072104"/>
<IPPlugIn.SE id="1004" index="2" intVal="156" key="2003072104"/>
<IPPlugIn.SE id="1004" index="3" intVal="125" key="2003072104"/>
<IPPlugIn.SE id="1004" index="4" intVal="108" key="2003072104"/>
<IPPlugIn.SE id="1004" index="5" intVal="108" key="2003072104"/>
<IPPlugIn.SE id="1004" index="5" intVal="1" key="1986622303"/>
<IPPlugIn.SE id="1004" index="5" intVal="1348029508" key="1952540511"/>
<IPPlugIn.SE id="1004" index="4" intVal="1" key="1986622303"/>
<IPPlugIn.SE id="1004" index="4" intVal="1397316165" key="1952540511"/>
<IPPlugIn.SE id="1004" index="3" intVal="1" key="1986622303"/>
<IPPlugIn.SE id="1004" index="3" intVal="1347571540" key="1952540511"/>
<IPPlugIn.SE id="1004" index="2" intVal="1" key="1986622303"/>
<IPPlugIn.SE id="1004" index="2" intVal="1145394004" key="1952540511"/>
<IPPlugIn.SE id="1004" index="1" intVal="1" key="1986622303"/>
<IPPlugIn.SE id="1004" index="1" intVal="1397708114" key="1952540511"/>
<IPPlugIn.SE id="1004" intVal="1" key="1986622303"/>
<IPPlugIn.SE id="1004" intVal="1145393987" key="1952540511"/>
<IPPlugIn.SE id="102" intVal="437" key="1920231791"/>
<IPPlugIn.SE id="102" intVal="199" key="1936292453"/>
<IPPlugIn.SE id="102" intVal="1" key="1702391908"/>
<IPPlugIn.SE id="102" intVal="0" key="1919247220"/>
<IPPlugIn.SE id="102" index="1" intVal="986" key="1919247220"/>
<IPPlugIn.SE id="102" index="2" intVal="0" key="1919247220"/>
<IPPlugIn.SE id="102" index="3" intVal="507" key="1919247220"/>
<IPPlugIn.SE id="1005" index="18" intVal="1" key="1702391908"/>
<IPPlugIn.SE id="1005" index="18" intVal="1" key="1633907830"/>
<IPPlugIn.SE id="1005" index="19" intVal="1" key="1702391908"/>
<IPPlugIn.SE id="1005" index="19" intVal="0" key="1633907830"/>
<IPPlugIn.SE id="1005" index="20" intVal="1" key="1702391908"/>
<IPPlugIn.SE id="1005" index="20" intVal="1" key="1633907830"/>
</IPPlugIn.PacketBuilder> </IPPlugIn.PacketBuilder>
End_Of_Object VSSPlugInConfiguration 6 End_Of_Object VSSPlugInConfiguration 6
NULL NULL
@ -5340,7 +5348,7 @@ NULL
End_Of_Object VDOLocalInfoStruct 3 End_Of_Object VDOLocalInfoStruct 3
0.000000 0.000000
0 0 0 0
1 1 0 59420 1 176 1 2882400001 639 815 319 694 2882400002 0 0 0 0 0 0 1 2882400001 1280 1280 321 321 2882400002 0 27 0 1629118104 0 0 3 1 1 0 59420 1 176 1 2882400001 639 815 319 694 2882400002 0 0 0 0 0 0 1 2882400001 1280 1280 321 321 2882400002 0 0 0 1437687448 0 0 3
SS_BEGIN_COMMON_INFO SS_BEGIN_COMMON_INFO
1 1
0 0
@ -5352,7 +5360,7 @@ Ether1
11 11
1 1
1 1
345965688 1 0 1 0 1 1 0 81 42 2000 1 504289040 1 0 1 0 1 1 0 81 42 2000 1
SS_BEGIN_COMMON_INFO SS_BEGIN_COMMON_INFO
1 1
3 3
@ -5463,7 +5471,7 @@ End_Of_Serialized_Data 2
End_Of_Object VWriteBox 2 End_Of_Object VWriteBox 2
VWinStore 2 Begin_Of_Object VWinStore 2 Begin_Of_Object
1 1
22 2 3 -32088 -32000 -1 -1 0 0 930 767 22 2 3 -1 -1 -1 -1 -10088 -10000 -9070 -9233
End_Of_Child_List End_Of_Child_List
End_Of_Object VWinStore 2 End_Of_Object VWinStore 2
VWinStore 2 Begin_Of_Object VWinStore 2 Begin_Of_Object
@ -5488,8 +5496,8 @@ VEthernetFilterConfig 4 Begin_Of_Object
End_Of_Object VEthernetFilterConfig 4 End_Of_Object VEthernetFilterConfig 4
VEthernetProtocolConfig 4 Begin_Of_Object VEthernetProtocolConfig 4 Begin_Of_Object
1 1
1 1 0 1 1 1
include\ModbusProtocolDLL\ModbusProtocol.dll
End_Of_Object VEthernetProtocolConfig 4 End_Of_Object VEthernetProtocolConfig 4
VEthernetVnChannelConfig 4 Begin_Of_Object VEthernetVnChannelConfig 4 Begin_Of_Object
1 1
@ -5783,6 +5791,7 @@ End
FiltersEnd FiltersEnd
1 1 1 1
END_OF_WORKSPACE_MEMBER_DATA END_OF_WORKSPACE_MEMBER_DATA
END_OF_WORKSPACE_MEMBER END_OF_WORKSPACE_MEMBER
1 1

View file

@ -2,13 +2,16 @@
includes includes
{ {
#include "include\ModbusUdpClientCommon.cin" #include "include\ModbusEilDllClientCommon.cin"
#include "include\ModbusFunctions.cin" #include "include\ModbusFunctions.cin"
} }
variables variables
{ {
msTimer gtRead; msTimer gtRead;
message Client_2_RecBits rb;
message Client_2_Ex81 ex;
} }
// Get information of local network interface such like ip address // Get information of local network interface such like ip address
@ -35,8 +38,6 @@ on start
//ModbusReadRegisters(0x2033, 63); //ModbusReadRegisters(0x2033, 63);
if (@sysvar::%BUS_TYPE%%CHANNEL%::%NODE_NAME%::Info::OutputBits > 0) if (@sysvar::%BUS_TYPE%%CHANNEL%::%NODE_NAME%::Info::OutputBits > 0)
ModbusReadBits(0x200, @sysvar::%BUS_TYPE%%CHANNEL%::%NODE_NAME%::Info::OutputBits); ModbusReadBits(0x200, @sysvar::%BUS_TYPE%%CHANNEL%::%NODE_NAME%::Info::OutputBits);
if (@sysvar::%BUS_TYPE%%CHANNEL%::%NODE_NAME%::Info::OutputRegisters > 0)
ModbusReadRegisters(0x200, @sysvar::%BUS_TYPE%%CHANNEL%::%NODE_NAME%::Info::OutputRegisters);
setTimerCyclic(gtRead, 1, @sysvar::%BUS_TYPE%%CHANNEL%::%NODE_NAME%::Config::Interval); setTimerCyclic(gtRead, 1, @sysvar::%BUS_TYPE%%CHANNEL%::%NODE_NAME%::Config::Interval);
} }
@ -191,7 +192,7 @@ on timer gtRead
if (@sysvar::%BUS_TYPE%%CHANNEL%::%NODE_NAME%::Info::InputBits > 0) if (@sysvar::%BUS_TYPE%%CHANNEL%::%NODE_NAME%::Info::InputBits > 0)
ModbusReadBits(@sysvar::%BUS_TYPE%%CHANNEL%::%NODE_NAME%::Info::InputRegisters * 2, @sysvar::%BUS_TYPE%%CHANNEL%::%NODE_NAME%::Info::InputBits); ModbusReadBits(@sysvar::%BUS_TYPE%%CHANNEL%::%NODE_NAME%::Info::InputRegisters * 2, @sysvar::%BUS_TYPE%%CHANNEL%::%NODE_NAME%::Info::InputBits);
} }
/*
on sysvar %BUS_TYPE%%CHANNEL%::%NODE_NAME%::Data::OutputBits on sysvar %BUS_TYPE%%CHANNEL%::%NODE_NAME%::Data::OutputBits
{ {
word firstBitAddr, count, i; word firstBitAddr, count, i;
@ -216,7 +217,7 @@ on sysvar %BUS_TYPE%%CHANNEL%::%NODE_NAME%::Data::OutputRegisters
regValues[i] = @sysvar::%BUS_TYPE%%CHANNEL%::%NODE_NAME%::Data::OutputRegisters[i]; regValues[i] = @sysvar::%BUS_TYPE%%CHANNEL%::%NODE_NAME%::Data::OutputRegisters[i];
ModbusWriteRegisters(0x000, count, regValues); ModbusWriteRegisters(0x000, count, regValues);
} }*/
on sysvar %BUS_TYPE%%CHANNEL%::%NODE_NAME%::Config::Interval on sysvar %BUS_TYPE%%CHANNEL%::%NODE_NAME%::Config::Interval
{ {
@ -243,4 +244,13 @@ on key '-'
for (i = 0; i < @sysvar::%BUS_TYPE%%CHANNEL%::%NODE_NAME%::Info::OutputBits; i++) for (i = 0; i < @sysvar::%BUS_TYPE%%CHANNEL%::%NODE_NAME%::Info::OutputBits; i++)
@sysvar::%BUS_TYPE%%CHANNEL%::%NODE_NAME%::Data::OutputBits[i] = 0; @sysvar::%BUS_TYPE%%CHANNEL%::%NODE_NAME%::Data::OutputBits[i] = 0;
sysEndVariableStructUpdate("%BUS_TYPE%%CHANNEL%::%NODE_NAME%::Data", "OutputBits"); sysEndVariableStructUpdate("%BUS_TYPE%%CHANNEL%::%NODE_NAME%::Data", "OutputBits");
} }
/*
on message rb
{
write("Hello! Read Bits =)");
}
on message ex
{
write("Oh no, exception!");
}*/

View file

@ -0,0 +1,167 @@
/*@!Encoding:1252*/
includes
{
#include "Common.cin"
#include "TcpUdpCommon.cin"
}
variables
{
long gPacket;
msTimer gtArp;
byte gLocalMac[6];
byte gRemoteMac[6];
dword gLocalIP = 0xC0A80101;
}
word EilConnectTo(char Remote_IP[], word remotePort)
{
dword remoteIp;
// Convert IP string to Number
remoteIp = IpGetAddressAsNumber(Remote_IP);
if (remoteIp == ~1)
{
writeDbg(ConnError, "EilConnectTo: invalid server Ip address!");
OnModbusClientPanics(ConnectionError);
return ipGetLastError();
}
return EilConnectTo(remoteIp, remotePort);
}
word EilConnectTo(dword remoteIp, word remotePort)
{
long error;
byte broadcastMac[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
if (EthGetMacId(gLocalMac) != 0)
{
gSocketState = ERROR;
error = EthGetLastError();
writeDbg(ConnError, "EthGetMacId: Could not get local MAC! %d", error);
OnModbusClientPanics(ConnectionError);
return error;
}
// TCP/IP API gives IP in little endian but EIL uses big endian
gRemotePort = remotePort;
gRemoteIP = (remoteIp >> 24) | (remoteIp >> 8) & 0x0000FF00 | (remoteIp << 8) & 0x00FF0000 | (remoteIp << 24);
if (gPacket != 0)
ModbusDisconnect();
// Try to create an ARP packet that gets the MAC from remote server
gPacket = EthInitPacket("arp");
if (gPacket == 0)
{
gSocketState = ERROR;
error = EthGetLastError();
writeDbg(ConnError, "EthInitPacket: Could not create ARP package! %d", error);
OnModbusClientPanics(ConnectionError);
return error;
}
EthSetTokenData(gPacket, "eth", "source" , elCount(gLocalMac), gLocalMac);
EthSetTokenData(gPacket, "eth", "destination" , elCount(broadcastMac), broadcastMac);
EthSetTokenInt(gPacket, "arp", "hwType" , 1); // Ethernet
EthSetTokenInt(gPacket, "arp", "protType" , 0x0800); // IPv4
EthSetTokenInt(gPacket, "arp", "hwSize" , 6); // Ethernet addr size
EthSetTokenInt(gPacket, "arp", "protSize" , 4); // IP addr size
EthSetTokenInt(gPacket, "arp", "operation" , 1);
EthSetTokenData(gPacket, "arp", "hwSourceAddr" , elCount(gLocalMac), gLocalMac);
EthSetTokenInt(gPacket, "arp", "protSourceAddr" , gLocalIP);
//EthSetTokenData(gPacket, "arp", "hwDestinationAddr" , elCount(gLocalMac), gLocalMac);
EthSetTokenInt(gPacket, "arp", "protDestinationAddr" , gRemoteIP);
EthReceivePacket("OnEthReceivePacket");
EthCompletePacket(gPacket);
EthOutputPacket(gPacket);
EthReleasePacket(gPacket);
gSocketState = NULL;
gtArp.set(@sysvar::Config::Modbus::RequestTimeout);
return 0;
}
void EilConnectTo2()
{
gPacket = EthInitPacket("modbus");
if (gPacket == 0)
{
gSocketState = ERROR;
writeDbg(ConnError, "EthInitPacket: Could not create UDP packet: %d", EthGetLastError());
OnModbusClientPanics(ConnectionError);
return;
}
EthSetTokenData(gPacket, "eth", "source" , elCount(gLocalMac), gLocalMac);
EthSetTokenData(gPacket, "eth", "destination" , elCount(gRemoteMac), gRemoteMac);
EthSetTokenInt(gPacket, "ipv4", "source" , gLocalIP);
EthSetTokenInt(gPacket, "ipv4", "destination" , gRemoteIP);
//EthSetTokenInt(gPacket, "udp", "source" , 23456); // we dont need those
//EthSetTokenInt(gPacket, "udp", "destination" , 502); // we do use modbus defaults
gSocketState = OK;
}
void EilDisconnect()
{
if (gPacket != 0)
{
EthReleasePacket(gPacket);
gPacket = 0;
}
gSocketState = CLOSED;
}
void EilRecv()
{
}
byte EilSnd(byte buffer[], word length)
{
char str[20*3];
switch (gSocketState)
{
case CLOSED:
EilConnectTo(gRemoteIP, gRemotePort);
if (gSocketState != OK)
{
writeDbg(ConnWarning, "EilSnd: Reconnecting failed! Doing nothing.");
return 1;
}
case OK:
break;
default:
writeDbg(ConnWarning, "EilSnd: Socket status is not OK! Doing nothing.");
return 1;
}
bin_to_strhex(buffer, str);
writeDbg(ConnDebug, "EilSnd: %s (Länge: %d)", str, length);
EthResizeToken(gPacket, "udp", "data" , length*8);
EthSetTokenData(gPacket, "udp", "data" , length, buffer);
EthCompletePacket(gPacket);
EthOutputPacket(gPacket);
return 0;
}
long EilGetLastConnectionError(char string[])
{
EthGetLastErrorText(elCount(string), string);
return EthGetLastError();
}
on timer gtArp
{
gSocketState = ERROR;
writeDbg(ConnError, "No (valid) ARP response detected. The host seems to be offline!");
OnModbusClientPanics(ConnectionError);
}

View file

@ -7,7 +7,7 @@ includes
variables variables
{ {
const word gMaxPacketLength = __size_of(struct ModbusReqWriteRegisters); const word gMaxPacketLength = 259; //__size_of(struct ModbusReqWriteRegisters);
msTimer gtRobin; // Timer that sends the packets and watches for timeouts msTimer gtRobin; // Timer that sends the packets and watches for timeouts
word gTxID = 0x0000; // Transaction Identifier for Modbus. Used as index for gQueue word gTxID = 0x0000; // Transaction Identifier for Modbus. Used as index for gQueue
@ -50,10 +50,7 @@ void ModbusInit()
void ModbusMakeHeader(struct ModbusApHeader mbap, word length) void ModbusMakeHeader(struct ModbusApHeader mbap, word length)
{ {
mbap.TxID = gTxID++; // [2] Transaction ID EthSetTokenInt(gPacket, "modbus", "TxId", gTxID++);
mbap.Protocol = 0x0000; // [2] Protocol ID = 0 = Modbus
mbap.Length = length - __offset_of(struct ModbusApHeader, UnitID); // [2] Length; Number of bytes following
mbap.UnitID = 0xFF; // [1] Unit identifier; not relevant
} }
@ -62,21 +59,21 @@ void ModbusMakeHeader(struct ModbusApHeader mbap, word length)
/// <ModbusReadBits> /// <ModbusReadBits>
void ModbusReadBits(word address, word count) void ModbusReadBits(word address, word count)
{ {
const byte length = __size_of(struct ModbusReqRead); const byte length = 12; //__size_of(struct ModbusReqRead);
const byte funcCode = 0x01; const byte funcCode = 0x01;
byte buffer[length]; byte buffer[4] = {0x0B, 0x22, 0x00, 0x02};
struct ModbusReqRead mbr; struct ModbusReqRead mbr;
ModbusMakeHeader(mbr.Header, length); ModbusMakeHeader(mbr.Header, length);
// Payload // Payload
mbr.Header.FuncCode = funcCode; // [1] Function Code; 1: Read Coils (DI), 2: Read Discret Inputs (DIO), seems to be the same for WAGO 750-881 EthSetTokenInt(gPacket, "modbus", "FuncCode", funcCode);
mbr.Address = address; // [2] Start address EthResizeToken(gPacket, "modbus", "data" , 4*8);
mbr.Count = count; // [2] Number of items; 1:max 2000=0x7D0 EthSetTokenData(gPacket, "modbus", "data" , 4, buffer);
writeDbg(MbDebug, "Sending 'Read Bits' (0x01) command. Addr: 0x%04X, Count: %d", address, count); writeDbg(MbDebug, "Sending 'Read Bits' (0x01) command. Addr: 0x%04X, Count: %d", address, count);
memcpy_h2n(buffer, mbr); EthCompletePacket(gPacket);
ModbusSend(buffer, length, mbr.Header.TxID); EthOutputPacket(gPacket);
} }
/// <ModbusReadBits> /// <ModbusReadBits>

View file

@ -0,0 +1,64 @@
/*@!Encoding:1252*/
includes
{
#include "EilDllCommon.cin"
#include "ModbusClientCommon.cin"
}
void ModbusConnectTo(char Remote_IP[], word Remote_Port)
{
EilConnectTo(Remote_IP, Remote_Port);
}
void ModbusConnectTo(dword Remote_IP, word Remote_Port)
{
EilConnectTo(Remote_IP, Remote_Port);
}
byte ModbusSnd(byte buffer[], word length)
{
return EilSnd(buffer, length);
}
void ModbusRecv()
{
EilRecv();
}
void ModbusDisconnect()
{
EilDisconnect();
}
long ModbusGetLastConnectionError(char string[])
{
return EilGetLastConnectionError(string);
}
void OnEthReceivePacket(long channel, long dir, long packet)
{
byte buffer[gMaxPacketLength];
long size;
if (dir == TX)
return;
if (EthGetTokenInt(packet, "arp", "protSourceAddr") == gRemoteIP) // this was our ARP package
{
if (EthGetTokenData(packet, "arp", "hwSourceAddr", elCount(gRemoteMac), gRemoteMac) == 6)
{
gtArp.Cancel();
writeDbg(ConnDebug, "Remote Mac: %02X:%02X:%02X:%02X:%02X:%02X", gRemoteMac[0], gRemoteMac[1], gRemoteMac[2], gRemoteMac[3], gRemoteMac[4], gRemoteMac[5]);
EilConnectTo2(); // create the UDP package
ModbusStartQueue();
}
return;
}
if (EthGetTokenInt(packet, "ipv4", "protocol") == 0x11 && EthGetTokenInt(packet, "ipv4", "source") == gRemoteIP) // if this is a UDP package from our server
{
size = EthGetThisData(0, gMaxPacketLength, buffer);
OnModbusReceive(0, 0, EthGetTokenInt(packet, "ipv4", "source"), gRemoteIP, buffer, size);
}
}

View file

@ -1,44 +0,0 @@
/*@!Encoding:1252*/
includes
{
#include "TcpCommon.cin"
#include "ModbusClientCommon.cin"
}
void ModbusConnectTo(char Remote_IP[], word Remote_Port)
{
TcpConnectTo(Remote_IP, Remote_Port);
}
void ModbusConnectTo(dword Remote_IP, word Remote_Port)
{
TcpConnectTo(Remote_IP, Remote_Port);
}
void ModbusDisconnect()
{
TcpDisconnect();
}
byte ModbusSnd(byte buffer[], word length)
{
return TcpSnd(buffer, length);
}
void ModbusRecv()
{
TcpRecv();
}
long ModbusGetLastConnectionError(char string[])
{
return TcpGetLastConnectionError(string);
}
void OnTcpReceive(dword socket, long result, dword address, dword port, byte buffer[], dword size)
{
OnModbusReceive(socket, result, address, port, buffer, size);
if (result == 0 && size != 0)
TcpRecv();
}

View file

@ -1,44 +0,0 @@
/*@!Encoding:1252*/
includes
{
#include "UdpCommon.cin"
#include "ModbusClientCommon.cin"
}
void ModbusConnectTo(char Remote_IP[], word Remote_Port)
{
UdpConnectTo(Remote_IP, Remote_Port);
}
void ModbusConnectTo(dword Remote_IP, word Remote_Port)
{
UdpConnectTo(Remote_IP, Remote_Port);
}
void ModbusDisconnect()
{
UdpDisconnect();
}
byte ModbusSnd(byte buffer[], word length)
{
return UdpSnd(buffer, length);
}
void ModbusRecv()
{
UdpRecv();
}
long ModbusGetLastConnectionError(char string[])
{
return UdpGetLastConnectionError(string);
}
void OnUdpReceiveFrom(dword socket, long result, dword address, dword port, byte buffer[], dword size)
{
OnModbusReceive(socket, result, address, port, buffer, size);
if (result == 0 && size != 0)
UdpRecv();
}

View file

@ -1,204 +0,0 @@
/*@!Encoding:1252*/
includes
{
#include "Common.cin"
#include "TcpUdpCommon.cin"
}
variables
{
TcpSocket gSocket;
}
word TcpOpenSocket()
{
byte i;
CHAR errorText[200];
long error;
if (EthGetAdapterStatus() != 2) // Not connected
{
writeDbg(ConnError, "TcpOpenSocket: Adapter status not ok: %d!", EthGetAdapterStatus());
OnModbusClientPanics(ConnectionError);
return INVALID_IP;
}
// Try to open socket
i = 0;
do
{
gSocket = TcpSocket::Open(0, 0);
error = gSocket.GetLastSocketError();
if (error != 0)
{
gSocket.GetLastSocketErrorAsString(errorText, elcount(errorText));
writeDbg(ConnInfo, "TcpOpenSocket: could not open socket: (%d) %s", error, errorText);
}
}
while (error != 0 && i++ < 9);
if (error != 0)
{
writeDbg(ConnError, "TcpOpenSocket: could not open socket: (%d) %s", error, errorText);
OnModbusClientPanics(ConnectionError);
return error;
}
else
{
writeDbg(ConnInfo, "Tcp socket opened.");
}
return 0;
}
word TcpConnectTo(char Remote_IP[], word remotePort)
{
dword remoteIp;
// Convert IP string to Number
remoteIp = IpGetAddressAsNumber(Remote_IP);
if (remoteIp == INVALID_IP)
{
writeDbg(ConnError, "TcpConnectTo: invalid server Ip address: %s", Remote_IP);
OnModbusClientPanics(ConnectionError);
return 1;
}
return TcpConnectTo(remoteIp, remotePort);
}
word TcpConnectTo(dword remoteIp, word remotePort)
{
long fehler;
// Try to open a socket
fehler = TcpOpenSocket();
if (fehler != 0)
{
gSocketState = ERROR;
return fehler;
}
gRemoteIP = remoteIp;
gRemotePort = remotePort;
// Connect to Server
if (gSocket.Connect(remoteIp, remotePort) != 0)
{
fehler = gSocket.GetLastSocketError();
if (fehler != WSAEWOULDBLOCK) // OnTcpConnect will be called otherwise
{
writeDbg(ConnError, "TcpConnectTo: No connection established: %d", fehler);
gSocketState = ERROR;
OnModbusClientPanics(ConnectionError);
return fehler;
}
return 0;
}
else
{
writeDbg(ConnInfo, "TcpConnectTo: Successfully connected to server");
gSocketState = OK;
return 0;
}
}
void OnTcpConnect(dword socket, long result)
{
if (result != 0)
{
gSocket.GetLastSocketErrorAsString(gIpLastErrStr, elcount(gIpLastErrStr));
writeDbg(ConnError, "OnTcpConnect: (%d) %s", gSocket.GetLastSocketError(), gIpLastErrStr);
gSocketState = ERROR;
OnModbusClientPanics(ConnectionError);
return;
}
else
{
writeDbg(ConnInfo, "OnTcpConnect: Successfully connected to server");
gSocketState = OK;
ModbusStartQueue();
}
}
void TcpDisconnect()
{
gSocket.Close();
gSocketState = CLOSED;
}
void TcpRecv()
{
int result;
if (gSocketState != OK)
{
writeDbg(ConnWarning, "TcpRecv: Socket status is not OK! Doing nothing.");
OnModbusClientPanics(ConnectionError);
return;
}
result = gSocket.Receive(gRxBuffer, elcount(gRxBuffer));
if (result != 0) // Calling OnTcpReceive otherwise
{
gIpLastErr = gSocket.GetLastSocketError();
if (gIpLastErr != WSA_IO_PENDING) // Calling OnTcpReceive otherwise
{
gSocket.GetLastSocketErrorAsString(gIpLastErrStr, elcount(gIpLastErrStr));
writeDbg(ConnError, "TcpReceive: (%d) %s", gIpLastErr, gIpLastErrStr);
TcpDisconnect();
}
}
return;
}
word TcpSnd(byte buffer[], word length)
{
char str[20*3];
switch (gSocketState)
{
case CLOSED:
TcpConnectTo(gRemoteIP, gRemotePort);
if (gSocketState != OK)
{
writeDbg(ConnError, "TcpSnd: Reconnecting failed!");
OnModbusClientPanics(ConnectionError);
return 1;
}
case OK:
break;
default:
writeDbg(ConnError, "TcpSnd: Socket status is not OK! Doing nothing.");
OnModbusClientPanics(ConnectionError);
return 1;
}
bin_to_strhex(buffer, str);
writeDbg(ConnDebug, "TcpSnd: %s (Länge: %d)", str, length);
if (gSocket.Send(buffer, length) != 0)
{
gIpLastErr = gSocket.GetLastSocketError();
if (gIpLastErr != WSA_IO_PENDING)
{
gSocket.GetLastSocketErrorAsString(gIpLastErrStr, elcount(gIpLastErrStr));
writeDbg(ConnError, "TcpSnd: (%d) %s", gIpLastErr, gIpLastErrStr);
TcpDisconnect();
return 1;
}
}
return 0;
}
long TcpGetLastConnectionError(char string[])
{
gSocket.GetLastSocketErrorAsString(string, elCount(string));
return gSocket.GetLastSocketError();
}

View file

@ -1,166 +0,0 @@
/*@!Encoding:1252*/
includes
{
#include "Common.cin"
#include "TcpUdpCommon.cin"
}
variables
{
UdpSocket gSocket;
}
word UdpOpenSocket()
{
byte i;
char errorText[200];
long error;
if (EthGetAdapterStatus() != 2) // Not connected
{
writeDbg(ConnError, "UdpOpenSocket: Adapter status not ok: %d!", EthGetAdapterStatus());
OnModbusClientPanics(ConnectionError);
return INVALID_IP;
}
// Try to open socket
i = 0;
do
{
gSocket = UdpSocket::Open(0, 0);
error = gSocket.GetLastSocketError();
if (error != 0)
{
gSocket.GetLastSocketErrorAsString(errorText, elcount(errorText));
writeDbg(ConnInfo, "UdpOpenSocket: could not open socket: (%d) %s", error, errorText);
}
}
while (error != 0 && i++ < 9);
if (error != 0)
{
writeDbg(ConnError, "UdpOpenSocket: could not open socket: (%d) %s", error, errorText);
OnModbusClientPanics(ConnectionError);
return error;
}
else
{
writeDbg(ConnInfo, "Udp socket opened.");
}
return 0;
}
word UdpConnectTo(char Remote_IP[], word remotePort)
{
dword remoteIp;
// Convert IP string to Number
remoteIp = IpGetAddressAsNumber(Remote_IP);
if (remoteIp == INVALID_IP)
{
writeDbg(ConnError, "UdpConnectTo: invalid server Ip address: %s", Remote_IP);
OnModbusClientPanics(ConnectionError);
return 1;
}
return UdpConnectTo(remoteIp, remotePort);
}
word UdpConnectTo(dword remoteIp, word remotePort)
{
long fehler;
// Try to open a socket
fehler = UdpOpenSocket();
if (fehler != 0)
{
gSocketState = ERROR;
return fehler;
}
gRemoteIP = remoteIp;
gRemotePort = remotePort;
gSocketState = OK;
return 0;
}
void UdpDisconnect()
{
gSocket.Close();
gSocketState = CLOSED;
}
void UdpRecv()
{
int result;
if (gSocketState != OK)
{
writeDbg(ConnError, "UdpRecv: Socket status is not OK! Doing nothing.");
OnModbusClientPanics(ConnectionError);
return;
}
result = gSocket.ReceiveFrom(gRxBuffer, elCount(gRxBuffer));
if (result != 0) // Calling OnUdpReceive otherwise
{
gIpLastErr = gSocket.GetLastSocketError();
if (gIpLastErr != WSA_IO_PENDING) // Calling OnUdpReceive otherwise
{
gSocket.GetLastSocketErrorAsString(gIpLastErrStr, elCount(gIpLastErrStr));
writeDbg(ConnError, "UdpReceiveFrom: (%d) %s", gIpLastErr, gIpLastErrStr);
UdpDisconnect();
}
}
return;
}
byte UdpSnd(byte buffer[], word length)
{
char str[20*3];
switch (gSocketState)
{
case CLOSED:
UdpConnectTo(gRemoteIP, gRemotePort);
if (gSocketState != OK)
{
writeDbg(ConnError, "UdpSnd: Reconnecting failed!");
OnModbusClientPanics(ConnectionError);
return 1;
}
case OK:
break;
default:
writeDbg(ConnError, "UdpSnd: Socket status is not OK! Doing nothing.");
OnModbusClientPanics(ConnectionError);
return 1;
}
bin_to_strhex(buffer, str);
writeDbg(ConnDebug, "UdpSnd: %s (Länge: %d)", str, length);
if (gSocket.SendTo(gRemoteIP, gRemotePort, buffer, length) != 0)
{
gIpLastErr = gSocket.GetLastSocketError();
if (gIpLastErr != WSA_IO_PENDING)
{
gSocket.GetLastSocketErrorAsString(gIpLastErrStr, elcount(gIpLastErrStr));
writeDbg(ConnError, "UdpSnd error (%d): %s", gIpLastErr, gIpLastErrStr);
UdpDisconnect();
return 1;
}
}
return 0;
}
long UdpGetLastConnectionError(char string[])
{
gSocket.GetLastSocketErrorAsString(string, elCount(string));
return gSocket.GetLastSocketError();
}

View file

@ -1,7 +1,7 @@
VERSION "" VERSION ""
NS_ : NS_ :
NS_DESC_ NS_DESC_
CM_ CM_
BA_DEF_ BA_DEF_
@ -36,6 +36,16 @@ BS_:
BU_: Client_2 BU_: Client_2
BO_ 3 ReadRegisters: 8 Vector__XXX
BO_ 16908289 Client_2_RecBits: 1 Vector__XXX
SG_ DI2 : 1|1@1- (1,0) [0|0] "" Client_2
SG_ DI1 : 0|1@1- (1,0) [0|0] "" Client_2
BO_ 16908417 Client_2_Ex81: 1 Vector__XXX
SG_ ExCode : 0|8@1+ (1,0) [0|4] "" Client_2
BA_DEF_ BU_ "NodeLayerModules" STRING ; BA_DEF_ BU_ "NodeLayerModules" STRING ;
BA_DEF_ "DBName" STRING ; BA_DEF_ "DBName" STRING ;
@ -45,3 +55,4 @@ BA_DEF_DEF_ "DBName" "";
BA_DEF_DEF_ "BusType" "Ethernet"; BA_DEF_DEF_ "BusType" "Ethernet";
BA_ "BusType" "Ethernet"; BA_ "BusType" "Ethernet";
BA_ "DBName" "Modbus"; BA_ "DBName" "Modbus";

View file

@ -1010,7 +1010,7 @@ namespace NIPB
\param protocolToken Points the the VProtocolToken for the protocol. \param protocolToken Points the the VProtocolToken for the protocol.
\param tokenId The identifier of the requested token. \param tokenId The identifier of the requested token.
\param token Points to a VToken, which must be fille by this function. \param token Points to a VToken, which must be filled by this function.
*/ */
VDECL GetToken( const VProtocolToken /*in*/ *protocolToken, VTokenId /*in*/ tokenId, VToken /*out*/ *token ) = 0; VDECL GetToken( const VProtocolToken /*in*/ *protocolToken, VTokenId /*in*/ tokenId, VToken /*out*/ *token ) = 0;

View file

@ -8,6 +8,9 @@
#include "StdAfx.h" #include "StdAfx.h"
#include "ModbusProtocol.h" #include "ModbusProtocol.h"
#include <fstream>
#include <iomanip>
#include <cstdarg>
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
// //
@ -22,11 +25,11 @@
*/ */
ModbusProtocol::ModbusProtocol() : ModbusProtocol::ModbusProtocol() :
mProtocolId( NIPB::kNil ), mProtocolId( NIPB::kNil ),
mTxId(0), mTxId( NIPB::kNil ),
mProtType(0), mProtType( NIPB::kNil ),
mLength(0), mLength( NIPB::kNil ),
mUnitId(0), mUnitId( NIPB::kNil ),
mFuncCode(0) mFuncCode( NIPB::kNil )
{ {
} }
@ -48,22 +51,37 @@ ModbusProtocol::ModbusProtocol() :
*/ */
VDEF ModbusProtocol::Initialize( NIPB::IProtocolManager /*in*/ *protocolManager, NIPB::INetworkModel /*in*/ *networkModel, NIPB::INetworkModelCreator /*in*/ *modelCreator ) VDEF ModbusProtocol::Initialize( NIPB::IProtocolManager /*in*/ *protocolManager, NIPB::INetworkModel /*in*/ *networkModel, NIPB::INetworkModelCreator /*in*/ *modelCreator )
{ {
if (!log.is_open())
log.open("log.txt", std::ofstream::out | std::ofstream::app);
log << "Initializing";
if (protocolManager == 0) return NIPB::kInvalidArg; if (protocolManager == 0) return NIPB::kInvalidArg;
if (networkModel == 0) return NIPB::kInvalidArg; if (networkModel == 0) return NIPB::kInvalidArg;
if (modelCreator == 0) return NIPB::kInvalidArg; if (modelCreator == 0) return NIPB::kInvalidArg;
mProtocolManager = protocolManager; if (mProtocolId == NIPB::kNil)
NIPB::ITokenDefinitionCreator *protocol = 0;
if (modelCreator->DefineProtocol( "modbus", &mProtocolId, &protocol ) == NIPB::kOK)
{ {
modelCreator->DefineProtocolField( protocol, "TxId", &mTxId, 0 ); mProtocolManager = protocolManager;
modelCreator->DefineProtocolField( protocol, "Protocol", &mProtType, 0 );
modelCreator->DefineProtocolField( protocol, "Length", &mLength, 0 );
modelCreator->DefineProtocolField( protocol, "UnitId", &mUnitId, 0 );
modelCreator->DefineProtocolField( protocol, "FuncCode", &mFuncCode, 0 );
}
NIPB::ITokenDefinitionCreator *protocol = 0;
if (modelCreator->DefineProtocol( "modbus", &mProtocolId, &protocol ) == NIPB::kOK)
{
log << " Defining fields";
modelCreator->DefineProtocolField( protocol, "TxId", &mTxId, 0 );
modelCreator->DefineProtocolField( protocol, "Protocol", &mProtType, 0 );
modelCreator->DefineProtocolField( protocol, "Length", &mLength, 0 );
modelCreator->DefineProtocolField( protocol, "UnitId", &mUnitId, 0 );
modelCreator->DefineProtocolField( protocol, "FuncCode", &mFuncCode, 0 );
}
log << " MyProtocolId = " << int(mProtocolId);
}
else
{
log << " not :) ";
}
log << ".\n";
log.flush();
return NIPB::kOK; return NIPB::kOK;
} }
@ -75,7 +93,6 @@ VDEF ModbusProtocol::Initialize( NIPB::IProtocolManager /*in*/ *protocolManager,
*/ */
VDEF ModbusProtocol::Deinitialize( NIPB::IProtocolManager /*in*/ * /*protocolManager*/, NIPB::INetworkModel /*in*/ * /*networkModel*/ ) VDEF ModbusProtocol::Deinitialize( NIPB::IProtocolManager /*in*/ * /*protocolManager*/, NIPB::INetworkModel /*in*/ * /*networkModel*/ )
{ {
mProtocolId = 0;
return NIPB::kOK; return NIPB::kOK;
} }
@ -89,12 +106,15 @@ VDEF ModbusProtocol::Deinitialize( NIPB::IProtocolManager /*in*/ * /*protocolMan
*/ */
VDEF ModbusProtocol::GetDesignator( unsigned long /*in*/ bufferSize, char /*out**/ *buffer ) VDEF ModbusProtocol::GetDesignator( unsigned long /*in*/ bufferSize, char /*out**/ *buffer )
{ {
log << "GetDesignator";
if (bufferSize == 0) return NIPB::kInvalidArg; if (bufferSize == 0) return NIPB::kInvalidArg;
if (buffer == 0) return NIPB::kInvalidArg; if (buffer == 0) return NIPB::kInvalidArg;
if (bufferSize < strlen("modbus")) return NIPB::kInvalidArg; if (bufferSize < strlen("modbus")) return NIPB::kInvalidArg;
strcpy_s( buffer, bufferSize, "modbus" ); strcpy_s( buffer, bufferSize, "modbus" );
log << ".\n";
log.flush();
return NIPB::kOK; return NIPB::kOK;
} }
@ -128,12 +148,9 @@ VDEF ModbusProtocol::GetEncoder( NIPB::VTokenId /*in*/ tokenId, NIPB::IEncoder /
if ( tokenId == mTxId if ( tokenId == mTxId
|| tokenId == mProtType || tokenId == mProtType
|| tokenId == mLength) || tokenId == mLength
{ || tokenId == mUnitId
return mProtocolManager->GetEncoder( NIPB::kEncoderUnsignedLE, encoder ); || tokenId == mFuncCode)
}
else if ( tokenId == mUnitId
|| tokenId == mFuncCode)
{ {
return mProtocolManager->GetEncoder( NIPB::kEncoderUnsignedBE, encoder ); return mProtocolManager->GetEncoder( NIPB::kEncoderUnsignedBE, encoder );
} }
@ -155,6 +172,7 @@ VDEF ModbusProtocol::GetEncoder( NIPB::VTokenId /*in*/ tokenId, NIPB::IEncoder /
*/ */
VDEF ModbusProtocol::InitProtocol( NIPB::IPacket /*in*/ *packet, NIPB::VTokenId /*in*/ /*protocolTypeId*/, const NIPB::VProtocolToken /*in*/ * /*topProtocolToken*/, NIPB::VProtocolToken /*out*/ *modbus ) VDEF ModbusProtocol::InitProtocol( NIPB::IPacket /*in*/ *packet, NIPB::VTokenId /*in*/ /*protocolTypeId*/, const NIPB::VProtocolToken /*in*/ * /*topProtocolToken*/, NIPB::VProtocolToken /*out*/ *modbus )
{ {
log << "InitProtocol";
if (mProtocolManager == 0) return NIPB::kInternalError; if (mProtocolManager == 0) return NIPB::kInternalError;
if (packet == 0) return NIPB::kInvalidArg; if (packet == 0) return NIPB::kInvalidArg;
@ -190,8 +208,8 @@ VDEF ModbusProtocol::InitProtocol( NIPB::IPacket /*in*/ *packet, NIPB::VTokenId
return result; return result;
} }
this->SetTokenUnsigned( udp, NIPB::kUDPSource , 2, 40002 ); // Set source port this->SetTokenUnsigned( udp, NIPB::kUDPSource, 2, kClientPort ); // Set source port
this->SetTokenUnsigned( udp, NIPB::kUDPDestination, 2, 502 ); // Set destination port this->SetTokenUnsigned( udp, NIPB::kUDPDestination, 2, kServerPort ); // Set destination port
// //
// Init Modbus protocol // Init Modbus protocol
@ -212,7 +230,9 @@ VDEF ModbusProtocol::InitProtocol( NIPB::IPacket /*in*/ *packet, NIPB::VTokenId
this->SetTokenUnsigned( *modbus, mUnitId, 1, 0xFF ); // Set some UnitID (unused) this->SetTokenUnsigned( *modbus, mUnitId, 1, 0xFF ); // Set some UnitID (unused)
this->SetTokenUnsigned( *modbus, mFuncCode, 1, 0x00 ); // Set some invalid FuncCode this->SetTokenUnsigned( *modbus, mFuncCode, 1, 0x00 ); // Set some invalid FuncCode
} }
log << ".\n";
log.flush();
return result; return result;
} }
@ -226,13 +246,18 @@ VDEF ModbusProtocol::InitProtocol( NIPB::IPacket /*in*/ *packet, NIPB::VTokenId
*/ */
VDEF ModbusProtocol::CompleteProtocol( NIPB::IPacket /*in*/ *packet, const NIPB::VProtocolToken /*in*/ *modbus ) VDEF ModbusProtocol::CompleteProtocol( NIPB::IPacket /*in*/ *packet, const NIPB::VProtocolToken /*in*/ *modbus )
{ {
log << "CompleteProtocol";
if (packet == 0) return NIPB::kInvalidArg; if (packet == 0) return NIPB::kInvalidArg;
if (modbus == 0) return NIPB::kInvalidArg; if (modbus == 0) return NIPB::kInvalidArg;
if (modbus->tokenId != mProtocolId) return NIPB::kError; if (modbus->tokenId != mProtocolId) return NIPB::kError;
WORD lengthByte; log << ": Modbus->bitLength = " << std::dec << modbus->bitLength << ", ";
lengthByte = (WORD)BI2BY(modbus->bitLength - kHeaderBitLength + 16); // add UnitID and FuncCode to length although they are header WORD lengthBy = (WORD)BI2BY(modbus->bitLength); // this is the length of the payload
this->SetTokenUnsigned( *(NIPB::VProtocolToken*)modbus, mLength, 2, lengthByte ); // Set the correct length lengthBy += 2; // these are the UnitID and FuncCode fields
this->SetTokenUnsigned( *(NIPB::VProtocolToken*)modbus, mLength, 2, lengthBy ); // Set the correct length
log << " --> Length = " << std::dec << int(lengthBy) << ".\n";
log.flush();
return NIPB::kOK; return NIPB::kOK;
} }
@ -250,25 +275,36 @@ VDEF ModbusProtocol::CompleteProtocol( NIPB::IPacket /*in*/ *packet, const NIPB:
*/ */
VDEF ModbusProtocol::ParsePacket( NIPB::IPacket /*in*/ *packet, const NIPB::VProtocolToken /*in*/ *topProtocolToken, NIPB::IFormatter /*in*/ * /*errorWriter*/, NIPB::VTokenId /*out*/ *nextProcotolId, NIPB::VProtocolToken /*out*/ *protocolToken ) VDEF ModbusProtocol::ParsePacket( NIPB::IPacket /*in*/ *packet, const NIPB::VProtocolToken /*in*/ *topProtocolToken, NIPB::IFormatter /*in*/ * /*errorWriter*/, NIPB::VTokenId /*out*/ *nextProcotolId, NIPB::VProtocolToken /*out*/ *protocolToken )
{ {
if (packet == 0 ) return NIPB::kInvalidArg; log << "ParsePacket topProtocolToken->tokenId = " << topProtocolToken->tokenId;
if (nextProcotolId == 0 ) return NIPB::kInvalidArg; if (packet == 0 ) return NIPB::kInvalidArg;
if (protocolToken == 0 ) return NIPB::kInvalidArg; if (nextProcotolId == 0 ) return NIPB::kInvalidArg;
if (topProtocolToken == 0 ) return NIPB::kInvalidArg; if (protocolToken == 0 ) return NIPB::kInvalidArg;
if (topProtocolToken->tokenId != NIPB::kUDP) return NIPB::kInvalidArg; if (topProtocolToken->tokenId != NIPB::kUDP ) return NIPB::kInvalidArg;
NIPB::VResult result = NIPB::kError; NIPB::VResult result = NIPB::kError;
const BYTE *packetData = 0; const BYTE *packetData = 0;
ULONG packetLength = 0; ULONG packetLength = 0;
NIPB::VProtocols *protocols = 0; NIPB::VProtocols *protocols = 0;
if ( ((result = packet->GetDataSize( &packetLength )) != NIPB::kOK) if ( ((result = packet->GetDataSize( &packetLength )) != NIPB::kOK) // get packet
|| ((result = packet->GetDataPtr ( (void**)&packetData )) != NIPB::kOK) || ((result = packet->GetDataPtr ( (void**)&packetData )) != NIPB::kOK)
|| ((result = packet->GetProtocols( &protocols )) != NIPB::kOK) ) || ((result = packet->GetProtocols( &protocols )) != NIPB::kOK) )
return result; return result;
if (topProtocolToken->bitLength <= kHeaderBitLength) if (topProtocolToken->bitLength <= kHeaderBitLength) // packet is too short
return NIPB::kPacketParseError; return NIPB::kPacketParseError;
if ((WORD)packetData[BI2BY(topProtocolToken->bitOffset) + 2] != 0x0000) // no Modbus protocol. Caution! BE/LE
return NIPB::kPacketParseError;
log << " byteOffset = " << BI2BY(topProtocolToken->bitOffset) << ", byteLength = " << BI2BY(topProtocolToken->bitLength) << std::endl;
log << " Data = ";
for (ULONG i = BI2BY(topProtocolToken->bitOffset); i < BI2BY(topProtocolToken->bitOffset+topProtocolToken->bitLength); i++)
log << std::hex << std::setw(2) << std::setfill('0') << int(packetData[i]) << " ";
log << std::dec << std::endl;
log.flush();
protocolToken->tokenId = mProtocolId; protocolToken->tokenId = mProtocolId;
protocolToken->protocol = this; protocolToken->protocol = this;
protocolToken->packet = packet; protocolToken->packet = packet;
@ -278,8 +314,13 @@ VDEF ModbusProtocol::ParsePacket( NIPB::IPacket /*in*/ *packet, const NIPB::VPro
protocolToken->bitLength = topProtocolToken->bitLength - kHeaderBitLength; // don't add UnitID and FuncCode here protocolToken->bitLength = topProtocolToken->bitLength - kHeaderBitLength; // don't add UnitID and FuncCode here
protocols->contentId = this->GetContentId( packetData, packetLength, *protocolToken ); protocols->contentId = this->GetContentId( packetData, packetLength, *protocolToken );
log << " --> byteOffset = " << BI2BY(protocolToken->bitOffset) << ", byteLength = " << BI2BY(protocolToken->bitLength) << std::endl;
log << " --> ContentId = " << std::hex << protocols->contentId << std::dec;
*nextProcotolId = 0; *nextProcotolId = 0;
log << ".\n\n";
log.flush();
return NIPB::kOK; return NIPB::kOK;
} }
@ -290,14 +331,14 @@ VDEF ModbusProtocol::ParsePacket( NIPB::IPacket /*in*/ *packet, const NIPB::VPro
\param protocolToken Points the the VProtocolToken for the protocol. \param protocolToken Points the the VProtocolToken for the protocol.
\param tokenId The identifier of the requested token. \param tokenId The identifier of the requested token.
\param token Points to a VToken, which must be fille by this function. \param token Points to a VToken, which must be filled by this function.
*/ */
VDEF ModbusProtocol::GetToken( const NIPB::VProtocolToken /*in*/ *protocolToken, NIPB::VTokenId /*in*/ tokenId, NIPB::VToken /*out*/ *token ) VDEF ModbusProtocol::GetToken( const NIPB::VProtocolToken /*in*/ *protocolToken, NIPB::VTokenId /*in*/ tokenId, NIPB::VToken /*out*/ *token )
{ {
if (token == 0) return NIPB::kInvalidArg; if (token == 0) return NIPB::kInvalidArg;
if (protocolToken == 0) return NIPB::kInvalidArg; if (protocolToken == 0) return NIPB::kInvalidArg;
if (protocolToken->tokenId != mProtocolId) return NIPB::kTokenNotFound; if (protocolToken->tokenId != mProtocolId) return NIPB::kTokenNotFound;
if (tokenId == mTxId) if (tokenId == mTxId)
return MakeHeaderToken( protocolToken, mTxId, 0, 16, token ); return MakeHeaderToken( protocolToken, mTxId, 0, 16, token );
else if (tokenId == mProtType) else if (tokenId == mProtType)
@ -337,7 +378,7 @@ VDEF ModbusProtocol::InspectProtocol ( const NIPB::VProtocolToken /*in*/ *protoc
ULONG packetLength = 0; ULONG packetLength = 0;
if ( ((result = protocolToken->packet->GetDataSize( &packetLength )) != NIPB::kOK) if ( ((result = protocolToken->packet->GetDataSize( &packetLength )) != NIPB::kOK)
|| ((result = protocolToken->packet->GetDataPtr ( (void**)&packetData )) != NIPB::kOK) ) || ((result = protocolToken->packet->GetDataPtr ( (void**)&packetData )) != NIPB::kOK) )
return result; return result;
if (inspector->BeginToken( mProtocolId, 0, 0) != NIPB::kOK) if (inspector->BeginToken( mProtocolId, 0, 0) != NIPB::kOK)
@ -349,29 +390,109 @@ VDEF ModbusProtocol::InspectProtocol ( const NIPB::VProtocolToken /*in*/ *protoc
// TODO: Make InspectProtocol nice and smooth // TODO: Make InspectProtocol nice and smooth
switch(type) switch(type)
{ {
// Protocol Info column // Protocol Info column
case NIPB::kInspectionInfoColumn: case NIPB::kInspectionInfoColumn:
if (inspector->SelectField( NIPB::kFieldLabel, &formatter ) == NIPB::kOK) if (inspector->SelectField( NIPB::kFieldLabel, &formatter ) == NIPB::kOK)
formatter->FormatString( "ModbusInfo" ); {
formatter->FormatString( "MB: [" );
// Source port val = GetTxId( packetData, packetLength, *protocolToken );
val = GetContentId( packetData, packetLength, *protocolToken ); formatter->FormatUnsigned(val, 2, 10);
FormatUnsigned( inspector, "TxIDInfo", mTxId, val, 2 );
formatter->FormatString( "] " );
val = GetFuncCode( packetData, packetLength, *protocolToken );
if (val > 0x80)
{
formatter->FormatString( "(0x" );
formatter->FormatUnsigned( val & 0x0F, 1, 16 );
val = GetExCode( packetData, packetLength, *protocolToken );
formatter->FormatString( ") Ex 0x" );
formatter->FormatUnsigned( val, 1, 16);
switch (val) // exCode
{
case 0x01:
formatter->FormatString( ": Illegal func code!" );
formatter->FormatUnsigned( GetFuncCode( packetData, packetLength, *protocolToken ), 1, 16 );
break;
case 0x02:
formatter->FormatString( ": Illegal data address!" );
break;
case 0x03:
formatter->FormatString( ": Illegal data value!" );
break;
case 0x04:
formatter->FormatString( ": Server failure!" );
break;
case 0x05:
formatter->FormatString( ": Acknowledge!" );
break;
case 0x06:
formatter->FormatString( ": Server busy!" );
break;
case 0x0A:
case 0x0B:
formatter->FormatString( ": Gateway problem!" );
break;
default:
formatter->FormatString( "!" );
break;
}
}
else
{
switch (val) // funcCode
{
case 0x01:
case 0x02:
formatter->FormatString( "Read bits" );
break;
case 0x03:
case 0x04:
formatter->FormatString( "Read regs" );
break;
case 0x05:
formatter->FormatString( "Write bit" );
break;
case 0x06:
formatter->FormatString( "Write reg" );
break;
case 0x0F:
formatter->FormatString( "Write bits" );
break;
case 0x10:
formatter->FormatString( "Write regs" );
break;
case 0x16:
formatter->FormatString( "Write masks" );
break;
case 0x17:
formatter->FormatString( "Read&Write regs" );
break;
default:
formatter->FormatString( "[0x" );
formatter->FormatUnsigned(val, 1, 16);
formatter->FormatString( "]" );
break;
}
}
}
break; break;
// //
// Detail View // Detail View
// //
case NIPB::kInspectionDetailTree: case NIPB::kInspectionDetailTree:
if (inspector->SelectField( NIPB::kFieldLabel, &formatter ) == NIPB::kOK) if (inspector->SelectField( NIPB::kFieldLabel, &formatter ) == NIPB::kOK)
formatter->FormatString( "ModbusDetail" ); formatter->FormatString( "ModbusDetail" );
// Source port
val = GetContentId( packetData, packetLength, *protocolToken ); val = GetContentId( packetData, packetLength, *protocolToken );
FormatUnsigned( inspector, "TxIDDetail", mTxId, val, 2 ); FormatUnsigned( inspector, "TxIDDetail", mTxId, val, 2 );
break; break;
} }
inspector->EndToken(); inspector->EndToken();
return result; return result;
} }
@ -385,11 +506,76 @@ VDEF ModbusProtocol::InspectProtocol ( const NIPB::VProtocolToken /*in*/ *protoc
*/ */
ULONG ModbusProtocol::GetContentId( const BYTE *packetData, ULONG packetLength, const NIPB::VProtocolToken &protocol ) ULONG ModbusProtocol::GetContentId( const BYTE *packetData, ULONG packetLength, const NIPB::VProtocolToken &protocol )
{ {
ULONG offset = BI2BY(protocol.headerBitOffset); ULONG ip = GetIp( packetData, packetLength, protocol );
BYTE funcCode = GetFuncCode( packetData, packetLength, protocol );
if (offset+4 < packetLength) return ((ip << 16) & 0xFFFF0000) | funcCode;
}
/*--------------------------------------------------------------------*/
//! Returns the TxID
/*!
*/
WORD ModbusProtocol::GetTxId( const BYTE *packetData, ULONG packetLength, const NIPB::VProtocolToken &protocol )
{
ULONG offset = BI2BY(protocol.headerBitOffset);
if (offset+1 < packetLength)
return packetData[offset] << 8 | packetData[offset+1]; // BE/LE
else
return 0;
}
/*--------------------------------------------------------------------*/
//! Returns the FuncCode
/*!
*/
BYTE ModbusProtocol::GetFuncCode( const BYTE *packetData, ULONG packetLength, const NIPB::VProtocolToken &protocol )
{
ULONG offset = BI2BY(protocol.headerBitOffset) + 7;
if (offset+1 < packetLength)
{ {
return *((ULONG*)&packetData[offset]); return packetData[offset];
}
else
{
return 0;
}
}
/*--------------------------------------------------------------------*/
//! Returns the DestinationIP
/*!
*/
ULONG ModbusProtocol::GetIp( const BYTE * /*packetData*/, ULONG /*packetLength*/, const NIPB::VProtocolToken &/*protocol*/ )
{
// TODO: GetDestIp
/*NIPB::VToken *ipv4DestIp;
if (NIPB::GetToken(NIPB::kIPv4, NIPB::kIPv4Destination, ipv4DestIp) != NIPB::kOK)
return 0;
return ipv4DestIp->bitOffset
if (offset+2 < packetLength)
{
return *((WORD*)&packetData[offset]);
}
else
{
return 0;
}*/
return 0xC0A80102;
}
BYTE ModbusProtocol::GetExCode( const BYTE *packetData, ULONG packetLength, const NIPB::VProtocolToken &protocol )
{
ULONG offset = BI2BY(protocol.bitOffset);
if (offset+1 < packetLength)
{
return packetData[offset];
} }
else else
{ {
@ -433,6 +619,28 @@ NIPB::VResult ModbusProtocol::MakePayloadToken( const NIPB::VProtocolToken /*in*
return NIPB::kOK; return NIPB::kOK;
} }
/*--------------------------------------------------------------------*/
//! Format a unsigned token.
/*!
*/
void ModbusProtocol::FormatUnsigned( NIPB::IPacketInspector *inspector, LPCTSTR labelPre, NIPB::VTokenId tokenId, LPCTSTR labelPost, ULONG value, ULONG valueLength )
{
if ((inspector) && (inspector->BeginToken( tokenId, 0, 0) == NIPB::kOK))
{
NIPB::IFormatter *formatter = 0;
if (inspector->SelectField( NIPB::kFieldLabel, &formatter ) == NIPB::kOK)
formatter->FormatString( labelPre );
if (inspector->SelectField( NIPB::kFieldValue, &formatter ) == NIPB::kOK)
formatter->FormatUnsigned( value, valueLength, 0 );
if (inspector->SelectField( NIPB::kFieldLabel, &formatter ) == NIPB::kOK)
formatter->FormatString( labelPost );
inspector->EndToken();
}
}
/*--------------------------------------------------------------------*/ /*--------------------------------------------------------------------*/
//! Format a unsigned token. //! Format a unsigned token.
/*! /*!
@ -453,6 +661,21 @@ void ModbusProtocol::FormatUnsigned( NIPB::IPacketInspector *inspector, LPCTSTR
} }
} }
/*--------------------------------------------------------------------*/
//! Format a string.
/*!
*/
void ModbusProtocol::FormatString( NIPB::IPacketInspector *inspector, LPCTSTR text )
{
if (inspector)
{
NIPB::IFormatter *formatter = 0;
if (inspector->SelectField( NIPB::kFieldLabel, &formatter ) == NIPB::kOK)
formatter->FormatString( text );
}
}
/*--------------------------------------------------------------------*/ /*--------------------------------------------------------------------*/
//! Set the value of a unsigned token. //! Set the value of a unsigned token.
/*! /*!

View file

@ -1,5 +1,5 @@
/*------------------------------------------------------------------- /*-------------------------------------------------------------------
VCSignalProtocol.h ModbusProtocol.h
------------------------------------------------------------------- -------------------------------------------------------------------
(c) Vector Informatik GmbH. All rights reserved. (c) Vector Informatik GmbH. All rights reserved.
@ -8,6 +8,8 @@
#pragma once #pragma once
#include <fstream>
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
@ -18,7 +20,7 @@
Modbus protocol Modbus protocol
The protocol is located within a UDP protocol and uses the UDP The protocol is located within a UDP protocol and uses the UDP
ports 40002 and 502. The first 8 Bytes of the UDP payload ports 50002 and 502. The first 8 Bytes of the UDP payload
contain the header: contain the header:
[0,2] Transaction ID [0,2] Transaction ID
[2,2] Protocol ID (Modbus := 0x0000) [2,2] Protocol ID (Modbus := 0x0000)
@ -29,8 +31,12 @@
class ModbusProtocol : class ModbusProtocol :
public NIPB::IProtocol public NIPB::IProtocol
{ {
private:
static const ULONG kHeaderLength = 8; // see above static const ULONG kHeaderLength = 8; // see above
static const ULONG kHeaderBitLength = kHeaderLength*8; static const ULONG kHeaderBitLength = kHeaderLength*8;
public:
static const WORD kClientPort = 502;
static const WORD kServerPort = 502;
// //
// Construction // Construction
@ -135,11 +141,17 @@ public:
// Methods // Methods
// //
public: public:
ULONG GetContentId( const BYTE *packetData, ULONG packetLength, const NIPB::VProtocolToken &protocol ); ULONG GetContentId( const BYTE *packetData, ULONG packetLength, const NIPB::VProtocolToken &protocol );
WORD GetTxId( const BYTE *packetData, ULONG packetLength, const NIPB::VProtocolToken &protocol );
ULONG GetIp( const BYTE *packetData, ULONG packetLength, const NIPB::VProtocolToken &protocol );
BYTE GetFuncCode( const BYTE *packetData, ULONG packetLength, const NIPB::VProtocolToken &protocol );
BYTE GetExCode( const BYTE *packetData, ULONG packetLength, const NIPB::VProtocolToken &protocol );
static NIPB::VResult MakeHeaderToken( const NIPB::VProtocolToken /*in*/ *protocolToken, NIPB::VTokenId /*in*/ tokenId, ULONG /*in*/ offset, ULONG /*in*/ length, NIPB::VToken /*out*/ *token ); static NIPB::VResult MakeHeaderToken( const NIPB::VProtocolToken /*in*/ *protocolToken, NIPB::VTokenId /*in*/ tokenId, ULONG /*in*/ offset, ULONG /*in*/ length, NIPB::VToken /*out*/ *token );
static NIPB::VResult MakePayloadToken( const NIPB::VProtocolToken /*in*/ *protocolToken, NIPB::VTokenId /*in*/ tokenId, ULONG /*in*/ offset, ULONG /*in*/ length, NIPB::VToken /*out*/ *token ); static NIPB::VResult MakePayloadToken( const NIPB::VProtocolToken /*in*/ *protocolToken, NIPB::VTokenId /*in*/ tokenId, ULONG /*in*/ offset, ULONG /*in*/ length, NIPB::VToken /*out*/ *token );
static void FormatUnsigned( NIPB::IPacketInspector *inspector, LPCTSTR label, NIPB::VTokenId tokenId, ULONG value, ULONG valueLength ); static void FormatUnsigned( NIPB::IPacketInspector *inspector, LPCTSTR label, NIPB::VTokenId tokenId, ULONG value, ULONG valueLength );
static void FormatUnsigned( NIPB::IPacketInspector *inspector, LPCTSTR labelPre, NIPB::VTokenId tokenId, LPCTSTR labelPost, ULONG value, ULONG valueLength );
static void FormatString( NIPB::IPacketInspector *inspector, LPCTSTR text );
static NIPB::VResult SetTokenUnsigned( NIPB::VProtocolToken &protocolToken, NIPB::VTokenId tokenId, ULONG valueLength, ULONG value ); static NIPB::VResult SetTokenUnsigned( NIPB::VProtocolToken &protocolToken, NIPB::VTokenId tokenId, ULONG valueLength, ULONG value );
static NIPB::VResult SetTokenData( NIPB::VProtocolToken &protocolToken, NIPB::VTokenId tokenId, ULONG dataLength, const BYTE *data ); static NIPB::VResult SetTokenData( NIPB::VProtocolToken &protocolToken, NIPB::VTokenId tokenId, ULONG dataLength, const BYTE *data );
@ -149,6 +161,7 @@ public:
// //
private: private:
NIPB::VTokenId mProtocolId; //!< Token ID of this protocol NIPB::VTokenId mProtocolId; //!< Token ID of this protocol
NIPB::VTokenId mTxId; //!< Token ID of the 'TxID' field NIPB::VTokenId mTxId; //!< Token ID of the 'TxID' field
NIPB::VTokenId mProtType; //!< Token ID of the 'ProtocolID' field NIPB::VTokenId mProtType; //!< Token ID of the 'ProtocolID' field
NIPB::VTokenId mLength; //!< Token ID of the 'Length' field NIPB::VTokenId mLength; //!< Token ID of the 'Length' field
@ -156,6 +169,8 @@ private:
NIPB::VTokenId mFuncCode; //!< Token ID of the 'FuncCode' field NIPB::VTokenId mFuncCode; //!< Token ID of the 'FuncCode' field
NIPB::IProtocolManager *mProtocolManager; NIPB::IProtocolManager *mProtocolManager;
std::ofstream log;
}; };
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////

View file

@ -8,7 +8,6 @@
#include "StdAfx.h" #include "StdAfx.h"
#include "ModbusProtocolAddOn.h" #include "ModbusProtocolAddOn.h"
#include "ModbusProtocol.h"
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
// //
@ -25,6 +24,7 @@ ModbusProtocolAddOn *ModbusProtocolAddOn::sInstance = NULL;
ModbusProtocolAddOn::ModbusProtocolAddOn() ModbusProtocolAddOn::ModbusProtocolAddOn()
{ {
sInstance = this; sInstance = this;
this->sProtocol = NULL;
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -51,7 +51,9 @@ VDEF ModbusProtocolAddOn::CreateProtocol( const char /*in*/ *protocolSymbol, NIP
if (protocol == 0) return NIPB::kInvalidArg; if (protocol == 0) return NIPB::kInvalidArg;
if (protocolSymbol == 0) return NIPB::kInvalidArg; if (protocolSymbol == 0) return NIPB::kInvalidArg;
*protocol = new ModbusProtocol(); if (this->sProtocol == 0)
this->sProtocol = new ModbusProtocol();
*protocol = this->sProtocol;
return NIPB::kOK; return NIPB::kOK;
} }

View file

@ -7,6 +7,7 @@
------------------------------------------------------------------- */ ------------------------------------------------------------------- */
#pragma once #pragma once
#include "ModbusProtocol.h"
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
@ -46,6 +47,7 @@ public:
// //
private: private:
static ModbusProtocolAddOn *sInstance; static ModbusProtocolAddOn *sInstance;
ModbusProtocol *sProtocol;
}; };
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////

View file

@ -9,6 +9,8 @@
#include "StdAfx.h" #include "StdAfx.h"
#include "ModbusProtocolDLL.h" #include "ModbusProtocolDLL.h"
#include "ModbusProtocolAddOn.h" #include "ModbusProtocolAddOn.h"
#include "ModbusProtocol.h"
#include <fstream>
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
@ -26,15 +28,29 @@ STDAPI DllRegisterAddOn( NIPB::IAddOnRegistrar* registrar )
return E_INVALIDARG; return E_INVALIDARG;
} }
std::ofstream log;
log.open("log.txt", std::ofstream::out);
// //
// register the signal protocol at the IPB Packet Lib. For the protocol // register the signal protocol at the IPB Packet Lib. For the protocol
// UDP with source port 40002 is used. // UDP is used.
// //
if (registrar->RegisterProtocol( "modbus", new ModbusProtocolAddOn(), "udp", 40002, 0xFFFFFFFF ) != NIPB::kOK) ModbusProtocolAddOn *mbpao = new ModbusProtocolAddOn();
if (registrar->RegisterProtocol( "modbus", mbpao, "udp", ModbusProtocol::kServerPort, 0xFFFFFFFF ) != NIPB::kOK)
{ {
ModbusProtocolAddOn::Instance().Release(); log << "Could not register UDP 502 -> 50002\n";
log.close();
mbpao->Release();
return NIPB::kError; return NIPB::kError;
} }
/*if (registrar->RegisterProtocol( "modbus", mbpao, "udp", 0xFFFFFFFF, ModbusProtocol::kServerPort ) != NIPB::kOK)
{
log << "Could not register UDP 50002 -> 502\n";
log.close();
mbpao->Release();
return NIPB::kError;
}*/
log << "Registered Modbus for UDP\n";
log.close();
return S_OK; return S_OK;
} }

View file

@ -1,6 +1,35 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<systemvariables version="4"> <systemvariables version="4">
<namespace name="" comment=""> <namespace name="" comment="">
<namespace name="Ethernet1" comment="Subnet: 192.168.1.">
<namespace name="Client_2" comment="Server with ip address '192.168.1.2'">
<namespace name="Config" comment="Configuration section for this server">
<variable anlyzLocal="2" readOnly="false" valueSequence="false" unit="" name="IP" comment="The IP address of this server" bitcount="8" isSigned="true" encoding="65001" type="string" startValue="192.168.1.2" />
<variable anlyzLocal="2" readOnly="false" valueSequence="false" unit="ms" name="Interval" comment="The interval with which the device will be queried" bitcount="32" isSigned="true" encoding="65001" type="int" startValue="1000" minValue="10" minValuePhys="10" maxValue="10000" maxValuePhys="10000" />
</namespace>
<namespace name="Info" comment="Some information about the device">
<variable anlyzLocal="2" readOnly="false" valueSequence="false" unit="" name="Vendor" comment="The vendor of the device" bitcount="32" isSigned="true" encoding="65001" type="int" startValue="23">
<valuetable definesMinMax="true">
<valuetableentry value="2" description="BuR" />
<valuetableentry value="23" description="Wago" />
</valuetable>
</variable>
<variable anlyzLocal="2" readOnly="false" valueSequence="false" unit="" name="InputRegisters" comment="Number of input registers" bitcount="32" isSigned="true" encoding="65001" type="int" startValue="0" minValue="0" minValuePhys="0" maxValue="123" maxValuePhys="123" />
<variable anlyzLocal="2" readOnly="false" valueSequence="false" unit="" name="Modules" comment="The type and number of inputs of modules that are connected to the server" bitcount="8" isSigned="true" encoding="65001" type="string" startValue="DI2,DO16" />
<variable anlyzLocal="2" readOnly="false" valueSequence="false" unit="" name="SerialCode" comment="The serial code of the server" bitcount="32" isSigned="true" encoding="65001" type="int" startValue="750" minValue="1" minValuePhys="1" maxValue="10000" maxValuePhys="10000" />
<variable anlyzLocal="2" readOnly="false" valueSequence="false" unit="" name="DeviceCode" comment="The device code of the server" bitcount="32" isSigned="true" encoding="65001" type="int" startValue="881" minValue="1" minValuePhys="1" maxValue="10000" maxValuePhys="10000" />
<variable anlyzLocal="2" readOnly="false" valueSequence="false" unit="" name="InputBits" comment="Number of input bits" bitcount="32" isSigned="true" encoding="65001" type="int" startValue="2" minValue="0" minValuePhys="0" maxValue="2000" maxValuePhys="2000" />
<variable anlyzLocal="2" readOnly="false" valueSequence="false" unit="" name="OutputBits" comment="Number of output bits" bitcount="32" isSigned="true" encoding="65001" type="int" startValue="16" minValue="0" minValuePhys="0" maxValue="2000" maxValuePhys="2000" />
<variable anlyzLocal="2" readOnly="false" valueSequence="false" unit="" name="OutputRegisters" comment="Number of output registers" bitcount="32" isSigned="true" encoding="65001" type="int" startValue="0" minValue="0" minValuePhys="0" maxValue="123" maxValuePhys="123" />
</namespace>
<namespace name="Data" comment="The actual process image">
<variable anlyzLocal="2" readOnly="false" valueSequence="false" unit="" name="InputRegisters" comment="The values of the input registers" bitcount="32" isSigned="true" encoding="65001" type="intarray" arrayLength="0" />
<variable anlyzLocal="2" readOnly="false" valueSequence="false" unit="" name="InputBits" comment="The state of the input bits" bitcount="32" isSigned="true" encoding="65001" type="intarray" arrayLength="2" />
<variable anlyzLocal="2" readOnly="false" valueSequence="false" unit="" name="OutputBits" comment="The state of the output bits. Write here and the values will be sent to the device" bitcount="32" isSigned="true" encoding="65001" type="intarray" arrayLength="16" />
<variable anlyzLocal="2" readOnly="false" valueSequence="false" unit="" name="OutputRegisters" comment="The values of the output registers. Write here and the values will be sent to the device" bitcount="32" isSigned="true" encoding="65001" type="intarray" arrayLength="0" />
</namespace>
</namespace>
</namespace>
<namespace name="Config" comment=""> <namespace name="Config" comment="">
<namespace name="Modbus" comment=""> <namespace name="Modbus" comment="">
<variable anlyzLocal="2" readOnly="false" valueSequence="false" unit="ms" name="RequestTimeout" comment="The maximum duration for a Modbus-UDP/-TCP request in milliseconds. After timeout a retransmission may be started (see MaxRetransmissionCount). Use `ping` to get the maximum latency to a device, double it and add 2-3 ms for processing." bitcount="32" isSigned="true" encoding="65001" type="int" startValue="7" minValue="1" minValuePhys="1" maxValue="1000" maxValuePhys="1000" /> <variable anlyzLocal="2" readOnly="false" valueSequence="false" unit="ms" name="RequestTimeout" comment="The maximum duration for a Modbus-UDP/-TCP request in milliseconds. After timeout a retransmission may be started (see MaxRetransmissionCount). Use `ping` to get the maximum latency to a device, double it and add 2-3 ms for processing." bitcount="32" isSigned="true" encoding="65001" type="int" startValue="7" minValue="1" minValuePhys="1" maxValue="1000" maxValuePhys="1000" />
@ -11,34 +40,5 @@
<variable anlyzLocal="2" readOnly="false" valueSequence="false" unit="" name="AdapterIndex" comment="Index of network interface to use" bitcount="32" isSigned="true" encoding="65001" type="int" startValue="2" minValue="1" minValuePhys="1" maxValue="20" maxValuePhys="20" /> <variable anlyzLocal="2" readOnly="false" valueSequence="false" unit="" name="AdapterIndex" comment="Index of network interface to use" bitcount="32" isSigned="true" encoding="65001" type="int" startValue="2" minValue="1" minValuePhys="1" maxValue="20" maxValuePhys="20" />
</namespace> </namespace>
</namespace> </namespace>
<namespace name="Ethernet1" comment="Subnet: 192.168.1.">
<namespace name="Client_2" comment="Server with ip address '192.168.1.2'">
<namespace name="Config" comment="Configuration section for this server">
<variable anlyzLocal="2" readOnly="false" valueSequence="false" unit="" name="IP" comment="The IP address of this server" bitcount="8" isSigned="true" encoding="65001" type="string" startValue="192.168.1.2" />
<variable anlyzLocal="2" readOnly="false" valueSequence="false" unit="ms" name="Interval" comment="The interval with which the device will be queried" bitcount="32" isSigned="true" encoding="65001" type="int" startValue="100" minValue="10" minValuePhys="10" maxValue="10000" maxValuePhys="10000" />
</namespace>
<namespace name="Info" comment="Some information about the device">
<variable anlyzLocal="2" readOnly="true" valueSequence="false" unit="" name="Vendor" comment="The vendor of the device" bitcount="32" isSigned="true" encoding="65001" type="int" startValue="23">
<valuetable definesMinMax="true">
<valuetableentry value="2" description="BuR" />
<valuetableentry value="23" description="Wago" />
</valuetable>
</variable>
<variable anlyzLocal="2" readOnly="true" valueSequence="false" unit="" name="SerialCode" comment="The serial code of the server" bitcount="32" isSigned="true" encoding="65001" type="int" startValue="750" minValue="1" minValuePhys="1" maxValue="10000" maxValuePhys="10000" />
<variable anlyzLocal="2" readOnly="true" valueSequence="false" unit="" name="DeviceCode" comment="The device code of the server" bitcount="32" isSigned="true" encoding="65001" type="int" startValue="881" minValue="1" minValuePhys="1" maxValue="10000" maxValuePhys="10000" />
<variable anlyzLocal="2" readOnly="true" valueSequence="false" unit="" name="Modules" comment="The type and number of inputs of modules that are connected to the server" bitcount="8" isSigned="true" encoding="65001" type="string" startValue="DI2,DO16" />
<variable anlyzLocal="2" readOnly="true" valueSequence="false" unit="" name="InputRegisters" comment="Number of input registers" bitcount="32" isSigned="true" encoding="65001" type="int" startValue="0" minValue="0" minValuePhys="0" maxValue="123" maxValuePhys="123" />
<variable anlyzLocal="2" readOnly="true" valueSequence="false" unit="" name="InputBits" comment="Number of input bits" bitcount="32" isSigned="true" encoding="65001" type="int" startValue="2" minValue="0" minValuePhys="0" maxValue="2000" maxValuePhys="2000" />
<variable anlyzLocal="2" readOnly="true" valueSequence="false" unit="" name="OutputRegisters" comment="Number of output registers" bitcount="32" isSigned="true" encoding="65001" type="int" startValue="0" minValue="0" minValuePhys="0" maxValue="123" maxValuePhys="123" />
<variable anlyzLocal="2" readOnly="true" valueSequence="false" unit="" name="OutputBits" comment="Number of output bits" bitcount="32" isSigned="true" encoding="65001" type="int" startValue="16" minValue="0" minValuePhys="0" maxValue="2000" maxValuePhys="2000" />
</namespace>
<namespace name="Data" comment="The actual process image">
<variable anlyzLocal="2" readOnly="false" valueSequence="false" unit="" name="InputRegisters" comment="The values of the input registers" bitcount="9" isSigned="true" encoding="65001" type="intarray" arrayLength="0" />
<variable anlyzLocal="2" readOnly="false" valueSequence="false" unit="" name="InputBits" comment="The state of the input bits" bitcount="2" isSigned="true" encoding="65001" type="intarray" arrayLength="2" />
<variable anlyzLocal="2" readOnly="false" valueSequence="false" unit="" name="OutputRegisters" comment="The values of the output registers. Write here and the values will be sent to the device" bitcount="9" isSigned="true" encoding="65001" type="intarray" arrayLength="0" />
<variable anlyzLocal="2" readOnly="false" valueSequence="false" unit="" name="OutputBits" comment="The state of the output bits. Write here and the values will be sent to the device" bitcount="2" isSigned="true" encoding="65001" type="intarray" arrayLength="16" />
</namespace>
</namespace>
</namespace>
</namespace> </namespace>
</systemvariables> </systemvariables>

45
Modbus-DLL/log.txt Normal file
View file

@ -0,0 +1,45 @@
Registered Modbus for UDP
Initializing Defining fields MyProtocolId = 4896.
InitProtocol.
CompleteProtocol: Modbus->bitLength = 32, --> Length = 6.
ParsePacket topProtocolToken->tokenId = 352 byteOffset = 42, byteLength = 12
Data = 00 01 00 00 00 06 ff 01 00 00 00 00
--> byteOffset = 50, byteLength = 4
--> ContentId = 1020001.
ParsePacket topProtocolToken->tokenId = 352 byteOffset = 42, byteLength = 9
Data = 00 01 00 00 00 03 ff 81 03
--> byteOffset = 50, byteLength = 1
--> ContentId = 1020081.
ParsePacket topProtocolToken->tokenId = 352 byteOffset = 42, byteLength = 12
Data = 00 01 00 00 00 06 ff 01 00 00 00 00
--> byteOffset = 50, byteLength = 4
--> ContentId = 1020001.
ParsePacket topProtocolToken->tokenId = 352 byteOffset = 42, byteLength = 9
Data = 00 01 00 00 00 03 ff 81 03
--> byteOffset = 50, byteLength = 1
--> ContentId = 1020081.
CompleteProtocol: Modbus->bitLength = 32, --> Length = 6.
ParsePacket topProtocolToken->tokenId = 352 byteOffset = 42, byteLength = 12
Data = 00 02 00 00 00 06 ff 01 00 00 00 00
--> byteOffset = 50, byteLength = 4
--> ContentId = 1020001.
ParsePacket topProtocolToken->tokenId = 352 byteOffset = 42, byteLength = 9
Data = 00 02 00 00 00 03 ff 81 03
--> byteOffset = 50, byteLength = 1
--> ContentId = 1020081.
ParsePacket topProtocolToken->tokenId = 352 byteOffset = 42, byteLength = 12
Data = 00 02 00 00 00 06 ff 01 00 00 00 00
--> byteOffset = 50, byteLength = 4
--> ContentId = 1020001.
ParsePacket topProtocolToken->tokenId = 352 byteOffset = 42, byteLength = 9
Data = 00 02 00 00 00 03 ff 81 03
--> byteOffset = 50, byteLength = 1
--> ContentId = 1020081.