comm.py
Код: Выделить всё
from time import sleep
from pySerialTransfer import pySerialTransfer as txfer
class struct:
control = 0
class receivestruct:
status = 0
if __name__ == '__main__':
try:
testStruct = struct
rstruct =receivestruct
link = txfer.SerialTransfer('COM7')
link.open()
sleep(2)
counter = 0
while True:
sendSize = 0
testStruct.control = counter
sendSize = link.tx_obj(testStruct.control, start_pos=sendSize)
link.send(sendSize)
print('sent')
#sleep(0.5)
read_correctly = False
while (read_correctly == False):
try:
if not (link.available()):
pass
recSize = 0
# this section returns errors with can't read str as int
rstruct.status = link.rx_obj(obj_type='i', start_pos=recSize)
counter = rstruct.status
recSize += txfer.STRUCT_FORMAT_LENGTHS['i']
print(rstruct.status)
read_correctly = True
except:
pass
except KeyboardInterrupt:
link.close()
Код: Выделить всё
#include "SerialTransfer.h"
SerialTransfer myTransfer;
uint32_t rcontrol;
uint32_t control;
void setup()
{
Serial.begin(115200);
myTransfer.begin(Serial);
}
void loop()
{
if(myTransfer.available())
{
// use this variable to keep track of how many
// bytes we've processed from the receive buffer
uint16_t recSize = 0;
recSize = myTransfer.rxObj(rcontrol, recSize);
control = rcontrol + 1;
uint16_t sendSize = 0;
sendSize = myTransfer.txObj(control, sendSize);
myTransfer.sendData(sendSize);
}
}
Код: Выделить всё
115
sent
115
sent
116
sent
116
sent
116
sent
116
sent
116
sent
116
sent
116
sent
116
sent
116
sent
117
sent
117
sent
117
sent
117
sent
117
sent
117
sent
117
sent
117
sent
117
sent
118
sent
118
sent
118
sent
118
sent
118
sent
118
sent
118
sent
118
sent
118
sent
119
sent
119
sent
119
sent
119
sent
119
sent
119
sent
119
sent
119
sent
Подробнее здесь: https://stackoverflow.com/questions/787 ... ion-issues