Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Communication with com ports...

Status
Not open for further replies.

anaphaxeton

Programmer
Jun 3, 1999
2
0
0
US
This may seem like a silly question but...<br>
How does one go about redirecting output <br>
and getting input from a com port device?<br>
A modem for example. Any help with this <br>
would be great.
 
I am currently working on a similar issue but have solved it in part.<br>
<br>
The answer depends upon where ("c" or "C-script" you want to do the re-direct) since you say it's a silly question, I'm not sure which you want to do.<br>
<br>
I will give you the benefit of the doubt and assume you want to do it in a "c" compiled program.<br>
<br>
Disclaimer: I received what I'm going to show you as a fax from IBM. so for legal purposes I want to give them credit. If you want the entire program, along with the entire legal disclaimer, contact IBM for the full program...It is called 'motalk.c'<br>
<br>
at any rate, here is an excerpt that give the idea. Be aware that there is a bunch of 'setup' stuff required. The whole program is about 150 -200 lines of code. If you send me your E-mail address I can send you a copy of the entire program.<br>
<br>
<br>
while(1)<br>
{<br>
<br>
if(select(rfd, &afds, &afds, (fd_set *)0, (struct timeval *)0) &lt; 0)<br>
printf("Select failed - errno = %d\n", errno);<br>
<br>
if(FD_ISSET(rfd, &afds))<br>
while ((num = read(rfd, buffer, 4096)) &gt; 0)<br>
write(fileno(stdout), buffer, num);<br>
<br>
if(FD_ISSET(std, &afds))<br>
while ((num = read(fileno(stdin), buffer, 4096)) &gt; 0)<br>
write(fileno(fdw), buffer, num);<br>
<br>
}<br>
<br>
Now, for a question of my own...... How do you convince X-modem to accept input from somewhere other that stdin/stdout? Or, stated differently, how do I spawn a process whose stdin/stdout is already /dev/tty?<br>
<br>
Also, if you could tell me how to 'post' inquiries myself, I would appreciate it.<br>
<br>
des :)<br>

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top