rvlahov has asked for the wisdom of the Perl Monks concerning the following question:

all,
I am trying to create a dual interface. TCP on one end and ComPort on the other.

I can get perl to accept TCP and pass it to a serial port, thanks to help from samples found in books and the net.

I am trying to do it in both directions.
The program will need to wait for TCP and pass it to the Serial port (COM1), as it does now. Additioanally it needs to wait for SERIAL input on COM1 and pass it back to TCP.

All the data will start with a chr(2) and end with a chr(3)

Any help in the proper "looping/waiting" methods required is appreciated.

Regards and a good holiday.

Rick Vlahov
use strict; use IO::Socket; use Win32::SerialPort qw( :STAT 0.19); my $Configuration_File_Name; my ($SerialPortObj, $PortName, $quiet); my $element; $Configuration_File_Name = 'c:\rvp\io-test\io-test.config'; $PortName = 'COM1'; $SerialPortObj = Win32::SerialPort->start($Configuration_File_Name); $SerialPortObj->debug(0); my $PORT = shift || 2007; my ($sock,$data); my $listen = IO::Socket::INET->new( Listen => 15, LocalPort => $PORT, Reuse => 1)<br> or die "Can't listen (TCP)"; warn "Listening (TCP) on port $PORT...\n"; $sock = $listen->accept; while (sysread $sock,$data,1024) { print "got ",length($data)," bytes of normal data 12-20-02: $data\n" +; $SerialPortObj->write(chr(2) . $data . chr(3)); } __END__

Replies are listed 'Best First'.
Re: TCP to Serial and back
by skamerman (Initiate) on Dec 26, 2002 at 20:01 UTC
    I can't really answer your question, but I can give you advice that might be helpful since I have written a few TCP -> Serial perl scripts. If you have $100 laying around, I would recommend a UDS-10 by Lantronix. I have used about 35 of them already at my company to monitor equipment. These devices act as a serial to ethernet bridge. They sit on the network and get an IP via DHCP if you want them to, and the listen to a RS-232 port on the other side. All you need to do is connect a socket to the device at port 10001 (or whatever you assign it to) and you can easily have bidirectional communications. Also, the UDS-10 has a 2K buffer for receiving, so if the serial port is spitting out information while you are sending it information, it will still work correctly. This is a very nice little gadget.

    Steve Kamerman
    President
    HardwareTechNet
      Steve,
      Thanks for your reply. Very nice solution. Will be ordering to test. I am still, also, pursuing the Software solution.

      Regards and thanks again,
      Rick Vlahov
Re: TCP to Serial and back
by tachyon (Chancellor) on Dec 27, 2002 at 10:10 UTC

    Win32::SerialPort provides what you need

    cheers

    tachyon

    s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print