Загрузить файлы в «/»

Добавлена функ. чтения по ячейке
This commit is contained in:
2025-12-23 00:39:03 +09:00
parent 794e5b3cac
commit 427174fec4

67
main.py
View File

@@ -74,45 +74,50 @@ class caser:
self.controller_number = hex(controller_number) self.controller_number = hex(controller_number)
def send_command(self, header : int, cell_number : int, command : int): def send_command(self, cell_number : int, command : int, header=138):
try: active_comport = serial.Serial(self.comport, baudrate=self.baudrate)
active_comport = serial.Serial(self.comport, baudrate=self.baudrate) logger.info(f"Connected to {active_comport.name }")
logger.info(f"Connected to {active_comport.name }")
# 1 - header(8Ahex) (138dec), 2 - controller number(01), 3 - cell number(04), 4 - command(11), 5 - checksum(9E) # 1 - header(8Ahex) (138dec), 2 - controller number(01), 3 - cell number(04), 4 - command(11), 5 - checksum(9E)
# *4 - (11) - open, (00) - close # *4 - (11) - open, (00) - close
data = [int(header).to_bytes(1, 'little'),
int(self.controller_number, 16).to_bytes(1, 'little'),
cell_number.to_bytes(1, 'little'),
command.to_bytes(1, 'little')]
data_string = b''
for i in data:
data_string += i
data = [header.to_bytes(1, 'little'), checksum = self.bc_calculator.xor_bcc(data_string)
int(self.controller_number, 16).to_bytes(1, 'little'),
cell_number.to_bytes(1, 'little'),
command.to_bytes(1, 'little')]
#проблемы тут
checksum = self.bc_calculator.xor_bcc(data)
exit()
packet = data + [checksum]
active_comport.write(b''.join(packet))
# time.sleep(0.2)
# добавь таймаут на чтение ответа от устройства data_string += checksum.to_bytes(1, 'little')
line = active_comport.read(10) active_comport.write(data_string)
return active_comport.read(5)
if line: def read_controller(self, cell_number : int, command=51, header=128):
print("Received:", line) active_comport = serial.Serial(self.comport, baudrate=self.baudrate)
logger.info(f"Connected to {active_comport.name }")
data = [header.to_bytes(1, 'little'),
int(self.controller_number, 16).to_bytes(1, 'little'),
cell_number.to_bytes(1, 'little'),
command.to_bytes(1, 'little')]
data_string = b''
for i in data:
data_string += i
except ValueError as ve: checksum = self.bc_calculator.xor_bcc(data_string)
logger.error(f"Invalid port or baudrate: {str(ve)}")
except serial.SerialException as se: data_string += checksum.to_bytes(1, 'little')
logger.error(f"Serial port error: {str(se)}") active_comport.write(data_string)
return active_comport.read(5)
except Exception as e:
logger.error(f"Unexpected error: {str(e)}")
zxc = caser(device_hwid="PID=1A86:7523", baudrate=9600, zxc = caser(device_hwid="PID=1A86:7523", baudrate=9600,
config=config) config=config)
zxc.set_controller_number(1) zxc.set_controller_number(1)
zxc.set_port_device() zxc.set_port_device()
# у тебя беды с хексами и типами данных # добавь *aargs
zxc.send_command(138, 1, 17) print(zxc.read_controller(1))
exit() print(zxc.send_command(1, 17))
print(zxc.read_controller(1))