Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!cornell!uw-beaver!fluke!ssc-vax!coy From: coy@ssc-vax.UUCP (Stephen B Coy) Newsgroups: comp.os.msdos.programmer Subject: Re: Help! serial comm problems Message-ID: <3466@ssc-vax.UUCP> Date: 27 Jul 90 19:51:18 GMT References: <487@roo.UUCP> Organization: Boeing Aerospace & Electronics, Seattle WA Lines: 89 Keywords: serial communication port RS232 In article <487@roo.UUCP>, kurtenba@parc.xerox.com (Gord Kurtenbach) writes: > > 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 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 #include #include #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 */ } /* end of main */