[alt.msdos.programmer] Microsoft C & serial comms

se@comp.lancs.ac.uk (Steve Elliott) (08/08/90)

I'd like some advice/help on the above topic.
Specifically, I'm trying to program a card reader through
COM1 with a Microsoft C (v5.1) program.
To initialise the lock, the docs state that "break level must be
off more than 2 seconds".
That's got me stumped. What is break level? Can I program it from C?
If so, how?
Thanks, 
	Steve
-- 
se@uk.ac.lancs.comp
University of Lancaster, Department of Computing,
Engineering Building, Bailrigg, Lancaster, LA1 4YR, UK
PHONE: +44 524 65201 ext 3783.

feit@cs.odu.edu (Mark A. Feit) (08/11/90)

In article <990@dcl-vitus.comp.lancs.ac.uk> se@comp.lancs.ac.uk (Steve Elliott) writes:

   I'd like some advice/help on the above topic.
   Specifically, I'm trying to program a card reader through
   COM1 with a Microsoft C (v5.1) program.
   To initialise the lock, the docs state that "break level must be
   off more than 2 seconds".

   That's got me stumped.

Don't sweat it.  Serial communications is a real jungle.

   What is break level?

The "break condition" means the UART must set the TXD line to its
"space" condition and hold it there for longer than one SDU (serial
data unit, the length of time it takes to transmit start, data,
parity, and stop bits for one character).  In your case, you must have
the UART hold the TXD line in its space condition for at least two
seconds.

   Can I program it from C?

Yes and no.  Your best bet is to write a short assembly-language
driver which will alter the UART's line control register (LCR), wait
for two seconds, and reset it to its normal state.

A little advice if I may: Head for your local bookstore and pick up a
copy of "C Programmer's Guide to Serial Communications" by Joe
Campbell.  It's published by Howard W. Sams and Company, lists for
$22.95, and contains two disks with source code of all examples in the
book.  It's a worthwhile investment if you're going to be doing any
communications work on PCs.  (It also includes an XMODEM driver
written in C, which I found really handy on my current project.)


						- Mark

................................... ................................... 
: Mark A. Feit                     : feit@cs.odu.edu                  :
: Old Dominion University CS Dept. : ...!xanth!feit                   :
: Norfolk, Virginia, U.S.A., Earth : "Where are my socks, anyway?"    :
................................... ................................... 
"Programming is 10% science, 25% ingenuity, and 65% the art of getting
the ingenuity to work with the science."
--

						- Mark

................................... ................................... 
: Mark A. Feit                     : feit@cs.odu.edu                  :
: Old Dominion University CS Dept. : ...!xanth!feit                   :
: Norfolk, Virginia, U.S.A., Earth : "Where are my socks, anyway?"    :
................................... ................................... 
"Programming is 10% science, 25% ingenuity, and 65% the art of getting
the ingenuity to work with the science."

PLFaith@cup.portal.com (Patrick L Faith) (08/11/90)

well "break" is used a couple of different ways, but they all come
down to this, if the serial port does not transfer a character at
the specified baud rate for the 8/7 bits of time it takes, then
there is a break set in the serial driver(atleast if you are using u8250).
So breaks are all to easy to send, just dont put anything out through
the port for a given amount of time - 500 mSec is fine - so is 2 seconds.
I like the book "C programmers guide to serial communications" of its 600+
pages it devotes about 2 pgs to break, which isn't indexed either.

				P L Faith

darcy@druid.uucp (D'Arcy J.M. Cain) (08/13/90)

In article <32673@cup.portal.com> PLFaith@cup.portal.com (Patrick L Faith) writes:
>well "break" is used a couple of different ways, but they all come
>down to this, if the serial port does not transfer a character at
>the specified baud rate for the 8/7 bits of time it takes, then
>there is a break set in the serial driver(atleast if you are using u8250).
>So breaks are all to easy to send, just dont put anything out through
>the port for a given amount of time - 500 mSec is fine - so is 2 seconds.
>I like the book "C programmers guide to serial communications" of its 600+
>pages it devotes about 2 pgs to break, which isn't indexed either.
>
Bzzzzzzzzzzzzzzzzzzzzt!!!!

In what universe?  Do you mean that a caller to a BBS puts out a break between
each keystroke while connected?  Pay attention class.  There will be a pop
quiz at the end.

on a serial connection the normal state of the 8250 SOUT pin is a logic 1. 
When a character is output a frame is assembled consisting of  1 start bit,
7 or 8 data bits, an optional parity bit and 1 or 2 stop bits.  The start
bit is a 0, the stop bits are 1 and the data and parity follows the data
and 8250 parity generation setup.  So say you transmit 'A' at 7 bit odd
parity 1 stop then the frame looks like this:
             0 1 0 0 0 0 0 1 1
When we add the idle bits before and after the character then we have:
     1 1 1 1 1 1 1 1 1 1 1 0 1 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1
As you can see the first 0 bit (the start bit) signals the receiver that
a character is starting.  It then assembles the next 7 bits into a character
and one more bit for the parity.  If the next bit is not a 1 then a framing
error occurs.

To send a break, you set a logic 0 long enough to have all zeros for
the start, data, parity and stop bits.  This special case is recognized
by the receiver as a break condition.  It looks like this:
      1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1
As long as the number of zeros is more than the total of a normal frame.

To generate this on a PC you set bit 6 in the line control register to 1
for the desired length of time.  This register is at port 0x3fb for COM1
and 2fb for COM2.  Don't forget to read the current contents first.  Here
is a snippet:

    int lcr;
    ...
    lcr = inportb(0x3fb);   /* or 0x2fb for COM2 */
    outportb(0x3fb, lcr | 0x40);
    delay(); /* for sufficient time */
    outportb(3fb, lcr);   /* restore it */

-- 
D'Arcy J.M. Cain (darcy@druid)     |
D'Arcy Cain Consulting             |   MS-DOS:  The Andrew Dice Clay
West Hill, Ontario, Canada         |   of operating systems.
+ 416 281 6094                     |

kondaman@aludra.usc.edu (Arjun Krishna Kondamani) (08/14/90)

In article <990@dcl-vitus.comp.lancs.ac.uk> se@comp.lancs.ac.uk (Steve Elliott) writes:
>I'd like some advice/help on the above topic.
>Specifically, I'm trying to program a card reader through
>COM1 with a Microsoft C (v5.1) program.
>To initialise the lock, the docs state that "break level must be
>off more than 2 seconds".
>That's got me stumped. What is break level? Can I program it from C?
>If so, how?
>Thanks, 
>	Steve
You can use function 33H to turn on or off extensive chking for the
Break char (CTRL-C). Also, BREAK command. Usually, interrupt on 21H
and let the AX register know that you r using 33H.

I'm sure you can do this from your C program.

Arjun.


-- 
kondaman@aludra.usc.edu@usc.edu 213-746-1151 (evening) 213-743-6210 (day)

Don't go around saying the world owes you a living. The world owes you
nothing. It was here first. -- Mark Twain