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