24 lines
679 B
Plaintext
24 lines
679 B
Plaintext
import serial
|
|
import time
|
|
|
|
def testar_serial_can():
|
|
try:
|
|
ser = serial.Serial('COM6', 115200, timeout=1) # ou tente 9600, 38400, 500000...
|
|
print("Conectado na COM6")
|
|
|
|
# Teste simples: enviar algum dado (exemplo: comando comum de entrada CAN?)
|
|
ser.write(b'\x01\x30\x31') # Exemplo CAN ID 01, comando 0x30 (ler posição), CRC 0x31
|
|
|
|
print("Comando enviado, aguardando resposta...")
|
|
time.sleep(0.5)
|
|
|
|
while ser.in_waiting:
|
|
resposta = ser.read(ser.in_waiting)
|
|
print("Resposta recebida:", resposta.hex())
|
|
|
|
ser.close()
|
|
except Exception as e:
|
|
print("Erro:", e)
|
|
|
|
testar_serial_can()
|