forked from vindevries/MD49-Python-Example
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmd49_serial.py
36 lines (25 loc) · 790 Bytes
/
md49_serial.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import serial
import struct
port = serial.Serial("/dev/ttyS0", baudrate=9600, parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE)
def writeBytes(bytes):
port.write(bytes)
def RESET_ENCODERS():
writeBytes("\x00\x35")
def SET_MODE(mode):
strMode = struct.pack("B",mode)
writeBytes("\x00\x34" + strMode)
def GET_ENCODER_1():
writeBytes("\x00\x23")
bytes = port.read(4)
encoderValue = struct.unpack('L',bytes)
print(str(encoderValue))
def SET_SPEED_1(speed):
strSpeed = struct.pack("B",speed)
writeBytes("\x00\x31" + strSpeed)
def SET_SPEED_2(speed):
strSpeed = struct.pack("B",speed)
writeBytes("\x00\x32" + strSpeed)
SET_MODE(0)
RESET_ENCODERS()
SET_SPEED_1(190)
GET_ENCODER_1()