Questions about rs232 serial communication using python in windows

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.

  • Maybe command = bytearray([0xfe, 0xB1, 0x03, 0x00])

    – 

  • Or you can use command = b'\xfe\xB1\x03\x00'. Python bytes literal has extra characters that aren’t hex, but alter the value of the string, Python byte literal, classmethod int.from_bytes(bytes, byteorder=’big’, *, signed=False)

    – 

  • Thank you for your response. Sadly there is no response from the motor, it’s really hard to communicate.

    – 

Leave a Comment