Help! serial comm problems

Help! serial comm problems

Post by Gord Kurtenba » Fri, 27 Jul 1990 10:57:46



I'm not a DOS programmer and I`m trying to write a program to read and
write over the serial port. The basic structure is:

while (1) {

        <if there is something to send out then stuff it down the serial port >

        <if something has been sent to the serial port then read it>

Quote:}

I've tried opening "com2" using fopen and I can successsfully stuff
data down the stream. But when I try to read from the stream with say
a call to fgetc, I get a "General failure reading com2:" errormessage.
I've fopened com2 for reading and writing and the baud rates etc are
correct and I can read data from the hardware port using bioscom so
communication is working.  What is wrong here? Will this approach work
or am I on the wrong track?

My second question is, if I do get the read working how can I avoid
blocking on it?

If some kind soul out there has a stitch of code (C would be great)
that does what I want I would be most thankful for their help.

Thanks.

Gord Kurtenbach

PS: I've notice that the DOS command "copy com2: junk" also gives the
same error. Could my system be configured wrong?

 
 
 

Help! serial comm problems

Post by Stephen B C » Sun, 29 Jul 1990 04:51:18



> I'm not a DOS programmer and I`m trying to write a program to read and
> write over the serial port. The basic structure is:

> while (1) {

>    <if there is something to send out then stuff it down the serial port >

>    <if something has been sent to the serial port then read it>
> }

> If some kind soul out there has a stitch of code (C would be great)
> that does what I want I would be most thankful for their help.

> Thanks.

> Gord Kurtenbach

This is for Microsoft C although I think the only thing you'll need
to change for Turbo C or others is the _bios_serialcom() function
calls.  Since its not a standard function everyone has created their
own standards.  Hope this helps.

Stephen Coy
uw-beaver!ssc-vax!coy

/*
        Test serial port interaction.  Keyboard hits are sent across
        the serial line, characters received are displayed on the
        screen.  Hit ESC to exit.
*/

#include <stdio.h>
#include <stdlib.h>
#include <bios.h>

#define COM1    (0)
#define COM2    (1)

#define COM     COM1
#define PARITY  _COM_NOPARITY
#define BITS    _COM_CHR8
#define STOP    _COM_STOP1
#define BAUD    _COM_9600

main(int ac, char **av)
{
        int     c, status, error;

        /* init serial port, 8bits, 1s stop bit, no parity, 9600 baud */

        _bios_serialcom(_COM_INIT, COM, BITS | STOP | PARITY | BAUD);

        for(;;) {
                /* Is DATA_READY set? If so, grab the character. */
                status = 0x0100 & _bios_serialcom(_COM_STATUS, COM, 0);
                if(status) {
                        c = 0x00ff & _bios_serialcom(_COM_RECEIVE, COM, 0);
                        printf("%c", c);
                }

                /* Do we have data to send? */

                if(kbhit()) {
                        c = getch();

                        /* bail if esc as hit */
                        if(c == 27) {
                                printf("\n\nbye...\n");
                                exit(0);
                        }

                        /* wait until transmit hold reg empty */

                        status = 0x2000 &_bios_serialcom(_COM_STATUS, COM, 0);
                        while(status != 0x2000) {
                                status = 0x2000 &_bios_serialcom(_COM_STATUS, COM, 0);
                        }

                        status = _bios_serialcom(_COM_SEND, COM, c);
                        if(status & 0x8000) {
                                fprintf(stderr, "\nError send %c\n", c);
                        }
                }       /* end of if kbrd hit loop */
        }       /* end of forever loop */

- Show quoted text -

Quote:}       /* end of main */


 
 
 

1. Follow-up to serial comm problem with C++ TV

This posting is a follow-up to my problem using serial communications with
the C++ TurboVision library.  

The problem was this: The application I was writing would hang when
sending
characters out the serial port.

The cause: TurboVision does not re-enable interrupts in its Int 24H
handler.  
Therefore, my comm library would hang when waiting for an interrupt from
the UART chip signaling the transmission of a character.

The solution: Installing the patch for SYSINT.ASM.  The patch can be found
at:
     ftp://ftp.zeta.org.au/home/grove/tvplus/patch
     The filename is: TV2BUG.ZIP

I would like to thank everyone who responded to my original posting.

And, in case any one is wondering, the communications library I am using
is the one from the book: "Serial Communications: A C++ Developer's
Guide."
It is an excellent book, and I would recommend it.  It includes complete
C++ source
code for DOS, Windows, and MultiPort Card serial drivers.

I have converted the DOS serial driver to a DLL.  I have also written a
DOS DLL
loader that allows my real mode TurboVision application to load the DLL.

Again, thanks.

Dav

2. .Wanted: Amiga 1200`s

3. BIOS & Serial comm problem...

4. DdeConnect return value

5. Help: serial comm in "C"

6. Panel derived Control doesn't render; WebControl drived does

7. HELP serial port comm with interrupt

8. Cannot find dynamic link library SrcRun.dll

9. HELP! serial comm in WATCOM C/C++

10. serial comm. HELP!

11. Need help using svasync serial comm library

12. Announce: DZComm - Serial comm functions for Allegro.

13. Serial comm