]>
Commit | Line | Data |
---|---|---|
5e069133 BW |
1 | #!/usr/bin/env python3 |
2 | # | |
3 | # A quick script to genererate modbus test data, it requires minimalmodbus. | |
4 | # | |
5 | # This is free and unencumbered software released into the public domain. | |
bfe7c799 BW |
6 | import time |
7 | ||
8 | import minimalmodbus | |
9 | ||
10 | minimalmodbus.PARITY= 'E' | |
11 | ||
12 | connection = minimalmodbus.Instrument("/dev/ttyUSB0", 1) | |
13 | ||
14 | while True: | |
15 | try: | |
16 | time.sleep(.05) | |
17 | ||
18 | # function 1 | |
19 | a = connection.read_bit(3, functioncode=1) | |
20 | ||
21 | # function 2 | |
22 | b = connection.read_bit(0, functioncode=2) | |
23 | ||
24 | # function 3 | |
25 | connection.read_register(99, functioncode=3) | |
26 | ||
27 | # function 4 | |
28 | connection.read_register(120, functioncode=4) | |
29 | ||
30 | # funciton 5 | |
31 | connection.write_bit(3, True, functioncode=5) | |
32 | ||
33 | # function 6 | |
34 | connection.write_register(1, 0b01010101, functioncode=6) | |
35 | ||
36 | # function 15 | |
37 | connection.write_bit(2, True, functioncode=15) | |
38 | ||
39 | # function 16 | |
40 | connection.write_register(1, 0b10101010, functioncode=16) | |
41 | ||
42 | except IOError: | |
43 | pass |