As I wrote before, 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 publicly. Here's a direct ink.

Comments

comments powered by Disqus