|
10 | 10 | #---------------------------------------------------------------------------# |
11 | 11 | # import the various server implementations |
12 | 12 | #---------------------------------------------------------------------------# |
13 | | -from pymodbus.client.sync import ModbusTcpClient as ModbusClient |
| 13 | +# from pymodbus.client.sync import ModbusTcpClient as ModbusClient |
14 | 14 | #from pymodbus.client.sync import ModbusUdpClient as ModbusClient |
15 | | -#from pymodbus.client.sync import ModbusSerialClient as ModbusClient |
| 15 | +from pymodbus.client.sync import ModbusSerialClient as ModbusClient |
16 | 16 |
|
17 | 17 | #---------------------------------------------------------------------------# |
18 | 18 | # configure the client logging |
|
32 | 32 | # It should be noted that you can supply an ipv4 or an ipv6 host address for |
33 | 33 | # both the UDP and TCP clients. |
34 | 34 | #---------------------------------------------------------------------------# |
35 | | -client = ModbusClient('127.0.0.1') |
| 35 | +client = ModbusClient(method='rtu', port="/dev/ttyp0") |
| 36 | +# client = ModbusClient('127.0.0.1', port=5020) |
36 | 37 | client.connect() |
37 | 38 |
|
38 | 39 | #---------------------------------------------------------------------------# |
|
65 | 66 | #---------------------------------------------------------------------------# |
66 | 67 | # information requests |
67 | 68 | #---------------------------------------------------------------------------# |
68 | | -rq = ReadDeviceInformationRequest() |
| 69 | +rq = ReadDeviceInformationRequest(unit=1) |
69 | 70 | rr = client.execute(rq) |
70 | 71 | #assert(rr == None) # not supported by reference |
71 | 72 | assert(rr.function_code < 0x80) # test that we are not an error |
72 | | -assert(rr.information[0] == 'proconX Pty Ltd') # test the vendor name |
73 | | -assert(rr.information[1] == 'FT-MBSV') # test the product code |
74 | | -assert(rr.information[2] == 'EXPERIMENTAL') # test the code revision |
| 73 | +assert(rr.information[0] == 'Pymodbus') # test the vendor name |
| 74 | +assert(rr.information[1] == 'PM') # test the product code |
| 75 | +assert(rr.information[2] == '1.0') # test the code revision |
75 | 76 |
|
76 | | -rq = ReportSlaveIdRequest() |
| 77 | +rq = ReportSlaveIdRequest(unit=1) |
77 | 78 | rr = client.execute(rq) |
78 | | -assert(rr == None) # not supported by reference |
| 79 | +# assert(rr == None) # not supported by reference |
79 | 80 | #assert(rr.function_code < 0x80) # test that we are not an error |
80 | 81 | #assert(rr.identifier == 0x00) # test the slave identifier |
81 | 82 | #assert(rr.status == 0x00) # test that the status is ok |
82 | 83 |
|
83 | | -rq = ReadExceptionStatusRequest() |
| 84 | +rq = ReadExceptionStatusRequest(unit=1) |
84 | 85 | rr = client.execute(rq) |
85 | 86 | #assert(rr == None) # not supported by reference |
86 | | -assert(rr.function_code < 0x80) # test that we are not an error |
87 | | -assert(rr.status == 0x55) # test the status code |
| 87 | +#assert(rr.function_code < 0x80) # test that we are not an error |
| 88 | +#assert(rr.status == 0x55) # test the status code |
88 | 89 |
|
89 | | -rq = GetCommEventCounterRequest() |
| 90 | +rq = GetCommEventCounterRequest(unit=1) |
90 | 91 | rr = client.execute(rq) |
91 | | -assert(rr == None) # not supported by reference |
| 92 | +#assert(rr == None) # not supported by reference |
92 | 93 | #assert(rr.function_code < 0x80) # test that we are not an error |
93 | 94 | #assert(rr.status == True) # test the status code |
94 | 95 | #assert(rr.count == 0x00) # test the status code |
95 | 96 |
|
96 | | -rq = GetCommEventLogRequest() |
| 97 | +rq = GetCommEventLogRequest(unit=1) |
97 | 98 | rr = client.execute(rq) |
98 | 99 | #assert(rr == None) # not supported by reference |
99 | 100 | #assert(rr.function_code < 0x80) # test that we are not an error |
|
105 | 106 | #---------------------------------------------------------------------------# |
106 | 107 | # diagnostic requests |
107 | 108 | #---------------------------------------------------------------------------# |
108 | | -rq = ReturnQueryDataRequest() |
| 109 | +rq = ReturnQueryDataRequest(unit=1) |
109 | 110 | rr = client.execute(rq) |
110 | | -assert(rr == None) # not supported by reference |
| 111 | +# assert(rr == None) # not supported by reference |
111 | 112 | #assert(rr.message[0] == 0x0000) # test the resulting message |
112 | 113 |
|
113 | | -rq = RestartCommunicationsOptionRequest() |
| 114 | +rq = RestartCommunicationsOptionRequest(unit=1) |
114 | 115 | rr = client.execute(rq) |
115 | 116 | #assert(rr == None) # not supported by reference |
116 | 117 | #assert(rr.message == 0x0000) # test the resulting message |
117 | 118 |
|
118 | | -rq = ReturnDiagnosticRegisterRequest() |
| 119 | +rq = ReturnDiagnosticRegisterRequest(unit=1) |
119 | 120 | rr = client.execute(rq) |
120 | 121 | #assert(rr == None) # not supported by reference |
121 | 122 |
|
122 | | -rq = ChangeAsciiInputDelimiterRequest() |
| 123 | +rq = ChangeAsciiInputDelimiterRequest(unit=1) |
123 | 124 | rr = client.execute(rq) |
124 | 125 | #assert(rr == None) # not supported by reference |
125 | 126 |
|
126 | | -rq = ForceListenOnlyModeRequest() |
| 127 | +rq = ForceListenOnlyModeRequest(unit=1) |
127 | 128 | client.execute(rq) # does not send a response |
128 | 129 |
|
129 | 130 | rq = ClearCountersRequest() |
130 | 131 | rr = client.execute(rq) |
131 | 132 | #assert(rr == None) # not supported by reference |
132 | 133 |
|
133 | | -rq = ReturnBusCommunicationErrorCountRequest() |
| 134 | +rq = ReturnBusCommunicationErrorCountRequest(unit=1) |
134 | 135 | rr = client.execute(rq) |
135 | 136 | #assert(rr == None) # not supported by reference |
136 | 137 |
|
137 | | -rq = ReturnBusExceptionErrorCountRequest() |
| 138 | +rq = ReturnBusExceptionErrorCountRequest(unit=1) |
138 | 139 | rr = client.execute(rq) |
139 | 140 | #assert(rr == None) # not supported by reference |
140 | 141 |
|
141 | | -rq = ReturnSlaveMessageCountRequest() |
| 142 | +rq = ReturnSlaveMessageCountRequest(unit=1) |
142 | 143 | rr = client.execute(rq) |
143 | 144 | #assert(rr == None) # not supported by reference |
144 | 145 |
|
145 | | -rq = ReturnSlaveNoResponseCountRequest() |
| 146 | +rq = ReturnSlaveNoResponseCountRequest(unit=1) |
146 | 147 | rr = client.execute(rq) |
147 | 148 | #assert(rr == None) # not supported by reference |
148 | 149 |
|
149 | | -rq = ReturnSlaveNAKCountRequest() |
| 150 | +rq = ReturnSlaveNAKCountRequest(unit=1) |
150 | 151 | rr = client.execute(rq) |
151 | 152 | #assert(rr == None) # not supported by reference |
152 | 153 |
|
153 | | -rq = ReturnSlaveBusyCountRequest() |
| 154 | +rq = ReturnSlaveBusyCountRequest(unit=1) |
154 | 155 | rr = client.execute(rq) |
155 | 156 | #assert(rr == None) # not supported by reference |
156 | 157 |
|
157 | | -rq = ReturnSlaveBusCharacterOverrunCountRequest() |
| 158 | +rq = ReturnSlaveBusCharacterOverrunCountRequest(unit=1) |
158 | 159 | rr = client.execute(rq) |
159 | 160 | #assert(rr == None) # not supported by reference |
160 | 161 |
|
161 | | -rq = ReturnIopOverrunCountRequest() |
| 162 | +rq = ReturnIopOverrunCountRequest(unit=1) |
162 | 163 | rr = client.execute(rq) |
163 | 164 | #assert(rr == None) # not supported by reference |
164 | 165 |
|
165 | | -rq = ClearOverrunCountRequest() |
| 166 | +rq = ClearOverrunCountRequest(unit=1) |
166 | 167 | rr = client.execute(rq) |
167 | 168 | #assert(rr == None) # not supported by reference |
168 | 169 |
|
169 | | -rq = GetClearModbusPlusRequest() |
| 170 | +rq = GetClearModbusPlusRequest(unit=1) |
170 | 171 | rr = client.execute(rq) |
171 | 172 | #assert(rr == None) # not supported by reference |
172 | 173 |
|
|
0 commit comments