Line | |
---|
1 | import serial |
---|
2 | |
---|
3 | #if doesn't work, try : |
---|
4 | #sudo chmod a+rw /dev/ttyS0 |
---|
5 | #sudo stty crtscts -F /dev/ttyS0 |
---|
6 | # on a terminal |
---|
7 | |
---|
8 | def test(): |
---|
9 | return([3.1415,1,2,3]) |
---|
10 | |
---|
11 | def read_vertical_position(): |
---|
12 | output = "/dev/ttyS0" |
---|
13 | fichier = open(output, "w") |
---|
14 | fichier.write("\x08") |
---|
15 | fichier.close() |
---|
16 | ser = serial.Serial(port="/dev/ttyS0") |
---|
17 | #print("connected to :" + ser.portstr) |
---|
18 | A = ser.readline() |
---|
19 | ser.close() |
---|
20 | #print(A) |
---|
21 | X_Y_Z_unit_nb = [] |
---|
22 | a = "" |
---|
23 | for i in range(2,len(A)): |
---|
24 | if (A[i] == " ") : |
---|
25 | a = "" |
---|
26 | elif (A[i] == ";"): |
---|
27 | #print(a) |
---|
28 | if a != "": |
---|
29 | X_Y_Z_unit_nb.append(a) |
---|
30 | a = "" |
---|
31 | elif A[i] == "m" and A[i+1] == "m": |
---|
32 | X_Y_Z_unit_nb.append("mm") |
---|
33 | elif A[i] == "I" and A[i+1] == "n"and A[i+2] == "c"and A[i+3] == "h": |
---|
34 | X_Y_Z_unit_nb.append("inch") |
---|
35 | else : |
---|
36 | a += A[i] |
---|
37 | return(X_Y_Z_unit_nb) |
---|
38 | |
---|
39 | |
---|
40 | print(read_vertical_position()) |
---|
Note: See
TracBrowser
for help on using the repository browser.