Mail Archives: djgpp/2000/11/15/06:33:02
Please don't post in HTML.
On Tue, 14 Nov 2000, Nick DiToro wrote:
> If I use djgpp it appears to actually open a file called com2.
???? Do you mean that you actually see a file `com2' on your disk
when you type "dir [Enter]" in the current directory? That's
impossible, I think, unless you are running the program not on MS-DOS,
but on some DOS emulator which doesn't emulate DOS devices.
> If I compile using watcom for a 16 bit executable, I am able to get about a
> line of output. Then I get an error from dos saying General error reading
> device COM2 Abort retry fail?.
It's off-topic to ask questions about Watcom here. However, there's
one aspect of your program that can cause problems with devices: you
use buffered stdio functions to read a device. This is a Bad Idea,
because these functions will typically read lots of characters to fill
their buffer, even if your program asked for a single character. If
the device doesn't have that many characters available, you will get
errors like cited above.
> FILE* com =fopen("com2","r+");
Forst, devices should be open with "rb". Second, the use of "+" is
probably another potential source of problems: it causes the librray
to seek back and forth through the file/devices, and devices don't
generally support seeking.
> system ("mode com2 9600 none 8 1");
This is a *really* bad idea: mode.com may install itself as a TSR in
some cases, so invoking it from a program is trouble. Instead, call
the appropriate BIOS functions to set the COM2 device to the state you
want.
- Raw text -