Пример #1
0
def initmodbusandread(i):
    try:
        if (registers.get(i)[4]["send"]) is True:
            print(i)
            instrument = mb.Instrument('/dev/ttyS1', slave_id)
            instrument.serial.baudrate = 9600  # Baud
            instrument.serial.bytesize = 8
            instrument.serial.stopbits = 1
            instrument.serial.timeout = 2  # seconds
            instrument.address = slave_id   # this is the slave address number
            instrument.mode = mb.MODE_RTU   # rtu or ascii mode
            read(i, instrument)
    except IOError:
        registers.get(i)[5]["value"] = '0'
        print("Failed to read from instrument")
Пример #2
0
def read(i, instrument):
    try:
        value = instrument.read_register(i, registers.get(i)[2]["decimal"], 4)
        gpio.output(led, 1)
        time.sleep(0.1)
        print(i)
        print(value)
        gpio.output(led, 0)
        time.sleep(0.1)

        registers.get(i)[5]["value"] = value
        print(i)
        print(value)
        time.sleep(0.2)
    except:
        registers.get(i)[5]["value"] = '0'
        print("can't read {} rig".format(i))
Пример #3
0
import time
from var import registers
import pandas as pd

from findslave import find_slave_id
print(registers)
slave_ids = find_slave_id()
slave_ids = [1, 2, 3]
uid = "28487678947878"
file_name = uid + '.csv'

while True:
    for slave_id in slave_ids:
        for i in range(3000, 3064):
            try:
                if (registers.get(i)[4]["send"]) is True:

                    instrument = mb.Instrument('/dev/ttyUSB0', slave_id)

                    # instrument.serial.port          # this is the serial port name
                    instrument.serial.baudrate = 9600  # Baud
                    instrument.serial.bytesize = 8

                    instrument.serial.stopbits = 1
                    instrument.serial.timeout = 2  # seconds

                    instrument.address = slave_id  # this is the slave address number
                    instrument.mode = mb.MODE_RTU  # rtu or ascii mode
                    # instrument.debug = True
                    # print(i, end=" ")
                    try: