2

I've a serialPort communication to a device wich send me a packege of 9 bits data. I'm using c#. the data are 8 bits and one bit to check if the byte is a data or a command if it's a command then the 9th bit is 1 else is 0. the problem is that the serialPort implemented in .Net accept only 8 bits. In some answer i've seen that can man use the parity bit to send and receive the 9 bits data but must restart the port everytime changing the parity value. the restarting is noway because I'll lose the ID of comunication with the device and the dialoge cycle is each 12ms. Can someone give me a clue how to solve this. Thanks!

Amin Ben
  • 53
  • 10
  • 8 bits = 1 byte, if you want 9 bits need 2 byte (16 bits). – Jnavero Dec 12 '16 at 10:23
  • @Jnavero yes it s, but the 9 th bit is a state bit. the problem by parsing the data .Net, the serialport class don t allow to control the 9th bit, the unity is one byte. – Amin Ben Dec 12 '16 at 10:26
  • Ok, then you have 8 bit data and 1 stop bit, haven't you? – Jnavero Dec 12 '16 at 10:28
  • @Jnavero the data format is: 9bit, No parity, 1 stop bit, 125Kbaud, A byte with the 9th bit set is a command byte A byte with the 9th bit clear is a data byte – Amin Ben Dec 12 '16 at 10:37
  • It is very weird, but i found this: http://digital.ni.com/public.nsf/allkb/3BDC7FF03541F772862564990057F919 What is your serial device? – Jnavero Dec 12 '16 at 10:58
  • I've via RS485, a controller, wich set the position of a stepper and give a feedback. Your link is for LabView, the problem in using the parity bit is that .Net don't accept to alternate the parity without cutting the communication, What stop the stream. I've found a library that can manipulate the problem https://www.adontec.com/super_e.htm#9-BIT-MULTIDROP .What I'm asking is there an opensource Library to .Net wich do the same job? – Amin Ben Dec 12 '16 at 11:22
  • It is a simple trick that vendors use to force you to buy their hardware. They know that you do not stand a chance to do this correctly in software on a protected-mode operating system with commodity hardware, it requires either a custom device driver or a microcontroller that can alter the UART initialization on-the-fly. Resistance is futile, you have to buy. – Hans Passant Dec 12 '16 at 12:59
  • See http://superuser.com/questions/411386/seeking-9-bit-serial-port-card-for-windows-pc/411438#411438 – sawdust Dec 12 '16 at 21:49
  • @HansPassant thank you! – Amin Ben Dec 13 '16 at 12:24
  • @sawdust thank you too! in the link it s possible to set the parity of a connected serialPort but if I switch the parity for each byte in the stream (r and w) this will interrupt the connection or not? or should I catch the errors? (sorry I don't have the opportunity to test it live, I implement it only now) – Amin Ben Dec 13 '16 at 12:24
  • What the schemes for using the parity bit typically fail to mention is that this would have to be done in the device driver, and DMA cannot be employed. Programmed I/O has to be used instead, meaning much slower I/O, and possible receiver overrun with the combination of fast baudrate & slow CPU. For output only, there's this termios scheme: https://viereck.ch/linux-mark-space-parity/ – sawdust Dec 14 '16 at 00:23

0 Answers0