home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: sparky!uunet!sun-barr!decwrl!csus.edu!target.water.ca.gov!tching
- From: tching@target.water.ca.gov (Tracy Ching <SysAdmin>)
- Subject: Need help with serial routine - how to get a byte from COM1
- Message-ID: <1992Aug27.222755.10534@csus.edu>
- Sender: news@csus.edu
- Organization: California State University, Sacramento
- Distribution: usa
- Date: Thu, 27 Aug 1992 22:27:55 GMT
- Lines: 27
-
- I'm using Quick C to write a very simple program to read and
- write to the serial port. My program is shown below. What do I
- need to be able to read from the port without getting nasty DOS error
- messages like "COM1 not ready ... Abort Retry Ignore Fail..." or
- something like that every time I try to read a byte from the port?
- I can write to it fine and the data comes out. (I see it on my dumb
- term connected to COM1). Please e-mail to
- tching@water.ca.gov
-
- #include <stdio.h>
- FILE *fp_ser; /* serial port */
- int ch;
-
- main()
- {
- int result;
-
- fp_ser = fopen("com1", "w+b"); /* opens com1 for read write binary */
- result = fputs ("Hello world \n", fp_ser); /* print it to serial port */
-
- /* How do I get a serial char back from the com1 and echo it
- onto my screen????
- I used fgetc() with disasterous results */
-
- fclose (fp_ser);
- }
-
-