Answer the question
In order to leave comments, you need to log in
PySerial How to correctly send a request?
I have a Chinese PSU-W-FDA power supply for a CNILaser laser. Voltage regulation, switching on and off is implemented through the RS-232 / USB interface, by sending simple requests, I deliberately simplify the code:
from serial import Serial
def send_message(self, v):
# Выключение лазера
if v == 0:
hex_string = '55 aa 03 00 03'
# Включение лазер
elif v == 1:
hex_string = '55 aa 03 01 04'
# Установка 100 мВ
elif v == 2:
hex_string = '55 aa 05 04 00 64 6D'
message = bytes.fromhex(hex_string)
ser = Serial(port='COM4', baudrate=9600, timeout = 0.1)
ser.open()
self.write(ser, message)
if ser.is_open:
ser.flushInput()
ser.flushOutput()
sleep(0.1)
try:
ser.write(message)
except Exception as exc:
print('type: {0}, message: {1}'.format(type(exc), str(exc)))
else:
res = ser.readline()
print(res)
ser.close()
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question