Mail Archives: djgpp/2000/11/14/18:25:15
This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.
------_=_NextPart_001_01C04E91.174AC758
Content-Type: text/plain;
charset="iso-8859-1"
Hi,
I need a real simple com port redirection program like *nix tip. Included
is something I hacked together.
If I use djgpp it appears to actually open a file called com2.
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?.
This has been done a million times before, I am sure. I can not find the
source for tip. Any ideas?
Thanks in advance,
Nick
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
int main(void)
{
int c;
FILE* com =fopen("com2","r+");
system ("mode com2 9600 none 8 1");
fprintf(com, "h\n"); // do "h" command to external computer so we can
see output
c=fgetc(com);
while(EOF != c)
{
if (0!=c)
printf("%c",c);
c=fgetc(com);
}
fclose(com);
return 0;
}
------_=_NextPart_001_01C04E91.174AC758
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV=3D"Content-Type" CONTENT=3D"text/html; =
charset=3Diso-8859-1">
<META NAME=3D"Generator" CONTENT=3D"MS Exchange Server version =
5.5.2448.0">
<TITLE>tip</TITLE>
</HEAD>
<BODY>
<P ALIGN=3DLEFT><FONT COLOR=3D"#000000" SIZE=3D2 =
FACE=3D"Arial">Hi,</FONT></P>
<P ALIGN=3DLEFT><FONT COLOR=3D"#000000" SIZE=3D2 FACE=3D"Arial">I need =
a real simple com port redirection</FONT> <FONT COLOR=3D"#000000" =
SIZE=3D2 FACE=3D"Arial">program like *nix tip. Included is =
something I hacked together. </FONT> </P>
<P ALIGN=3DLEFT><FONT COLOR=3D"#000000" SIZE=3D2 FACE=3D"Arial">If I =
use djgpp it appears to actually open</FONT> <FONT COLOR=3D"#000000" =
SIZE=3D2 FACE=3D"Arial">a</FONT> <FONT COLOR=3D"#000000" SIZE=3D2 =
FACE=3D"Arial">file</FONT><FONT COLOR=3D"#000000" SIZE=3D2 =
FACE=3D"Arial"> called</FONT><FONT COLOR=3D"#000000" SIZE=3D2 =
FACE=3D"Arial"> com2.</FONT></P>
<P ALIGN=3DLEFT><FONT COLOR=3D"#000000" SIZE=3D2 FACE=3D"Arial">If I =
compile using watcom for a 16 bit executable, I am</FONT> <FONT =
COLOR=3D"#000000" SIZE=3D2 FACE=3D"Arial">able to get</FONT> <FONT =
COLOR=3D"#000000" SIZE=3D2 FACE=3D"Arial">about a line of output. =
Then I</FONT> <FONT COLOR=3D"#000000" SIZE=3D2 =
FACE=3D"Arial">g</FONT><FONT COLOR=3D"#000000" SIZE=3D2 =
FACE=3D"Arial">et an error from dos saying</FONT> <FONT =
COLOR=3D"#000000" SIZE=3D2 FACE=3D"Arial">General error reading device =
COM2</FONT><FONT COLOR=3D"#000000" SIZE=3D2 FACE=3D"Arial"> Abort retry =
fail?</FONT><FONT COLOR=3D"#000000" SIZE=3D2 =
FACE=3D"Arial">.</FONT></P>
<P ALIGN=3DLEFT><FONT COLOR=3D"#000000" SIZE=3D2 FACE=3D"Arial">This =
has been done a million times before, I am sure. I can not find =
the source for tip</FONT><FONT COLOR=3D"#000000" SIZE=3D2 =
FACE=3D"Arial">. Any ideas?</FONT></P>
<P ALIGN=3DLEFT><FONT COLOR=3D"#000000" SIZE=3D2 FACE=3D"Arial">Thanks =
in advance,</FONT></P>
<P ALIGN=3DLEFT><FONT COLOR=3D"#000000" SIZE=3D2 =
FACE=3D"Arial">Nick</FONT></P>
<BR>
<P ALIGN=3DLEFT><FONT COLOR=3D"#000000" SIZE=3D2 =
FACE=3D"Arial">#include <stdio.h></FONT></P>
<P ALIGN=3DLEFT><FONT COLOR=3D"#000000" SIZE=3D2 =
FACE=3D"Arial">#include <stdlib.h></FONT></P>
<P ALIGN=3DLEFT><FONT COLOR=3D"#000000" SIZE=3D2 =
FACE=3D"Arial">#include <conio.h></FONT></P>
<P ALIGN=3DLEFT><FONT COLOR=3D"#000000" SIZE=3D2 FACE=3D"Arial">int =
main(void)</FONT></P>
<P ALIGN=3DLEFT><FONT COLOR=3D"#000000" SIZE=3D2 =
FACE=3D"Arial">{</FONT></P>
<P ALIGN=3DLEFT><FONT COLOR=3D"#000000" SIZE=3D2 =
FACE=3D"Arial"> int c;</FONT></P>
<P ALIGN=3DLEFT><FONT COLOR=3D"#000000" SIZE=3D2 =
FACE=3D"Arial"> FILE* com =
=3Dfopen("com2","r+");</FONT></P>
<P ALIGN=3DLEFT><FONT COLOR=3D"#000000" SIZE=3D2 =
FACE=3D"Arial"> system ("mode com2 9600 none 8 =
1");</FONT></P>
<P ALIGN=3DLEFT><FONT COLOR=3D"#000000" SIZE=3D2 =
FACE=3D"Arial"> fprintf(com, =
"h\n");</FONT><FONT COLOR=3D"#000000" SIZE=3D2 =
FACE=3D"Arial"> // do "h" command to external computer so we can =
see output</FONT></P>
<P ALIGN=3DLEFT><FONT COLOR=3D"#000000" SIZE=3D2 =
FACE=3D"Arial"> c=3Dfgetc(com);</FONT></P>
<P ALIGN=3DLEFT><FONT COLOR=3D"#000000" SIZE=3D2 =
FACE=3D"Arial"> while(EOF !=3D c)</FONT></P>
<P ALIGN=3DLEFT><FONT COLOR=3D"#000000" SIZE=3D2 =
FACE=3D"Arial"> {</FONT></P>
<P ALIGN=3DLEFT><FONT COLOR=3D"#000000" SIZE=3D2 =
FACE=3D"Arial"> if =
(0!=3Dc)</FONT></P>
<P ALIGN=3DLEFT><FONT COLOR=3D"#000000" SIZE=3D2 =
FACE=3D"Arial"> &nb=
sp; printf("%c",c);</FONT></P>
<P ALIGN=3DLEFT><FONT COLOR=3D"#000000" SIZE=3D2 =
FACE=3D"Arial"> =
c=3Dfgetc(com);</FONT></P>
<P ALIGN=3DLEFT><FONT COLOR=3D"#000000" SIZE=3D2 =
FACE=3D"Arial"> }</FONT></P>
<P ALIGN=3DLEFT><FONT COLOR=3D"#000000" SIZE=3D2 =
FACE=3D"Arial"> fclose(com);</FONT></P>
<P ALIGN=3DLEFT><FONT COLOR=3D"#000000" SIZE=3D2 =
FACE=3D"Arial"> return 0;</FONT></P>
<P ALIGN=3DLEFT><FONT COLOR=3D"#000000" SIZE=3D2 =
FACE=3D"Arial">}</FONT></P>
</BODY>
</HTML>
------_=_NextPart_001_01C04E91.174AC758--
- Raw text -