tecna ethernet wip
This commit is contained in:
parent
c22ca85f4d
commit
90832d382c
|
|
@ -78,6 +78,7 @@ risoluzione: 203
|
|||
|
||||
|
||||
[tecna_t3]
|
||||
connection_type: usb
|
||||
model: t3l
|
||||
port: COM4
|
||||
baudrate: 115200
|
||||
|
|
|
|||
|
|
@ -26,7 +26,8 @@ poll_time: 10
|
|||
hold_time: 10
|
||||
|
||||
[tecna_t3]
|
||||
port: /dev/ttyUSB0
|
||||
connection_type:ethernet
|
||||
ip_address:10.10.10.2
|
||||
model: t3l
|
||||
|
||||
[fixture_rfid]
|
||||
|
|
|
|||
|
|
@ -16,6 +16,8 @@ from pymodbus.payload import BinaryPayloadBuilder, BinaryPayloadDecoder
|
|||
|
||||
if "--sim-modbus" not in sys.argv:
|
||||
from pymodbus.client import ModbusSerialClient as ModbusClient
|
||||
from pymodbus.client import ModbusTcpClient as ModbusTcpClient
|
||||
|
||||
else:
|
||||
from components.dummies.pymodbus import ModbusClient
|
||||
|
||||
|
|
@ -33,8 +35,9 @@ class ModbusComponent(Component):
|
|||
self.lock = QMutex()
|
||||
|
||||
def config_changed(self):
|
||||
|
||||
# Read configuration values
|
||||
self.connection_type = self.config[self.name].get("connection_type", "usb").lower()
|
||||
self.ip_address = self.config[self.name].get("ip_address", "10.10.10.2").lower()
|
||||
self.method = self.config[self.name].get("method", "rtu").lower()
|
||||
self.port = self.config[self.name]["port"]
|
||||
self.baudrate = int(self.config[self.name]["baudrate"])
|
||||
|
|
@ -48,22 +51,30 @@ class ModbusComponent(Component):
|
|||
# Lock the interaction to ensure thread safety
|
||||
self.lock.lock()
|
||||
try:
|
||||
# Initialize the Modbus client
|
||||
self.client = ModbusClient(
|
||||
method=self.method,
|
||||
port=self.port,
|
||||
stopbits=self.stopbits,
|
||||
bytesize=self.bytesize,
|
||||
parity=self.parity,
|
||||
baudrate=self.baudrate,
|
||||
timeout=self.timeout,
|
||||
strict=False,
|
||||
)
|
||||
if not self.client.connect():
|
||||
raise ConnectionError(f"Cannot connect to Modbus on port {self.port}")
|
||||
if self.connection_type == "ethernet":
|
||||
self.client = ModbusTcpClient(host=self.ip_address)
|
||||
if not self.client.connect():
|
||||
raise ConnectionError(
|
||||
f"Cannot connect to Modbus on IP address {self.ip_address} and port {self.port}"
|
||||
)
|
||||
|
||||
if not self.client.is_socket_open():
|
||||
raise ConnectionError(f"Connection socket not open on port {self.port}")
|
||||
else:
|
||||
# Initialize the Modbus client
|
||||
self.client = ModbusClient(
|
||||
method=self.method,
|
||||
port=self.port,
|
||||
stopbits=self.stopbits,
|
||||
bytesize=self.bytesize,
|
||||
parity=self.parity,
|
||||
baudrate=self.baudrate,
|
||||
timeout=self.timeout,
|
||||
strict=False,
|
||||
)
|
||||
if not self.client.connect():
|
||||
raise ConnectionError(f"Cannot connect to Modbus on port {self.port}")
|
||||
|
||||
if not self.client.is_socket_open():
|
||||
raise ConnectionError(f"Connection socket not open on port {self.port}")
|
||||
|
||||
except FileNotFoundError as e:
|
||||
error_message = f"Serial port error: {self.port} not found. Check your configuration."
|
||||
|
|
|
|||
33
src/test/evtest.py
Normal file
33
src/test/evtest.py
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
import evdev
|
||||
from evdev import InputDevice, categorize, ecodes
|
||||
|
||||
def capture_input_events():
|
||||
try:
|
||||
# List available input devices
|
||||
devices = [InputDevice(path) for path in evdev.list_devices()]
|
||||
for device in devices:
|
||||
print(device.path, device.name, device.phys)
|
||||
|
||||
# Prompt the user to select a device
|
||||
device_path = input("Enter the path of the device you want to capture (e.g., /dev/input/eventX): ")
|
||||
device = InputDevice(device_path)
|
||||
|
||||
print(f"Capturing events from {device.name}...")
|
||||
|
||||
for event in device.read_loop():
|
||||
if event.type == ecodes.EV_KEY:
|
||||
print(categorize(event))
|
||||
elif event.type == ecodes.EV_REL:
|
||||
pass # print(categorize(event))
|
||||
elif event.type == ecodes.EV_ABS:
|
||||
pass # print(categorize(event))
|
||||
else:
|
||||
pass # print(event)
|
||||
|
||||
except FileNotFoundError:
|
||||
print("Device not found.")
|
||||
except KeyboardInterrupt:
|
||||
print("Capture stopped.")
|
||||
|
||||
if __name__ == "__main__":
|
||||
capture_input_events()
|
||||
Loading…
Reference in New Issue
Block a user