Note that there are some explanatory texts on larger screens.

plurals
  1. POPython: What's the best way to send status bits and timestamps with PySerial
    primarykey
    data
    text
    <p>I have done a fair bit of searching and reading around but haven't found an exact clear answer. I am making python application which will communicate with another over the serial port. I have been using PySerial to accomplish this. The types of packets I want to send are status information and data readings. I am proposing to form of my packets as follows:</p> <pre><code>[ Start Byte ][ Length ][ Message ][ End Byte ][ Checksum ] </code></pre> <p>Although I don't think I need the end byte since have a length in there. Am I correct?</p> <p>I am thinking of shaping the 'Message' part of the packet for status info like so:</p> <pre><code>[ MsgTypeID ][ PacketID ][ Status Bits ][ Timestamp ] </code></pre> <p>The message ID here is just to differentiate that this is a status packet rather than a data packet. The status information itself is made up of 16 bits, representing the state of a number of subsystems in the sending application. For some of these subsystems, a single bit will provide enough info ('0' to say the subsystem is off/low/false, '1' for on/high/true). Others will require 2 or 3 bits (representing states and such). Prototyping the system up, I have been simply constructing a string concatenating the bits up to form a something like <code>'1001110101101100'</code> and sending this out the serial port, with the checksum being a modulo 256 of the status bits.</p> <p>I am pretty new to Python and serial communication but I know this is probably a waste of bandwidth. I know that PySerial has to send strings but representing each bit as a '0' or '1' like this is using a full string representation for each bit. I was wondering what is the best way to send these bits to reduce the bandwidth?</p> <p>For example, would I take each 8 bits, convert them to hex and send concatenated hex bytes, as in:</p> <pre><code>'10011101' + '01101100' </code></pre> <p>represented as</p> <pre><code>'\x9d' + '\x6c' </code></pre> <p>or should I send them as ASCII? I've also seen mentions of the Struct module. Should I be going down that route instead?</p> <p>The other thing I am wondering is how to represent the timestamp parts of the message.</p> <p>Any help, suggestions you can give me would be greatly appreciated.</p> <p>Thanks very much :) </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload