5

I have developed an embedded solution which communicates over a Multi Drop Bus and now I would like to develop a PC based application which monitors traffic on the bus.

MDB supports true 9 data bits (plus start/stop/parity - and *no fudging* by using the parity bit as a 9th data bit) whereas standard Windows and Linux libraries offer a maximum of 8 data bits.

I have a StarTech PCI2S950 PC serial port card which supports 9-data bits, but am not sure how to code my monitoring app & have googled a lot to no great avail.

I would prefer to code in C (or Delphi, or C++). I have a slight preference for Cygwn, but am willing to use straightforward Windows or Linux.

Just anything to read/write 9 data bits over that PC serial port card.

Can anyone help?

Mawg says reinstate Monica
  • 38,334
  • 103
  • 306
  • 551

4 Answers4

5

The card you selected is not suitable for this application. It has just plain RS-232 ports, it is not suitable for a multi-drop bus. You'll need to shop elsewhere for an EIA-485 style bus interface, you could only find those at industrial electronics suppliers. By far the best way is to go through the National Automatic Merchandising Association, the industry group that owns the MDB specification.

The 9-bit data format is just a trick and is used in the MDB protocol to mode-switch between address bytes and data bytes. All ports on the bus listen to address bytes, only the addressed port listens to data bytes.

The 9th bit is simply the parity bit that any UART can generate. The fundamental data size is still 8 bits. An UART auto-generates the parity bit from the way it was initialized, you can choose between mark, space, odd and even parity.

Now this is easy to do in a micro-controller that has an UART, the kind of processor used on a bus like this. You simply re-program the UART on-the-fly, telling it to generate mark parity when you send the address bytes. And re-program it again to space parity when you send the data bytes. Waiting for the fifo to empty will typically be necessary although it depends on the actual UART chip.

That is a lot harder to do on a regular Windows or Linux machine, there's a driver between the user mode program and the UART. The driver generates a "transmit buffer empty" status bit, like WaitCommmEvent() for EV_TXEMPTY on Windows, but this doesn't include the fifo empty status, it only indicates that the buffer is empty. A workaround would be to wait for the buffer empty status and then sleep() long enough to ensure that the fifo is emptied. A fifo is typically 16 bytes deep so sleep for 16 times the bit time. You'll need the datasheet for the UART on the card you selected to know these details for sure.

Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
  • +1 thanks very much for your help. I am not a hardware guy, only software, so I might not undertsand comepltely :-/ The NAMA MDB/IPC spec in section 2.1 says Baud Serial Bit 1 Start Bit 8 Data Bits 1 Mode Bit 1 Stop Bit 11 Bits Total LSB MSB Start 0 1 2 3 4 5 6 7 Mode Stop – Mawg says reinstate Monica Jan 15 '13 at 04:41
  • +1 thanks very much for your help. I am not a hardware guy, only software, so I might not undertsand comepltely :-/ The NAMA MDB/IPC spec in section 2.1 says "1 Start Bit, 8 Data Bits, 1 Mode Bit, 1 Stop Bit, 11 Bits Total", so I suppose that I could klduge using the parity bit; but why would it not work with a 9 data bit card? I already have it working on an Atmel UC3 which has 9 databits and I don't kludge the parity there. I just wanted to interface a PC with the MCB. NAMA does nto appear to sell hardware or publish software on their website, so I doubt that they would help. – Mawg says reinstate Monica Jan 15 '13 at 04:50
  • Btw, did you ever develop vending machine software? – Mawg says reinstate Monica Jan 15 '13 at 04:51
  • 1
    It is a hardware problem, the electrical bus interface is unusual and is completely unlike RS-232. Not in the least because of the NRZ encoding. If there's anybody that can help you find a vendor that can supply you the hardware then it is NAMA. You'll have to pick up the phone, can't help you do that. 312-346-0370 – Hans Passant Jan 15 '13 at 10:39
  • +1 and thanks again. At the moment I have the Atmel board talking to a coin box. Since it has two serial ports, I might get a second board an use it to conenct 9-bit MD to 8-bit PC. I also googled and found a few solutions including some which convert 9-bit MS to USB at the PC. – Mawg says reinstate Monica Jan 16 '13 at 03:21
5

The document at http://www.semiconductorstore.com/pdf/newsite/oxford/ox16c950b.pdf describes the differences between various UARTs. While your StarTech board includes the 16C950, which is RS-485 (and 9-bit) capable, it uses it in RS-232 compatible (550) mode, similar to 16550/8250 from IBM-PC days, and supports max 8 bit data.

You need a board with the same chip (16C950) but that exposes the RS-485 compatible 950 mode that supports 9 bit data as per the spec. And any board claiming such support would have to come with custom drivers for Windows, since Microsoft's is 8 bit only.

There are several other chips that can do 9-bit RS-485 mentioned here but again finding Windows driver support will be tricky. And, of course, many boards use 16C950 but only in 8-bit and/or RS-232 only mode, and without appropriate drivers.

In answer to your related question on Superuser, sawdust suggested the Sealevel 7205e, which looks like a good choice, with Windows driver support. It is pricey but they specifically mention 9-bit, RS-485 support, and Windows drivers. It may well be your best option.

Community
  • 1
  • 1
Peter Krnjevic
  • 1,070
  • 15
  • 20
3

Under Win32 serial ports are just files, so you create a handle for it with CreateFile and then use a DCB structure to set up the configuration options (the members are documented here and include number of data bits as ByteSize).

There's a good walk through here: http://www.codeproject.com/Articles/3061/Creating-a-Serial-communication-on-Win32

Vicky
  • 12,934
  • 4
  • 46
  • 54
  • Thanks, this looks very good, BUT ... both of those pages seem to suggest an 8 bit limit on data size "The number of data bits must be 5 to 8 bits" & "BYTE ByteSize: Number of bits/byte, 4-8 (default = 8)" – Mawg says reinstate Monica Jan 08 '13 at 10:51
  • 1
    That's talking about the 8250 UART though. You said in your question that you've purchased a serial port that supports 9 bits. As long as you have it registered as a COM port on the system that should be fine. – Vicky Jan 08 '13 at 11:22
  • 1
    In fact, tell us what you've bought specifically and then we might be more able to help... – Vicky Jan 08 '13 at 11:24
  • The first reference talks about the 8520, while the second just talks of the datasize without mentioning the 8520. Unfortunately I just left the office but will post the exact details of the card in about 12 hours time. Thanks again – Mawg says reinstate Monica Jan 08 '13 at 12:49
0

The link provided shows the card supports 9 data bits and Windows 8, so I would presume all the cards features are available to the application through the standard Windows API.

Apart from setting the correct data format in a DCB and opening the port, I would have thought the standard ReadFile would work. I wonder if the data read in would actually be 2*8 bit bytes which represent the 9 data bits, rather than a continuous 9 bits streamed in (which you will need to decode at a later date).

Is the 9th bit used for some purpose other than data?

Neil
  • 11,059
  • 3
  • 31
  • 56