I’m trying to communicate with IKA hardware EUROSTAR 60. I can read data with no problem. But when I try to output a value(adjusting), my code fails and there is no error message whatsoever. The hardware is connected to my computer using a USB cable.
import serial
import time
serial_port = 'COM7'
baud_rate = 9600
def send_command(ser, command):
try:
full_command = f'{command} rn'
print(f"Sending command: '{full_command.strip()}'")
ser.write(full_command.encode())
time.sleep(0.5)
response = ser.readline().decode().strip()
print(f"Response: '{response}'")
return response
except Exception as e:
print(f"Error sending command: {e}")
return None
def main():
try:
ser = serial.Serial(serial_port, baudrate=baud_rate, bytesize=serial.SEVENBITS, parity=serial.PARITY_EVEN, stopbits=serial.STOPBITS_ONE, timeout=1)
time.sleep(2)
speed_limit = 213
command = f'OUT_SP_4 {speed_limit}'
response = send_command(ser, command)
if response:
print(f"Speed limit set to {speed_limit} RPM")
else:
print("Failed to set speed limit.")
except Exception as e:
print(f"Error: {e}")
finally:
ser.close()
if __name__ == "__main__":
main()
The code above tries to change the ‘set rpm’ value on the device to 213. But the response I get is empty and the value on the device stays the same.
Does anyone know how to communicate correctly?
AEO is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.