Note that there are some explanatory texts on larger screens.

plurals
  1. POruby serialport gem, who is responsible to check parity errors?
    text
    copied!<h3>gems</h3> <p>serialport (1.0.4)<br> Authors: Guillaume Pierronnet, Alan Stern, Daniel E. Shipton, Tobin<br> Richard, Hector Parra, Ryan C. Payne<br> Homepage: <a href="http://github.com/hparra/ruby-serialport/" rel="nofollow">http://github.com/hparra/ruby-serialport/</a><br> Library for using RS-232 serial ports. </p> <p>I am using this gem, and my device's specifications are as follows.</p> <ul> <li>9600bps</li> <li>7bits</li> <li>1 stop bit</li> <li>EVEN parity</li> </ul> <p>When I receive data like below, the unpacked data is still with parity bit.</p> <pre class="lang-rb prettyprint-override"><code>sp = SerialPort.new("/dev/serial-device", 9600, 7, 1, SerialPort::EVEN) data = sp.gets data.chars.each do |char| puts char.unpack("B*") end </code></pre> <p>ex. if <code>sp</code> receives <code>a</code>, the unpacked data is <code>11100001</code> instead of <code>01100001</code>, because it's EVEN parity.</p> <hr> <p>To convert the byte back the what it should be, I do like this</p> <pre class="lang-rb prettyprint-override"><code>data = sp.gets #gets 11100001 for 'a' (even parity) data.bytes.to_a.each do |byte| puts (byte &amp; 127).chr end </code></pre> <p>now, to me, this is a way low-level. I was expecting the serialport gem was to do this parity check, but as far as I read its document, it doesn't say anything about parity check.</p> <p>Am I missing a method that is already implemented in the gem, or is my work around above is nessesary since it's my responsibity to check the parity and find error?</p>
 

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