• Please review our updated Terms and Rules here

Best way to read/write to the serial port on MS-DOS hardware

PgrAm

Experienced Member
Joined
Sep 28, 2011
Messages
276
Location
Toronto, Canada
I wrote some code to send binary data back and forth via serial between an app on DOS PC and an app Windows PC. Initially I simply used Watcom's fopen to open com1 and fread/fwrite to send/receive data. Unfortunately while this works ok on DosBox, it is both unreliable and horrendously slow on real hardware.

So I think I need to use some lower level method for reading and writing. Should I use bios interrupts? or should I just interface directly with the uart via port 0x3F8 (com1). Anyone have experience with this? What is a good and reliable method here?

I'm using c++/assembly btw
 
The best and fastest interface is usually direct access. If you're trying to do something else while data is coming in or out, use interrupt driven routines. Otherwise, poll-mode can be more efficient (no interrupt servicing overhead). The web should have numerous examples of this.

Note that if you're trying to display data at the same time as receiving it, scrolling the display can take very long.
 
So I ended up directly accessing the ports. Had a little trouble because it turns out I can't assume that com1 is at 0x3F8, but you can just get the correct info from the bios :D.
 
Back
Top