sarathy@gpu.utcs.utoronto.ca (Rajiv Sarathy) (02/21/90)
Over the last couple of months several people have asked how to read/write from PC serial ports in C. However, none of the posters summarized any info they received. Since I have no record of who the posters were, and postings are cleared every week on this machine, I would like to either see a summary, or have someone help me. I need to read formatted text from the serial port. Unfortunately, fopen doesn't open "com1:", so I can't see how to use fscanf. This problem has definitely been tackled several times before by users of digitizers, etc. Please help! If it matters, I can use any of MSC5.1, QC2 with MASM, MASM5.1 Thanks in advance. -- Rajiv Partha Sarathy _ _ /^\ INTERNET sarathy@gpu.utcs.utoronto.ca ................ooooooooOOOO(_)(_)\_/ BITNET sarathy@utorgpu.bitnet University Of Toronto Computing Services UUCP sarathy@utgpu.uucp
scott@wilbur.uucp (Scott Beckstead) (02/22/90)
In article <1990Feb20.165257.21884@gpu.utcs.utoronto.ca> sarathy@gpu.utcs.utoronto.ca (Rajiv Sarathy) writes: >Over the last couple of months several people have asked how to read/write >from PC serial ports in C. However, none of the posters summarized any >info they received. > >Since I have no record of who the posters were, and postings are cleared every >week on this machine, I would like to either see a summary, or have someone >help me. > >I need to read formatted text from the serial port. Unfortunately, fopen >doesn't open "com1:", so I can't see how to use fscanf. > >This problem has definitely been tackled several times before by users of >digitizers, etc. Please help! > >If it matters, I can use any of MSC5.1, QC2 with MASM, MASM5.1 > >Thanks in advance. > >-- > > Rajiv Partha Sarathy _ _ /^\ INTERNET sarathy@gpu.utcs.utoronto.ca > ................ooooooooOOOO(_)(_)\_/ BITNET sarathy@utorgpu.bitnet > University Of Toronto Computing Services UUCP sarathy@utgpu.uucp Best solution I can think of (and have used) is read the raw data into a buffer and use scanf(...) works just as well as fscanf(...) just takes a little longer. Have you tried any of the "canned" libraries for the serial ports?? Scott -- Scott Beckstead | Sew Crates was a grate greek. CIS 76106,3720 | Dang that one got right by the spelling checker FIDO 1:206/2814 | don't look at me YOU wrote it!
cs4g6ag@maccs.dcss.mcmaster.ca (Stephen M. Dunn) (02/27/90)
In article <1990Feb20.165257.21884@gpu.utcs.utoronto.ca> sarathy@gpu.utcs.utoronto.ca (Rajiv Sarathy) writes:
$I need to read formatted text from the serial port. Unfortunately, fopen
$doesn't open "com1:", so I can't see how to use fscanf.
Use stdaux ... it's already there for you. But don't count on it working.
The serial port is not interrupt-driven by default, and has no buffering
except that provided by the chip you're using. Writing stuff to it works
fine, but good luck trying to read from it! I have had no luck in Turbo
Pascal or in Turbo C doing this; if you're sure you can write something
fast enough not to miss a character, you can do it all with calls to
the appropriate BIOS interrupt (14h, I think), but then the maximum speed
your program will run at depends on the power of your computer.
Might I suggest that you look around on simtel20 for a shareware/PD
interrupt-driven comm port package? Also check out any decent PC BBSs
in your area (Canada Remote Systems might, and I think I might have seen
such programs on the Lamis BBS at (416) 754-4103, but CRS requries
membership and Lamis also does, I think). I found a couple of such
libraries somewhere last term, but never got around to checking them
out and I don't think I have them anymore.
--
Stephen M. Dunn cs4g6ag@maccs.dcss.mcmaster.ca
<std_disclaimer.h> = "\nI'm only an undergraduate!!!\n";
****************************************************************************
I Think I'm Going Bald - Caress of Steel, Rush
rreiner@yunexus.UUCP (Richard Reiner) (02/28/90)
cs4g6ag@maccs.dcss.mcmaster.ca (Stephen M. Dunn) writes: >In article <1990Feb20.165257.21884@gpu.utcs.utoronto.ca> sarathy@gpu.utcs.utoronto.ca (Rajiv Sarathy) writes: >$I need to read formatted text from the serial port. Unfortunately, fopen >$doesn't open "com1:", so I can't see how to use fscanf. > Might I suggest that you look around on simtel20 for a shareware/PD >interrupt-driven comm port package? LiteComm is the biggest and best such library for C in the PD / shareware area. Available on Simtel as PD:<MSDOS.C>MCOMM.ARC (microsoft C version), and PD:<MSDOS.TURBOC>TCOMM.ARC (turbo C version). --Richard -- Richard J. Reiner rreiner@nexus.yorku.ca BITNET: rreiner@yorkvm1.bitnet (also rreiner@vm1.yorku.ca)