0

I need to build communication between Multidrop bus nodes and main process running on Windows IoT over Raspberry Pi 3.
I know how to exchange data with 8 bit byte. It example of working code:

_serial_port = await SerialDevice.FromIdAsync(di.Id);

if (_serial_port == null) return false;

_serial_port.WriteTimeout = TimeSpan.FromMilliseconds(1000);
_serial_port.ReadTimeout = TimeSpan.FromMilliseconds(1000);
_serial_port.BaudRate = 9600;
_serial_port.Parity = SerialParity.None;
_serial_port.StopBits = SerialStopBitCount.One;
_serial_port.DataBits = 8;

dataWriteObject = new DataWriter(_serial_port.OutputStream);
dataReaderObject = new DataReader(_serial_port.InputStream);

dataWriteObject.WriteBytes(0xAA);
await dataWriteObject.StoreAsync();

await dataReaderObject.LoadAsync(1);
byte resp = dataReaderObject.ReadByte();

Here I transmit 1010 1010 and receive xxxx xxxx from the remote node.

The question.

  1. Lets say, remote node sends me 1010 1010 1
  2. Lets say I need send 1010 1010 1

What the code need to looks like?

UPDATE

I think about workaround solutions:

  1. To use parity bit of the UART. But I actually don't understand, how.
  2. Use COM -> USB converter, but actually there can be same problems of 9th bit.
  3. Use Adruino in middle that will implement RxTx 9 bit over GPIO and output data to Raspberry in our inner format.
Olga Pshenichnikova
  • 1,509
  • 4
  • 22
  • 47
  • 2
    Explaining *why* you need to solve this problem is pretty important to get a good answer. Most typically, 9-bit serial protocols are specified by hardware vendors. NAMA in the USA and EVA in Europe are examples, industry groups for coin-operated vending machines. They intentionally picked a format that you can't implement in software without being able to control the interrupt handler. A bug that's the feature, they want to sell you the hardware. Resistance is fairly futile, only 3) will get you anywhere and is very little joy to get reliable. – Hans Passant Feb 21 '19 at 09:50
  • My boss ask me to prepare software to be ready to talk devices MDB protocol... This why. – Olga Pshenichnikova Feb 21 '19 at 13:24
  • 1
    It is an acronym that means Multi Drop Bus. But yes, that's one that NAMA uses so my guess is likely to be accurate. Talk to the boss, this is buy and not build. – Hans Passant Feb 24 '19 at 09:03

1 Answers1

0

SerialDevice.Parity is used for error-checking instead of data transmitting. And application can't access this bit.

Use two bytes for 9 bits transmitting.

Send part:

dataWriteObject.WriteBytes(new byte[] { 0b10101010, 0b10000000});

Receive part:

                byte[] data = new byte[2] { 0, 0 };
                dataReaderObject.ReadBytes(data);
                int data1 = data[0];
                int data2 = data[1];
                data1 = data1 << 1;
                data2 = data2 >> 7;
                int data3 = data1 | data2;
Rita Han
  • 9,574
  • 1
  • 11
  • 24