Created
August 26, 2022 10:14
-
-
Save mikekenneth/a486a65fa2489cde7842318f6bddd760 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import serial | |
import time | |
# Instantiate serial connection to the HD Ranger | |
hd_ranger_serial_port_id = '/dev/ttyUSB0' # 'COM5' | |
ser = serial.Serial(hd_ranger_serial_port_id, 115200) # open serial port | |
print(ser.name) # check which port was really used | |
# Get XON from HD Ranger | |
print(ser.read(1)) # Pour lire le XON | |
# Format BATTERY command | |
cmd = "*?BATTERY" | |
cr = hex(int('0D', base=16)) | |
formatted_command = cmd + cr | |
# Execute BATTERY command | |
ser.write(formatted_command.encode()) # write a string | |
# Read BATTERY command Response | |
time.sleep(1) | |
print(ser.read(1)) # Pour lire le XOFF | |
time.sleep(1) | |
print(ser.read(1)) # Pour lire le ACK(06) ou NAK(15) | |
time.sleep(1) | |
print(ser.read()) # Pour lire la reponse | |
ser.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment