www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/11/14/18:25:15

Message-ID: <5337D585DDD3D111996B0008C728F07DCE468D@pa00fsr01.pa.atitech.com>
From: Nick DiToro <NDiToro AT ati DOT com>
To: djgpp AT delorie DOT com
Subject: tip
Date: Tue, 14 Nov 2000 18:17:36 -0500
MIME-Version: 1.0
X-Mailer: Internet Mail Service (5.5.2448.0)
Reply-To: djgpp AT delorie DOT com

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.&nbsp; Included is =
something I hacked together.&nbsp;</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.&nbsp; =
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.&nbsp; I can not find =
the source for tip</FONT><FONT COLOR=3D"#000000" SIZE=3D2 =
FACE=3D"Arial">.&nbsp; 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 &lt;stdio.h&gt;</FONT></P>

<P ALIGN=3DLEFT><FONT COLOR=3D"#000000" SIZE=3D2 =
FACE=3D"Arial">#include &lt;stdlib.h&gt;</FONT></P>

<P ALIGN=3DLEFT><FONT COLOR=3D"#000000" SIZE=3D2 =
FACE=3D"Arial">#include &lt;conio.h&gt;</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">&nbsp;&nbsp;&nbsp; int c;</FONT></P>

<P ALIGN=3DLEFT><FONT COLOR=3D"#000000" SIZE=3D2 =
FACE=3D"Arial">&nbsp;&nbsp;&nbsp; FILE* com =
=3Dfopen(&quot;com2&quot;,&quot;r+&quot;);</FONT></P>

<P ALIGN=3DLEFT><FONT COLOR=3D"#000000" SIZE=3D2 =
FACE=3D"Arial">&nbsp;&nbsp;&nbsp; system (&quot;mode com2 9600 none 8 =
1&quot;);</FONT></P>

<P ALIGN=3DLEFT><FONT COLOR=3D"#000000" SIZE=3D2 =
FACE=3D"Arial">&nbsp;&nbsp;&nbsp; fprintf(com, =
&quot;h\n&quot;);</FONT><FONT COLOR=3D"#000000" SIZE=3D2 =
FACE=3D"Arial">&nbsp; // 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">&nbsp;&nbsp;&nbsp; c=3Dfgetc(com);</FONT></P>

<P ALIGN=3DLEFT><FONT COLOR=3D"#000000" SIZE=3D2 =
FACE=3D"Arial">&nbsp;&nbsp;&nbsp; while(EOF !=3D c)</FONT></P>

<P ALIGN=3DLEFT><FONT COLOR=3D"#000000" SIZE=3D2 =
FACE=3D"Arial">&nbsp;&nbsp;&nbsp; {</FONT></P>

<P ALIGN=3DLEFT><FONT COLOR=3D"#000000" SIZE=3D2 =
FACE=3D"Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if =
(0!=3Dc)</FONT></P>

<P ALIGN=3DLEFT><FONT COLOR=3D"#000000" SIZE=3D2 =
FACE=3D"Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp; printf(&quot;%c&quot;,c);</FONT></P>

<P ALIGN=3DLEFT><FONT COLOR=3D"#000000" SIZE=3D2 =
FACE=3D"Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
c=3Dfgetc(com);</FONT></P>

<P ALIGN=3DLEFT><FONT COLOR=3D"#000000" SIZE=3D2 =
FACE=3D"Arial">&nbsp;&nbsp;&nbsp; }</FONT></P>

<P ALIGN=3DLEFT><FONT COLOR=3D"#000000" SIZE=3D2 =
FACE=3D"Arial">&nbsp;&nbsp;&nbsp; fclose(com);</FONT></P>

<P ALIGN=3DLEFT><FONT COLOR=3D"#000000" SIZE=3D2 =
FACE=3D"Arial">&nbsp;&nbsp;&nbsp; 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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019