Board index » delphi » Need 11-bit frame read/write to com port

Need 11-bit frame read/write to com port

I need to be able to send / receive the following bit structure:
   1 Start bit
   8 Data bits
   1 Mode bit
   1 Stop bit

The Start and Stop bits of course are fixed.  I have to be able to set the
Mode bit high or low outgoing, and read an incoming Mode bit.  

I've checked all the com-port components, and none seem to allow this extra
variable Mode bit.  I've looked at the Port command, but the Delphi help has
very little info on how to use it.  If this is the answer, could someone post
a more verbose description on how to use it, with reference to my problem, of
course :)

This is for interacting with a Coin Changer on the Multi-Drop-Bus (MDB)
standard.

 

Re:Need 11-bit frame read/write to com port


In message <3263bc6...@ntnews.compusmart.ab.ca>, dr...@compusmart.ab.ca (Rob Eitzen) said:

Quote
> I need to be able to send / receive the following bit structure:
>    1 Start bit
>    8 Data bits
>    1 Mode bit
>    1 Stop bit

> The Start and Stop bits of course are fixed.  I have to be able to set the
> Mode bit high or low outgoing, and read an incoming Mode bit.  

> I've checked all the com-port components, and none seem to allow this extra
> variable Mode bit.  I've looked at the Port command, but the Delphi help has
> very little info on how to use it.  If this is the answer, could someone post
> a more verbose description on how to use it, with reference to my problem, of
> course :)

Your 'mode' bit is normally used for parity on a PC system, and rarely used
in conjunction with 8 data bits. The standard PC UART will do what you want,
but you may have difficulty getting that functionality out of a generic comms
component. For most normal comms applications, the parity bit is handled
transparently by the hardware if it's used at all.

On a multidrop bus, this bit is set to indicate that the associated data
represents an address, and that the device with that address should wake up
and pay attention. Microcontrollers often have that functionality built-in,
but it's straightforward to code it yourself.

If you are writing a 16-bit program, it's probably easiest to go directly
to the UART. It can get very messy if you want interrupt-driven buffered
communications, but simple "write a value"/"read a value" code is easy.
You'll need the manufacturer's data sheet for the 8250/16450/16550 chip
(these are all the same thing to a first approximation) or you might well
find enough info in a book on assembler programming or PC hardware.

The Delphi I/O port functions probably seem unclear to you because exactly
*what* you read from/write to a port depends on what sort of hardware the
port belongs to.

If you are writing a Win32 program, life is a bit more complicated. You can
*probably* do it with the comms API functions provided your data rate is
not too high. This is because you'll have to do a load of control/status
calls for every character rather than just letting Win32 buffer them as
normal.

If the above is not enough to get you going, you probably need to buy a
book on using your PC to control external devices. I can't offer you any
specific suggestions, but I've seen several over the years. Maybe someone
can offer a title or two.

-----------------------------------------------------------------------
Steve Rencontre               |  st...@dstrip.demon.co.uk (business)
If it works, it's obsolete.   |  steve...@cix.compulink.co.uk (private)
-----------------------------------------------------------------------

Re:Need 11-bit frame read/write to com port


Quote
dr...@compusmart.ab.ca (Rob Eitzen) writes:
>I need to be able to send / receive the following bit structure:
>   1 Start bit
>   8 Data bits
>   1 Mode bit
>   1 Stop bit
>The Start and Stop bits of course are fixed.  I have to be able to set the
>Mode bit high or low outgoing, and read an incoming Mode bit.  

Jesus! Are these characters serious? That's a disgusting protocol you've
got there.

The only way I can think of to read this bit is to set your parity to (as
an example) even, then test for a parity error on input and count the
bits in the data byte. A byte with an odd number of bits with good parity
must have the mode bit set, and with bad parity the mode bit must be
zero. The opposite applies for a byte with an even number of bits.

For output, you'd be needing to toggle parity between mark and space as
required between each byte, and make sure the output buffer has emptied
before you send your next byte. Ugly as sin.

So what you have is the need for three different types of parity, two for
output and one for input. I'd call that unworkable.

Quote
>I've checked all the com-port components, and none seem to allow this extra
>variable Mode bit.  I've looked at the Port command, but the Delphi help has
>very little info on how to use it.  If this is the answer, could someone post
>a more verbose description on how to use it, with reference to my problem, of
>course :)
>This is for interacting with a Coin Changer on the Multi-Drop-Bus (MDB)
>standard.

--
Luke Webber

* Note: The opinions expressed by Luke Webber are in no way supported *
*       by his employers, Luke Webber Consulting Services             *

Other Threads