(New)SoftwareSerial parity bit?

Hi,

I try to use the SoftwareSerial or the NewSoftwareSerial libraries to communicate with a device which only accepts: 8bits of data, 1 bit of even parity and 2 stop bits.

I understood that (New)SoftwareSerial only works with 8 data bits and 1 start/stop bit.

Any way to modify (New)SoftwareSerial to have parity bits and more than one stop bit?

First question: what device are you talking about?

You can adapt the library to receive and send the extra bits:
First overload the begin() method so the number of stopbits and parity can be set (store these values in an internal var);

void NewSoftSerial::begin(long speed, byte stopbits=1, char parity = 'N')  // this makes 1 stopbit and None Parity the default
{
  _stopbits = stopbits;
  _parity = parity;
...
}

Then change : void NewSoftSerial::recv() so that depending on the number of stopbits set it reads 0, 1 or 2 stopbits AND handle parity

Search for :
// skip the stop bit
tunedDelay(_rx_delay_stopbit);
DebugPulse(_DEBUG_PIN2, 1);

this becomes something like:

   // handle parity bits
    if (_parity != 'N') 
    {
      tunedDelay(_rx_delay_stopbit);  // better read and check the parity bit :)
    }
    // skip the stop bits
    for (int i=0; i< _stopbits; i++) tunedDelay(_rx_delay_stopbit);

    DebugPulse(_DEBUG_PIN2, 1);

Then change: void NewSoftSerial::write(uint8_t b) so that it handles stopbits and parity correctly. This is more complex as you must first calculate the value of the paritybit and send it directly after sending the 8 databits. Take care of the inverse flag ! Same for the stopbits. Left as an exercise for the reader :wink:

succes Rob