ademmler has asked for the wisdom of the Perl Monks concerning the following question:
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: BP: Serial protocol detection
by BrowserUk (Patriarch) on Jun 15, 2014 at 12:24 UTC | |
how to detect and interpret serial port data. I have "googled" a lot but I don't find a "general explanation". I have a couple of protocol specifications for serial devices, which I want to talk with and read from. The biggest hurdle for me is to get the "data stream" out of a continuous message I've never seen such a tutorial, and I've been playing with serial ports for 30+ years. Mind you, I haven't gone looking for a long time either :) There are basically two types of serial line protocol: In general, the former is easier and more efficient to deal with at the lower level. However, at the higher level, the latter allows you to use filetype line-oriented reads and writes provided that your libraries allow you to set the EOL character -- which Perl allows by the setting of $/ & $\. With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
| [reply] [d/l] [select] |
|
Re: BP: Serial protocol detection
by Anonymous Monk on Jun 15, 2014 at 23:35 UTC | |
A good module to access the serial port is Device::SerialPort in *NIX and Win32::SerialPort on Windows. Their docs as well as googling their names will get you some sample programs which is probably the easiest way to get started, here are some examples: Device::SerialPort Examples.., Reading Data from a Serial Port using Win32::SerialPort The general approach to read from the serial port is to read it a single byte at a time, unless you know exactly how many bytes you're expecting, in which case you can request that number of bytes from the driver. Make sure to read about the different timeout settings the driver accepts, so that you don't time out too soon or end up waiting for a byte forever in case one gets lost somewhere (which does tend to happen on serial ports). Also note that the modules I mentioned are generally blocking I/O, meaning that your program won't do anything else if it's waiting for data from the serial port. Although I've rarely needed it, there are ways to work around this, but it can be tricky to get right, so looking for help online is very helpful there too. Lastly, I've found it's important to remember the distinction between bytes and characters, a line which Perl unfortunately blurs a little from time to time. Most serial protocols I've seen express their data in bytes, and you want to keep treating them as such, and not as characters at the Unicode level, until the protocol calls for some explicit decoding of the bytes. | [reply] |
|
Re: BP: Serial protocol detection
by crusty_collins (Friar) on Jun 16, 2014 at 18:07 UTC | |
| [reply] [d/l] |