Serial port to serial port copying software 
Author Message
 Serial port to serial port copying software

Quote:

>Hello:

>   I'm trying to find out whether anyone has idea for a serial-port
>sharing program.  Basically, I have a Linux box connected to a modem
>and a PC acting as a terminal.  I would like to be able to access the
>modem directly from the terminal, probably by setting up an account
>with the shell set as the serial-copying program.  This would allow me
>to access the modem from the terminal without having to go through the
>intermediate step of starting up a terminal program on the Linux
>machine.

>   Does anyone have something like this already written?

I wrote something like this for SCO a while back.  It was truely
trivial, about 30 lines of C.

Basically you open the modem port, set the line to raw mode, set stdin,
and stdout to raw mode, fork, with one process echoing stdin to the
modem, and the other echoing modem input to stdout.

Just set it as your login shell:

main() {
        int fdin,fdout
        int     cc;
        struct termio ios, ios2;

        ioctl(0, TCGETA, ios)
        ...
        ios.c_cc[VMIN]=1;
        ios.c_cc[VTIME]=0;
        ...
        ioctl(0, TCSETAF, ios);

        fdin = open("/dev/modem",O_RDONLY);
        ioctl(fdin, TCGETA, ios2)
        ...
        ios2.c_cc[VMIN]=1;
        ios2.c_cc[VTIME]=0;
        ...
        ioctl(fdin, TCSETAF, ios2);

        fdout = open("/dev/modem",O_WRONLY);
        if(fork()) {
                for(;;){
                        read(fdin, &cc, 1);
                        write(1, &cc, 1);
                }
        } else {
                for(;;) {
                        read(0, &cc, 1);
                        write(fdout, &cc, 1);
                }
        }

Quote:
}

Rough but you get the idea

Note Follow-ups to comp.lang.c
--

Digital Designs      BBS 1-919-423-4216            Hope Mills, NC 28348-2201
Somewhere in the Styx of North Carolina ...



Sun, 17 Mar 1996 00:58:09 GMT  
 Serial port to serial port copying software

Quote:


>>   I'm trying to find out whether anyone has idea for a serial-port
>>sharing program.  Basically, I have a Linux box connected to a modem
>>and a PC acting as a terminal.  I would like to be able to access the
>>modem directly from the terminal, probably by setting up an account
>Basically you open the modem port, set the line to raw mode, set stdin,
>and stdout to raw mode, fork, with one process echoing stdin to the
>modem, and the other echoing modem input to stdout.
> [...]
>    fdout = open("/dev/modem",O_WRONLY);
>    if(fork()) {
>            for(;;){
>                    read(fdin, &cc, 1);
>                    write(1, &cc, 1);
>            }
>    } else {
>            for(;;) {
>                    read(0, &cc, 1);
>                    write(fdout, &cc, 1);
>            }
>    }
>}

>Rough but you get the idea

That's a lot of system calls.  You need to read as many characters as
possible at a time.  Of course you don't want to block either since
it is supposed to be interactive.  Here is the body of a smart read
loop:

  Turn on O_NDELAY
  read a buffer of characters (buffer size 1K for example)
  if no characters read then turn off O_NDELAY and read 1 character
  write the buffer read in either case

When you write the buffer you will either have the characters that
were waiting in the input buffer at the time (up to the maximum
buffer size in your program) or you will have the one character
you waited for.  You will find a big improvement in throughput
as well as system usage this way.

Quote:
>Note Follow-ups to comp.lang.c

Why?  This is pretty system specific.  I have set followups
back to comp.linux.misc and added comp.unix.programmer.

--

D'Arcy Cain Consulting              |   There's no government
Toronto, Ontario, Canada            |   like no government!
+1 416 424 2871          DoD#0082   |



Tue, 19 Mar 1996 19:27:35 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Challenge: Virtual serial ports from real serial port

2. using PC/104 serial expansion board with WinCE, 4 serial ports total

3. Looking For Serial Port Communication Software

4. RS232 COM1 serial port Software/Hardware Problem

5. Software to monitor data on the iPaq Serial Port

6. Parallel port/ Serial port

7. I want open the COM1 Port (serial Port)

8. Serial port

9. Serial port access

10. Serial port drivers

11. Reading from a Serial Port with C# ???

12. open serial port with C

 

 
Powered by phpBB® Forum Software