Skip to content

Commit 3c1654b

Browse files
author
harunkurt.me
committed
python file import our reading files and tupple arrangment for list at python script
1 parent 6b64820 commit 3c1654b

2 files changed

Lines changed: 31 additions & 23 deletions

File tree

‎serial_com2.py‎

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,38 +23,40 @@
2323
# int y;
2424
# }Point;
2525
# typedef struct{
26+
# // arrangment is important our value list
2627

27-
# int16_t val;
28-
# int16_t other_val;
29-
# int16_t other_val2;
30-
# uint16_t checksum;
31-
3228
# struct structVal{
3329
# int x;
3430
# int y;
3531
# };
36-
32+
33+
# int16_t val;
34+
# int16_t other_val;
35+
# int16_t other_val2;
3736
# Point point;
3837
# structVal stcVal;
38+
# // checksum is bellow must be
39+
# uint16_t checksum;
40+
41+
3942
# } SerialCommand;
4043

44+
# serial_com2Arduino2
45+
4146
while True:
4247
val=ser.readline()
4348
# print(val)
4449
# https://docs.python.org/3/library/struct.html#format-characters
4550
"""
4651
page is our c/cpp struct valuable datas
4752
"""
48-
value=struct.unpack_from("HHHH",val)
49-
# print(value)
50-
if value[3]==25:
51-
print(value[0:3])
52-
elif value[3]==55:
53+
value=struct.unpack_from("HHHHHHHH",val)
54+
print(value) # read value
55+
print(value[7])
56+
57+
if value[7]==55:
5358
print(value[0:3])
54-
# if value[2]==
5559
else:
5660
print("not true val")
57-
# print(value[0:3])
58-
# print(value)
5961

6062
ser.close()

‎serial_com2Arduino2/serial_com2Arduino2.ino‎

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,22 @@ typedef struct {
88
int y;
99
}Point;
1010
typedef struct{
11+
// arrangment is important our value list
1112

12-
int16_t val;
13-
int16_t other_val;
14-
int16_t other_val2;
15-
uint16_t checksum;
16-
1713
struct structVal{
1814
int x;
1915
int y;
2016
};
21-
17+
18+
int16_t val;
19+
int16_t other_val;
20+
int16_t other_val2;
2221
Point point;
2322
structVal stcVal;
23+
// checksum is bellow must be
24+
uint16_t checksum;
25+
26+
2427
} SerialCommand;
2528

2629
SerialCommand Command;
@@ -35,12 +38,15 @@ void loop() {
3538
// put your main code here, to run repeatedly:
3639
Command.val=(int16_t)15;
3740
Command.other_val=(int16_t)42;
38-
Command.other_val2=(int16_t)25;
41+
Command.other_val2=(int16_t)16;
3942
//Command.a=(int16_t)"Hello World";
4043
//Command.checksum = (uint16_t)(Command.val^ Command.other_val ^ Command.other_val2);
4144

42-
Command.point.x=15;
43-
Command.stcVal.x=15;
45+
Command.point.x=11;
46+
Command.point.y=12;
47+
48+
Command.stcVal.x=21;
49+
Command.stcVal.y=22;
4450

4551
Command.checksum=(uint16_t)Sensor1;
4652

0 commit comments

Comments
 (0)