garlinto has asked for the wisdom of the Perl Monks concerning the following question:
This works very well, but makes it difficult for writing data to the port. My guess is, after much googling, that the port is being blocked by the open command/while loop and making it to where I can't use another script to open the same port for write access. There are a number of Event modules in perl for handling event-driven communications, but after reading some posts here, seems like overkill for my simple app. Ideally, this is what I would love to do: In the gnokii package (a tool for reading/writing to a nokia phone for sending sms messages, etc) is a daemon called smsd. I LOVE this little daemon: whenever a text message is received, the daemon writes the message data to a database table. Conversely, when an insert is made into the outbox table, the daemon gets wind of this and sends the text message. I would love to find/write a similar daemon for doing the same thing over a USB/serial port, i.e. writing incoming data to a "received" table and then sending data that is inserted into a "send" table. However, such a daemon is way over my head I am sure, which is why I am trying to do this in perl with as little code as possible. Looking at my example above, what would be the best way to read and write to a serial port with perl? Should I run a perl script as a cron job every 30 seconds or so to see if there is any incoming data, and then use another script that sends data when needed, first checking to make sure that the port can be opened for writing? Am I really over thinking this and there already exists a simple solution?#!/usr/bin/perl use strict; use warnings; use IO::Handle; open( COM, "/dev/ttyUSB0") || die "Cannot read serial port : $!\n"; while( <COM> ){ # do stuff here }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Best way to read/write to a serial port
by Khen1950fx (Canon) on Jan 11, 2012 at 22:48 UTC | |
|
Re: Best way to read/write to a serial port
by flexvault (Monsignor) on Jan 11, 2012 at 21:55 UTC | |
|
Re: Best way to read/write to a serial port
by wink (Scribe) on Jan 11, 2012 at 21:06 UTC | |
|
Re: Best way to read/write to a serial port
by wrog (Friar) on Jan 11, 2012 at 22:39 UTC |