Questions about rs232 serial communication using python in windows

90 Views Asked by At

I'm currently trying to do RS232 communication using python.

The communication manual is as shown in the picture below.

Instruction Overview

Stirrer control(rpm up to 1000)

I followed it and created the communication code, but it's not working, so I'm contacting you guys.

The code below sends a signal to the OS20 pro model overhead stirrer to change the rpm value to 1000.

import serial

ser = serial.Serial('COM7', 9600, timeout=1)
def calculate_checksum(data): #calculate checksum
    checksum = sum(data[1:]) & 0xFF
    return bytes([checksum])

print("Start")
print(ser.name)

command = b'0xfe0xB10x030x00'
checksum = calculate_checksum(command)
command_with_checksum = command + checksum

ser.write(command_with_checksum)

print("Reading")
read = ser.readline().decode('ascii')
print("Reading: ", read)

ser.close()

Is there something wrong with the checksum side? Or is it because I made the command wrong and sent it?

Thank you for reading.

Sends a signal to the OS20 pro model overhead stirrer to change the rpm value to 1000.

1

There are 1 best solutions below

0
SirAmir On

use this instead. may work:)

command_with_checksum = command.decode("utf-8") + checksum.decode("utf-8")
ser.write(command_with_checksum.encode())