[WIP] Всё еще пытаемся настроить modbuse
This commit is contained in:
parent
1429e85dfc
commit
261c243e31
16
main.py
16
main.py
@ -5,18 +5,22 @@ import time
|
||||
|
||||
serial_port = "COM5"
|
||||
baud_rate = 9600
|
||||
modbus_client = ModbusSerialClient(method='rtu', port=serial_port, baudrate=baud_rate)
|
||||
modbus_client = ModbusSerialClient(port=serial_port, baudrate=baud_rate, )
|
||||
|
||||
modbus_data = "0"
|
||||
|
||||
def poll_modbus():
|
||||
global modbus_data
|
||||
modbus_client.connect()
|
||||
while True:
|
||||
response = modbus_client.read_holding_registers(0, 1, unit=1)
|
||||
if not response.isError():
|
||||
modbus_data = response.registers[0]
|
||||
print(modbus_data)
|
||||
while True:
|
||||
try:
|
||||
response = modbus_client.read_discrete_inputs(0, 1, unit=1)
|
||||
print(response)
|
||||
if not response.isError():
|
||||
modbus_data = response.registers[0]
|
||||
print(modbus_data)
|
||||
except:
|
||||
pass
|
||||
|
||||
|
||||
|
||||
|
@ -1,9 +1,9 @@
|
||||
#include <ModbusSerial.h>
|
||||
const int GPIOCoil = 0;
|
||||
|
||||
ModbusSerial modbus(Serial, 10);
|
||||
ModbusSerial modbus(Serial, 1);
|
||||
bool coils[10];
|
||||
int pinToRead = 2;
|
||||
int pinToRead = 6;
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
|
Loading…
Reference in New Issue
Block a user