home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!olivea!hal.com!decwrl!mips!munnari.oz.au!uniwa!cujo!cc.curtin.edu.au!sbakerjr
- From: sbakerjr@cc.curtin.edu.au
- Newsgroups: comp.protocols.tcp-ip.ibmpc
- Subject: HELP! Turbo C serial comms problems
- Message-ID: <1992Aug27.193502.1@cc.curtin.edu.au>
- Date: 27 Aug 92 10:35:02 GMT
- Sender: news@cujo.curtin.edu.au (News Manager)
- Organization: Curtin University of Technology
- Lines: 71
-
- I am writing a "simple" data collection routine for a PC to
- read data off one of the serial ports and put the data into
- a file for insertion into an SQL database (after processing...)
-
- I am using Turbo C V2.0 to read the ports, check the status, etc,
- but the bioscom() function that TC uses is not always reliable.
-
- The bioscom(3,0,port) function should return the current status of the
- port . I want to poll the data ready bit (bit 8) of the 16 bit return
- value.
-
- I have written this loop to keep reading the port until a byte is ready
- to read, then read the byte into a variable, ch and from there into an
- array where the file processing can take place...
-
- --------------------------------------------------
- #include <bios.h>
- #include <stdio.h>
- #define DATA_READY 0x100
- #define CR 0xD
- #define SETTINGS 0xE3 /* 9600,n,8,1 */
-
- main()
- {
- int setup(int);
- int read(int);
- int status(int);
-
- int ch = 0;
- int i=0,buffer[100];
- int port=0; /* COM1: */
-
- while (ch != CR)
- {
- if (status(port) & DATA_READY)
- {
- buffer[i] = read(port);
- putchar(buffer[i]);
- i++;
- }
- }
- }
-
- int setup(port)
- {
- return(bioscom(0,SETTINGS,port);
- }
-
- int read(port)
- {
- return(bioscom(2,0,port));
- }
-
- int status(port)
- {
- return(bioscom(3,0,port));
- }
-
- --------------------------------------
- I ran this program but the data ready bit does not
- seem to be being set correctly, or the code does
- not read it correctly.
-
- Is my algorithm flawed ?
- Have you had any similar problems ?
-
- The system will eventually be running on an OS/2 based machine
- so I do not wish to rely on UART interrupts, rather I would prefer
- to poll the data ready bit and copy bytes into the buffer as they arrive.
-
- Thanks for reading this...
-