modpoll 0.6.4__tar.gz → 0.7.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: modpoll
3
- Version: 0.6.4
3
+ Version: 0.7.1
4
4
  Summary: A New Command Line Tool for Modbus
5
5
  Home-page: https://helloysd.gitlab.io/modpoll
6
6
  License: MIT
@@ -75,7 +75,7 @@ pip install modpoll
75
75
  Optionally, pyserial library can be installed for Modbus-RTU communication,
76
76
 
77
77
  ```bash
78
- pip install modpoll[serial]
78
+ pip install 'modpoll[serial]'
79
79
  ```
80
80
 
81
81
  Upgrade the tool via the following command,
@@ -107,7 +107,9 @@ pipx upgrade modpoll
107
107
  Let's start exploring *modpoll* with *modsim* device, run the following command to get a first glimpse,
108
108
 
109
109
  ```bash
110
- modpoll --tcp modsim.topmaker.net --config https://raw.githubusercontent.com/gavinying/modpoll/master/examples/modsim.csv
110
+ modpoll \
111
+ --tcp modsim.topmaker.net \
112
+ --config https://raw.githubusercontent.com/gavinying/modpoll/master/examples/modsim.csv
111
113
  ```
112
114
 
113
115
  <p align="center">
@@ -186,14 +188,19 @@ docker run -p 5020:5020 helloysd/modsim
186
188
  It will create a virtual Modbus TCP device running at `localhost:5020`, and then you can poll it using *modpoll* tool,
187
189
 
188
190
  ```bash
189
- modpoll --tcp localhost --tcp-port 5020 --config https://raw.githubusercontent.com/gavinying/modpoll/master/examples/modsim.csv
191
+ modpoll \
192
+ --tcp localhost \
193
+ --tcp-port 5020 \
194
+ --config https://raw.githubusercontent.com/gavinying/modpoll/master/examples/modsim.csv
190
195
  ```
191
196
 
192
197
  > Use `sudo` before the docker command if you want to use the standard port `502`.
193
198
 
194
199
  ```bash
195
200
  sudo docker run -p 502:5020 helloysd/modsim
196
- modpoll --tcp localhost --config https://raw.githubusercontent.com/gavinying/modpoll/master/examples/modsim.csv
201
+ modpoll \
202
+ --tcp localhost \
203
+ --config https://raw.githubusercontent.com/gavinying/modpoll/master/examples/modsim.csv
197
204
  ```
198
205
 
199
206
  ### Publish data to MQTT broker
@@ -203,7 +210,10 @@ This is a useful function of this new *modpoll* tool, which provides a simple wa
203
210
  The following example uses a public MQTT broker `mqtt.eclipseprojects.io` for test purpose. You can also set up your own MQTT broker locally using [mosquitto](https://mosquitto.org/download/).
204
211
 
205
212
  ```bash
206
- modpoll --tcp modsim.topmaker.net --config https://raw.githubusercontent.com/gavinying/modpoll/master/examples/modsim.csv --mqtt-host mqtt.eclipseprojects.io
213
+ modpoll \
214
+ --tcp modsim.topmaker.net \
215
+ --mqtt-host mqtt.eclipseprojects.io \
216
+ --config https://raw.githubusercontent.com/gavinying/modpoll/master/examples/modsim.csv
207
217
  ```
208
218
 
209
219
  With successful data polling and publishing, you can subscribe the topic `modpoll/modsim` on the same MQTT broker `mqtt.eclipseprojects.io` to view the collected data.
@@ -241,7 +251,7 @@ The *modpoll* tool will subscribe to the topic `<mqtt_topic_prefix>/<deviceid>/s
241
251
  ```
242
252
 
243
253
 
244
- ## Run in docker
254
+ ## Run with docker
245
255
 
246
256
  A docker image has been provided for user to directly run the program without local installation,
247
257
 
@@ -251,17 +261,23 @@ A docker image has been provided for user to directly run the program without lo
251
261
 
252
262
  It shows the version of the program by default.
253
263
 
254
- Similar to the above *modsim* test, we can poll the first 5 holding registers with `docker run`,
264
+ Similar to the above *modsim* test, we can poll data with `docker run`, in order to avoid printing out received data, the argument `--daemon` or `-d` is recommended to use with docker.
255
265
 
256
266
  ```bash
257
- docker run helloysd/modpoll modpoll --tcp modsim.topmaker.net --config https://raw.githubusercontent.com/gavinying/modpoll/master/examples/modsim.csv
267
+ docker run helloysd/modpoll \
268
+ modpoll -d \
269
+ --tcp modsim.topmaker.net \
270
+ --config https://raw.githubusercontent.com/gavinying/modpoll/master/examples/modsim.csv
258
271
  ```
259
272
 
260
273
  If you want to load a local configure file, you need to mount a local folder onto container volume,
261
274
  for example, if the child folder `examples` contains the config file `modsim.csv`, we can use it via the following command,
262
275
 
263
276
  ```bash
264
- docker run -v $(pwd)/examples:/app/examples helloysd/modpoll modpoll --tcp modsim.topmaker.net --config /app/examples/modsim.csv
277
+ docker run -v $(pwd)/examples:/app/examples helloysd/modpoll \
278
+ modpoll -d \
279
+ --tcp modsim.topmaker.net \
280
+ --config /app/examples/modsim.csv
265
281
  ```
266
282
 
267
283
 
@@ -270,25 +286,38 @@ for example, if the child folder `examples` contains the config file `modsim.csv
270
286
  - Connect to Modbus TCP device
271
287
 
272
288
  ```bash
273
- modpoll --tcp 192.168.1.10 --config examples/modsim.csv
289
+ modpoll \
290
+ --tcp 192.168.1.10 \
291
+ --config examples/modsim.csv
274
292
  ```
275
293
 
276
294
  - Connect to Modbus RTU device
277
295
 
278
296
  ```bash
279
- modpoll --rtu /dev/ttyUSB0 --rtu-baud 9600 --config contrib/eniwise/scpms6.csv
297
+ modpoll \
298
+ --rtu /dev/ttyUSB0 \
299
+ --rtu-baud 9600 \
300
+ --config contrib/eniwise/scpms6.csv
280
301
  ```
281
302
 
282
303
  - Connect to Modbus TCP device and publish data to MQTT broker
283
304
 
284
305
  ```bash
285
- modpoll --tcp modsim.topmaker.net --tcp-port 5020 --config examples/modsim.csv --mqtt-host mqtt.eclipseprojects.io
306
+ modpoll \
307
+ --tcp modsim.topmaker.net \
308
+ --tcp-port 5020 \
309
+ --mqtt-host mqtt.eclipseprojects.io \
310
+ --config examples/modsim.csv
286
311
  ```
287
312
 
288
313
  - Connect to Modbus TCP device and export data to local csv file
289
314
 
290
315
  ```bash
291
- modpoll --tcp modsim.topmaker.net --tcp-port 5020 --config examples/modsim.csv --export data.csv
316
+ modpoll \
317
+ --tcp modsim.topmaker.net \
318
+ --tcp-port 5020 \
319
+ --export data.csv \
320
+ --config examples/modsim.csv
292
321
  ```
293
322
 
294
323
 
@@ -52,7 +52,7 @@ pip install modpoll
52
52
  Optionally, pyserial library can be installed for Modbus-RTU communication,
53
53
 
54
54
  ```bash
55
- pip install modpoll[serial]
55
+ pip install 'modpoll[serial]'
56
56
  ```
57
57
 
58
58
  Upgrade the tool via the following command,
@@ -84,7 +84,9 @@ pipx upgrade modpoll
84
84
  Let's start exploring *modpoll* with *modsim* device, run the following command to get a first glimpse,
85
85
 
86
86
  ```bash
87
- modpoll --tcp modsim.topmaker.net --config https://raw.githubusercontent.com/gavinying/modpoll/master/examples/modsim.csv
87
+ modpoll \
88
+ --tcp modsim.topmaker.net \
89
+ --config https://raw.githubusercontent.com/gavinying/modpoll/master/examples/modsim.csv
88
90
  ```
89
91
 
90
92
  <p align="center">
@@ -163,14 +165,19 @@ docker run -p 5020:5020 helloysd/modsim
163
165
  It will create a virtual Modbus TCP device running at `localhost:5020`, and then you can poll it using *modpoll* tool,
164
166
 
165
167
  ```bash
166
- modpoll --tcp localhost --tcp-port 5020 --config https://raw.githubusercontent.com/gavinying/modpoll/master/examples/modsim.csv
168
+ modpoll \
169
+ --tcp localhost \
170
+ --tcp-port 5020 \
171
+ --config https://raw.githubusercontent.com/gavinying/modpoll/master/examples/modsim.csv
167
172
  ```
168
173
 
169
174
  > Use `sudo` before the docker command if you want to use the standard port `502`.
170
175
 
171
176
  ```bash
172
177
  sudo docker run -p 502:5020 helloysd/modsim
173
- modpoll --tcp localhost --config https://raw.githubusercontent.com/gavinying/modpoll/master/examples/modsim.csv
178
+ modpoll \
179
+ --tcp localhost \
180
+ --config https://raw.githubusercontent.com/gavinying/modpoll/master/examples/modsim.csv
174
181
  ```
175
182
 
176
183
  ### Publish data to MQTT broker
@@ -180,7 +187,10 @@ This is a useful function of this new *modpoll* tool, which provides a simple wa
180
187
  The following example uses a public MQTT broker `mqtt.eclipseprojects.io` for test purpose. You can also set up your own MQTT broker locally using [mosquitto](https://mosquitto.org/download/).
181
188
 
182
189
  ```bash
183
- modpoll --tcp modsim.topmaker.net --config https://raw.githubusercontent.com/gavinying/modpoll/master/examples/modsim.csv --mqtt-host mqtt.eclipseprojects.io
190
+ modpoll \
191
+ --tcp modsim.topmaker.net \
192
+ --mqtt-host mqtt.eclipseprojects.io \
193
+ --config https://raw.githubusercontent.com/gavinying/modpoll/master/examples/modsim.csv
184
194
  ```
185
195
 
186
196
  With successful data polling and publishing, you can subscribe the topic `modpoll/modsim` on the same MQTT broker `mqtt.eclipseprojects.io` to view the collected data.
@@ -218,7 +228,7 @@ The *modpoll* tool will subscribe to the topic `<mqtt_topic_prefix>/<deviceid>/s
218
228
  ```
219
229
 
220
230
 
221
- ## Run in docker
231
+ ## Run with docker
222
232
 
223
233
  A docker image has been provided for user to directly run the program without local installation,
224
234
 
@@ -228,17 +238,23 @@ A docker image has been provided for user to directly run the program without lo
228
238
 
229
239
  It shows the version of the program by default.
230
240
 
231
- Similar to the above *modsim* test, we can poll the first 5 holding registers with `docker run`,
241
+ Similar to the above *modsim* test, we can poll data with `docker run`, in order to avoid printing out received data, the argument `--daemon` or `-d` is recommended to use with docker.
232
242
 
233
243
  ```bash
234
- docker run helloysd/modpoll modpoll --tcp modsim.topmaker.net --config https://raw.githubusercontent.com/gavinying/modpoll/master/examples/modsim.csv
244
+ docker run helloysd/modpoll \
245
+ modpoll -d \
246
+ --tcp modsim.topmaker.net \
247
+ --config https://raw.githubusercontent.com/gavinying/modpoll/master/examples/modsim.csv
235
248
  ```
236
249
 
237
250
  If you want to load a local configure file, you need to mount a local folder onto container volume,
238
251
  for example, if the child folder `examples` contains the config file `modsim.csv`, we can use it via the following command,
239
252
 
240
253
  ```bash
241
- docker run -v $(pwd)/examples:/app/examples helloysd/modpoll modpoll --tcp modsim.topmaker.net --config /app/examples/modsim.csv
254
+ docker run -v $(pwd)/examples:/app/examples helloysd/modpoll \
255
+ modpoll -d \
256
+ --tcp modsim.topmaker.net \
257
+ --config /app/examples/modsim.csv
242
258
  ```
243
259
 
244
260
 
@@ -247,25 +263,38 @@ for example, if the child folder `examples` contains the config file `modsim.csv
247
263
  - Connect to Modbus TCP device
248
264
 
249
265
  ```bash
250
- modpoll --tcp 192.168.1.10 --config examples/modsim.csv
266
+ modpoll \
267
+ --tcp 192.168.1.10 \
268
+ --config examples/modsim.csv
251
269
  ```
252
270
 
253
271
  - Connect to Modbus RTU device
254
272
 
255
273
  ```bash
256
- modpoll --rtu /dev/ttyUSB0 --rtu-baud 9600 --config contrib/eniwise/scpms6.csv
274
+ modpoll \
275
+ --rtu /dev/ttyUSB0 \
276
+ --rtu-baud 9600 \
277
+ --config contrib/eniwise/scpms6.csv
257
278
  ```
258
279
 
259
280
  - Connect to Modbus TCP device and publish data to MQTT broker
260
281
 
261
282
  ```bash
262
- modpoll --tcp modsim.topmaker.net --tcp-port 5020 --config examples/modsim.csv --mqtt-host mqtt.eclipseprojects.io
283
+ modpoll \
284
+ --tcp modsim.topmaker.net \
285
+ --tcp-port 5020 \
286
+ --mqtt-host mqtt.eclipseprojects.io \
287
+ --config examples/modsim.csv
263
288
  ```
264
289
 
265
290
  - Connect to Modbus TCP device and export data to local csv file
266
291
 
267
292
  ```bash
268
- modpoll --tcp modsim.topmaker.net --tcp-port 5020 --config examples/modsim.csv --export data.csv
293
+ modpoll \
294
+ --tcp modsim.topmaker.net \
295
+ --tcp-port 5020 \
296
+ --export data.csv \
297
+ --config examples/modsim.csv
269
298
  ```
270
299
 
271
300
 
@@ -8,7 +8,10 @@ def get_parser():
8
8
  description=f"modpoll v{__version__} - A New Command Line Tool for Modbus"
9
9
  )
10
10
  parser.add_argument(
11
- "-v", "--version", action="version", version=f"modpoll v{__version__}"
11
+ "-v",
12
+ "--version",
13
+ action="version",
14
+ version=f"modpoll v{__version__}",
12
15
  )
13
16
  parser.add_argument(
14
17
  "-f",
@@ -16,51 +19,57 @@ def get_parser():
16
19
  required=True,
17
20
  help="A local path or URL of Modbus configuration file. Required!",
18
21
  )
22
+ parser.add_argument(
23
+ "-d",
24
+ "--daemon",
25
+ action="store_true",
26
+ help="Run in daemon mode without printing result. Recommended to use with docker",
27
+ )
19
28
  parser.add_argument(
20
29
  "-r",
21
30
  "--rate",
22
- default=5.0,
23
31
  type=float,
24
- help="The sampling rate (s) to poll modbus device, Defaults to 5.0",
32
+ default=10.0,
33
+ help="The sampling rate (s) to poll modbus device, Defaults to 10.0",
25
34
  )
26
35
  parser.add_argument(
27
36
  "-1", "--once", action="store_true", help="Only run polling at one time"
28
37
  )
29
38
  parser.add_argument(
30
39
  "--interval",
31
- default=1.0,
32
40
  type=float,
41
+ default=1.0,
33
42
  help="The time interval in seconds between two polling, Defaults to 1.0",
34
43
  )
35
44
  parser.add_argument(
36
45
  "--tcp", help="Act as a Modbus TCP master, connecting to host TCP"
37
46
  )
38
47
  parser.add_argument(
39
- "--tcp-port", default=502, type=int, help="Port for MODBUS TCP. Defaults to 502"
48
+ "--tcp-port", type=int, default=502, help="Port for MODBUS TCP. Defaults to 502"
40
49
  )
41
50
  parser.add_argument(
42
51
  "--udp", help="Act as a Modbus UDP master, connecting to host UDP"
43
52
  )
44
53
  parser.add_argument(
45
- "--udp-port", default=502, type=int, help="Port for MODBUS UDP. Defaults to 502"
54
+ "--udp-port", type=int, default=502, help="Port for MODBUS UDP. Defaults to 502"
46
55
  )
47
56
  parser.add_argument("--rtu", help="pyserial URL (or port name) for RTU serial port")
48
57
  parser.add_argument(
49
58
  "--rtu-baud",
50
- default=9600,
51
59
  type=int,
60
+ default=9600,
52
61
  help="Baud rate for serial port. Defaults to 9600",
53
62
  )
54
63
  parser.add_argument(
55
64
  "--rtu-parity",
56
- default="none",
57
65
  choices=["none", "odd", "even"],
66
+ default="none",
58
67
  help="Parity for serial port. Defaults to none",
59
68
  )
60
69
  parser.add_argument(
61
70
  "--timeout",
62
- default=3.0,
63
71
  type=float,
72
+ default=3.0,
64
73
  help="Response time-out seconds for MODBUS devices, Defaults to 3.0",
65
74
  )
66
75
  parser.add_argument(
@@ -69,9 +78,6 @@ def get_parser():
69
78
  default=None,
70
79
  help="The file name to export references/registers",
71
80
  )
72
- parser.add_argument(
73
- "-p", "--print-result", action="store_true", help="Print received data."
74
- )
75
81
  parser.add_argument(
76
82
  "--mqtt-host",
77
83
  default=None,
@@ -79,8 +85,8 @@ def get_parser():
79
85
  )
80
86
  parser.add_argument(
81
87
  "--mqtt-port",
82
- default=1883,
83
88
  type=int,
89
+ default=1883,
84
90
  help="1883 for non-TLS or 8883 for TLS, Defaults to 1883",
85
91
  )
86
92
  parser.add_argument(
@@ -95,9 +101,8 @@ def get_parser():
95
101
  )
96
102
  parser.add_argument(
97
103
  "--mqtt-qos",
98
- default=0,
99
- type=int,
100
104
  choices=[0, 1, 2],
105
+ default=0,
101
106
  help="MQTT QoS value. Defaults to 0",
102
107
  )
103
108
  parser.add_argument(
@@ -115,8 +120,8 @@ def get_parser():
115
120
  parser.add_argument("--mqtt-cacerts", default=None, help="Path to ca keychain")
116
121
  parser.add_argument(
117
122
  "--mqtt-tls-version",
118
- default=None,
119
123
  choices=["tlsv1.2", "tlsv1.1", "tlsv1"],
124
+ default="tlsv1.2",
120
125
  help="TLS protocol version, can be one of tlsv1.2 tlsv1.1 or tlsv1",
121
126
  )
122
127
  parser.add_argument(
@@ -126,8 +131,8 @@ def get_parser():
126
131
  )
127
132
  parser.add_argument(
128
133
  "--diagnostics-rate",
129
- default=0,
130
134
  type=float,
135
+ default=0,
131
136
  help="Time in seconds as publishing period for each device diagnostics",
132
137
  )
133
138
  parser.add_argument(
@@ -137,8 +142,8 @@ def get_parser():
137
142
  )
138
143
  parser.add_argument(
139
144
  "--loglevel",
140
- default="INFO",
141
145
  choices=["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"],
146
+ default="INFO",
142
147
  help="Set log level, Defaults to INFO",
143
148
  )
144
149
  parser.add_argument(
@@ -146,8 +151,14 @@ def get_parser():
146
151
  )
147
152
  parser.add_argument(
148
153
  "--delay",
149
- default=0,
150
154
  type=int,
155
+ default=0,
151
156
  help="Time to delay sending first request in seconds after connecting. Default to 0",
152
157
  )
158
+ parser.add_argument(
159
+ "--framer",
160
+ default="default",
161
+ choices=["default", "ascii", "binary", "rtu", "socket"],
162
+ help="The type of framer for modbus message. Use default framer if not specified.",
163
+ )
153
164
  return parser
@@ -418,24 +418,39 @@ def modbus_setup(config, event):
418
418
  parity = "E"
419
419
  else:
420
420
  parity = "N"
421
- master = ModbusSerialClient(
422
- method="rtu",
423
- port=args.rtu,
424
- stopbits=1,
425
- bytesize=8,
426
- parity=parity,
427
- baudrate=int(args.rtu_baud),
428
- timeout=args.timeout,
429
- reset_socket=True,
430
- )
421
+ if args.framer == "default":
422
+ master = ModbusSerialClient(
423
+ args.rtu,
424
+ baudrate=int(args.rtu_baud),
425
+ bytesize=8,
426
+ parity=parity,
427
+ stopbits=1,
428
+ timeout=args.timeout,
429
+ )
430
+ else:
431
+ master = ModbusSerialClient(
432
+ args.rtu,
433
+ baudrate=int(args.rtu_baud),
434
+ bytesize=8,
435
+ parity=parity,
436
+ stopbits=1,
437
+ framer=args.framer,
438
+ timeout=args.timeout,
439
+ )
431
440
  elif args.tcp:
432
- master = ModbusTcpClient(
433
- args.tcp, args.tcp_port, timeout=args.timeout, reset_socket=True
434
- )
441
+ if args.framer == "default":
442
+ master = ModbusTcpClient(args.tcp, port=args.tcp_port, timeout=args.timeout)
443
+ else:
444
+ master = ModbusTcpClient(
445
+ args.tcp, port=args.tcp_port, framer=args.framer, timeout=args.timeout
446
+ )
435
447
  elif args.udp:
436
- master = ModbusUdpClient(
437
- args.udp, args.udp_port, timeout=args.timeout, reset_socket=True
438
- )
448
+ if args.framer == "default":
449
+ master = ModbusUdpClient(args.udp, port=args.udp_port, timeout=args.timeout)
450
+ else:
451
+ master = ModbusUdpClient(
452
+ args.udp, port=args.udp_port, framer=args.framer, timeout=args.timeout
453
+ )
439
454
  else:
440
455
  log.error(
441
456
  "You must specify a modbus access method, either --rtu, --tcp or --udp"
@@ -460,8 +475,8 @@ def modbus_poll():
460
475
  return
461
476
  event_exit.wait(timeout=args.interval)
462
477
  master.close()
463
- # printout result, if -p or --print-result are set
464
- if args.print_result:
478
+ # print out result, if not in daemon mode
479
+ if not args.daemon:
465
480
  modbus_print()
466
481
 
467
482
 
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "modpoll"
3
- version = "0.6.4"
3
+ version = "0.7.1"
4
4
  description = "A New Command Line Tool for Modbus"
5
5
  authors = ["Ying Shaodong <helloysd@gmail.com>"]
6
6
  readme = "README.md"
File without changes
File without changes
File without changes
File without changes
File without changes