A
A
Alexey2018-10-27 16:02:33
Python
Alexey, 2018-10-27 16:02:33

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()

The instruction includes one page on which it is written how the request is formed. The request for setting 100 mV is actually taken from it.
55 aa - some identifier;
00 64 is 100 (mV) in hexadecimal;
Checksum: 05 + 04 + 00 + 64 = 6D
It also says that "8 Low bits of 6D" are taken for the checksum, but 6D is present in the example request.
As a result, turning on and off work, but setting 100 mV or any other value does not work (a certain error code 05 is returned), although it is clear that the principle of generating a request in all three cases is the same, only the number of characters differs.
The kit comes with a simple program for dummies, written in Delphi7 (there is no source code). With this program, the volts are set.
Now, in fact, the question is: where am I wrong? Everything is complicated by the fact that exactly the example given by the Chinese developers themselves does not work, i.e. this is not self-employment.
And if I'm right about everything, and this is a mistake in the instructions, then maybe someone knows what boards / controllers are used in these power supplies, and whether this equipment can be found, for example, by the drivers on the disk, because that the technical support of the Chinese is at zero, and I would not want to disassemble the power source to see what kind of iron is there.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
longclaps, 2018-10-27
@Eig

Here's a hint .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question