]>
Commit | Line | Data |
---|---|---|
bfe7c799 BW |
1 | import time |
2 | ||
3 | import minimalmodbus | |
4 | ||
5 | minimalmodbus.PARITY= 'E' | |
6 | ||
7 | connection = minimalmodbus.Instrument("/dev/ttyUSB0", 1) | |
8 | ||
9 | while True: | |
10 | try: | |
11 | time.sleep(.05) | |
12 | ||
13 | # function 1 | |
14 | a = connection.read_bit(3, functioncode=1) | |
15 | ||
16 | # function 2 | |
17 | b = connection.read_bit(0, functioncode=2) | |
18 | ||
19 | # function 3 | |
20 | connection.read_register(99, functioncode=3) | |
21 | ||
22 | # function 4 | |
23 | connection.read_register(120, functioncode=4) | |
24 | ||
25 | # funciton 5 | |
26 | connection.write_bit(3, True, functioncode=5) | |
27 | ||
28 | # function 6 | |
29 | connection.write_register(1, 0b01010101, functioncode=6) | |
30 | ||
31 | # function 15 | |
32 | connection.write_bit(2, True, functioncode=15) | |
33 | ||
34 | # function 16 | |
35 | connection.write_register(1, 0b10101010, functioncode=16) | |
36 | ||
37 | except IOError: | |
38 | pass |