-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserial_com2.py
More file actions
62 lines (50 loc) · 1.29 KB
/
serial_com2.py
File metadata and controls
62 lines (50 loc) · 1.29 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import serial
import struct
try:
ser = serial.Serial( # set parameters, in fact use your own :-)
port="/dev/ttyUSB0",
baudrate=9600,
bytesize=serial.SEVENBITS,
parity=serial.PARITY_EVEN,
stopbits=serial.STOPBITS_ONE
)
ser.isOpen() # try to open port, if possible print message and proceed with 'while True:'
print ("port is opened!")
except IOError: # if port is already opened, close it and open it again and print message
ser.close()
ser.open()
print ("port was already open, was closed and opened again!")
# typedef struct {
# int x;
# int y;
# }Point;
# typedef struct{
# // arrangment is important our value list
# struct structVal{
# int x;
# int y;
# };
# int16_t val;
# int16_t other_val;
# int16_t other_val2;
# Point point;
# structVal stcVal;
# // checksum is bellow must be
# uint16_t checksum;
# } SerialCommand;
# serial_com2Arduino2
while True:
val=ser.readline()
# print(val)
# https://docs.python.org/3/library/struct.html#format-characters
"""
page is our c/cpp struct valuable datas
"""
value=struct.unpack_from("HHHHHHHH",val)
print(value) # read value
print(value[7])
if value[7]==55:
print(value[0:3])
else:
print("not true val")
ser.close()