Recent

Author Topic: 9-bit serial port communication  (Read 841 times)

shyub

  • Full Member
  • ***
  • Posts: 144
9-bit serial port communication
« on: October 29, 2025, 02:38:45 pm »
I encountered a device whose communication protocol uses 9 data bits. After transmitting each 9-bit packet, the device responds with a packet containing a start bit, 9 data bits, and 2 stop bits.
The TComPort component provides the ability to add a 9th bit (the Parity.Bits:=prMark or prSpace property). How can I determine the state of the 9th bit when receiving data?

MarkMLl

  • Hero Member
  • *****
  • Posts: 8572
Re: 9-bit serial port communication
« Reply #1 on: October 29, 2025, 03:14:57 pm »
Do the original devices contain PC-compatible serial ports, or something like the SCC which might (note that I've not checked this) be more flexible on account of their support for SDLC etc.? Or are they bit-banging it, or perverting SPI hardware?

I can't speak for TComPort and the rest, but I've just checked serial.pp (to which I was the most recent contributor) and there's no immediately-obvious way to do it, and I suspect that you'll be getting very heavily OS-dependent.

On reception, I think you'll need to look for a parity error on each symbol: which could get messed up by buffering.

On transmission, I think you'll need to set the top bit explicitly to mark or space: which might not work properly if symbols are already queued for transmission.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

shyub

  • Full Member
  • ***
  • Posts: 144
Re: 9-bit serial port communication
« Reply #2 on: October 29, 2025, 05:45:32 pm »
No, the exchange works like this: I transmit a byte (consisting of 9 bits) and substitute the desired value for the 9th bit (it works). The device responds. I can transmit the next byte with a delay long enough for me to check the parity.
The problem is, I can't determine whether there's a parity error when receiving.
I tried using the "OnError" and "OnRxFlag" events, but they never fire. Maybe I'm doing something wrong...

LeP

  • Sr. Member
  • ****
  • Posts: 347
Re: 9-bit serial port communication
« Reply #3 on: October 29, 2025, 05:46:36 pm »
You can start from here: https://stackoverflow.com/questions/14212660/how-to-access-my-9-data-bit-serial-port-on-a-pc

But I'm pretty sure that is not possible without an appropriate hardware.
Un Sistema per domarli, un IDE per trovarli, un codice per ghermirli e nel framework incatenarli.
An operating system to tame them, an IDE to find them, a code to catch them and in the framework chain them.

MarkMLl

  • Hero Member
  • *****
  • Posts: 8572
Re: 9-bit serial port communication
« Reply #4 on: October 29, 2025, 06:54:32 pm »
You can start from here: https://stackoverflow.com/questions/14212660/how-to-access-my-9-data-bit-serial-port-on-a-pc

But I'm pretty sure that is not possible without an appropriate hardware.

Any attempt to do this is- as I've said- likely to be heavily OS-dependent. Even if the hardware supports it.

I agree that link's useful, and there's discussion elsewhere in the context of AVR processors (i.e. as used in Arduinos but not necessarily using the Arduino libraries) where apparently their U(S)ARTS /can/ handle 9 bits.

My own feeling is that the OS- unless it specifically supports it- is going to get in the way: it will either make reliable bit setting and recovery impossible, or it will enforce sufficiently-long delays that communications will be glacial. That's particularly going to be the case if the comms hardware is interfaced via USB where several layers of packetisation must be considered: I've previously discussed related latency with FTDI who could offer no solution.

And off-the-shelf hardware is very likely to use counterfeit chips, at which point all bets are off.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

avra

  • Hero Member
  • *****
  • Posts: 2592
    • Additional info
« Last Edit: October 29, 2025, 08:14:05 pm by avra »
ct2laz - Conversion between Lazarus and CodeTyphon
bithelpers - Bit manipulation for standard types
pasettimino - Siemens S7 PLC lib

MarkMLl

  • Hero Member
  • *****
  • Posts: 8572
Re: 9-bit serial port communication
« Reply #6 on: October 29, 2025, 08:59:23 pm »
Just a mo. Looking at OP's "pretty picture"... I accept that that 9th bit isn't simple parity but are you absolutely sure that it isn't something CRC-like?

Noting Avra's agreement that some AVR chips can handle 9 bits of data, I think it might be worth using one of those on an Arduino-like board to monitor the comms line for an extended period and count the number of 9-bit symbol values encountered.

If, out of the 2^9 = 512 possibilities you actually see only around 256 then the 9th bit can- initially- be ignored: simply drop the parity.

Later on, either have an external device based on an AVR or similar chip which returns each 9-bit symbol as a 16-bit integer, or learn how to implement a USART in an FPGA >:-)

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

 

TinyPortal © 2005-2018