python - Sending binary data over a serial connection with pyserial -


i want preface noting lost right now, there may things don't make sense because have no idea i'm talking about. feel free dissect question long helpful.

alright, overall project i'm working on write program in python interface custom built temperature control unit (built this chip) , copy data memory buffer data points stored.

i not 1 programmed , i'm going off limited experience arduinos (also i'm new python). here of sent regarding commands interface it:

#define command_ping                'p' //  ->  'p' //  <-  'p' uuuu //      uuuu - unique number == 0x03645145  #define command_get_record_number   'i' //  -> 'i' //  <- 'i' nnnn //      nnnn - current record number (not written yet)  #define command_get_data            'd' //length 32-bit boundary //  ->  'd' ssss llll //  <-  'd' ddddddd... //      ssss - starting address (should, don't need @ 32-byte boundary) //      llll - data length - must multiplicity of 32 //      ddddddd... - data returned 

i can use con.write('p') fine , using con.readline() \x00\x00peqd\x03 converted hex 7045516403 (note values sent , returned little endian).

my problem 'd' command. think need send 'd' string along 2 32-bit binary values i'm not sure how that. i'm hardly sure of right questions ask, guys can give highly appreciated.

looking through internet resources (for hours) think might want use struct or maybe this? i'd love example showing whole process of connecting, writing, , reading to/from serial port.

something like

port.write(struct.pack('<cii', 'd', address, length) d = port.read(1)         #'d' expected data = port.read(length) #length bytes of data expected if d != 'd' or len(data) < length:     raise exception("bad response received") 

where < specifies little-endian byte order, c single char , i 32-bit int.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -