Files
MesinAbsen/serialConnect.py
Aries Wibowo 484ba05a65 Initial test
2026-04-22 09:19:12 +07:00

37 lines
905 B
Python

import serial
ser = serial.Serial('/dev/ttyACM0', 115200, timeout=1)
if ser:
print("Terhubung!")
else:
print("Gagal terhubung.")
#ser.write(b'\r\n')
#response = ser.read(100)
#print("Response:", response.decode(errors='ignore'))
#ser.write(bytes.fromhex('02 00 00 00 00 00 00 03'))
#response = ser.read(100)
#print("Response:", response.hex())
#while True:
# data = ser.readline()
# if data:
# print("Received:", data.decode(errors='ignore'))
#ser.write(b'~RS\n') # Try Reset
ser.write(b'~VER\n') # Try Version
ser.write(b'~ID\n') # Try Device ID
response = ser.read(100)
print("Response:", response.decode(errors='ignore'))
#ser.write(b'INFO\n')
#ser.write(b'PING\n')
##response = ser.read(100)
#print(response.decode('utf-8'))
#ser.write(b'RESET\n') # Kirim perintah reset
#response = ser.read(100) # Baca respons dari mesin
#print(response.decode('utf-8'))
ser.close()