once again: perl, serial ports and what’s between them

February 13th, 2006 at 10:06 pm

As I wrote here, I managed to avoid using the Win32::SerialPort module for sending data to the serial port (COM) by employing a C++ slave program that listens to a socket and transmits whatever it gets to the serial port.

Today, I finally perfected this scheme. Now my C++ program (104 Kb !) is a full-duplex serial port <-> socket bridge. It is created by the Perl ‘master’ script and starts listening to the socket and to the serial port. When it gets something from the socket (sent by the Perl script) it transmits it to the serial port. When it gets something from the serial port, it sends it to the Perl script using the socket.

The Perl script can now either send serial data by shoving it into the socket or query it, in a convenient non-blocking way (thank you ioctl(), see this), to see if anything new has arrived.

The C++ bridge works in two threads. One waits (using recv()) on the socket to get data from the master and transmit it to the serial port. The other waits on the serial port and transmits what it gets into the socket.

For now I’m actually doing this using two sockets, one for each way (master -> slave and slave -> master). In theory this is doable with a single bi-directional socket, though I may leave it as it is to allow future flexibility.

Update (05.03.2008): I’ve released this to the Programs and Code section. Here’s a direct ink.

Related posts:

  1. perl master, C++ slave, bound for serial port programming
  2. Non-blocking socket access on Windows
  3. threads, serial ports, kernel, emacs and other vegetables
  4. dissapointed with Perl
  5. communication with a serial port

5 Responses to “once again: perl, serial ports and what’s between them”

  1. aNo Gravatar Says:

    Will the C++ source code and/or exe be made available?

  2. elibenNo Gravatar Says:

    Not at the moment, sorry

  3. guntherNo Gravatar Says:

    what’s the point in blogging then? dickhead!

  4. ripper234No Gravatar Says:

    I’m guessing Eli cannot release the code because he doesn’t own it.

  5. elibenNo Gravatar Says:

    gunther,

    Your comments sounds a bit like spam…

    I’ve actually released the package shortly after writing that comment. It’s available here: http://eli.thegreenplace.net/files/prog_code/perl_serial_comm.zip