|Problems? Is your data what you think it is?|
Perl stdout timing/formattingby dburke (Novice)
|on Sep 12, 2012 at 00:36 UTC||Need Help??|
dburke has asked for the
wisdom of the Perl Monks concerning the following question:
Hi guys! This is my first post, but don't spare me. :) Any suggestions/comments are appreciated; the negative ones tend to be the most enlightening! I'm currently trying to make a perl script to help me handle the cycling of my aquaponics system. I have the script connect to my Arduino Uno and then issue very simple commands to have the arduino control a pump.
Currently, I've found I get the best results by having my script fork a process that deals with listening for incoming signals (from the arduino) over the serial connection while the main process deals with handling user input and issuing the commands to the arduino over the serial connection. I did this because the script couldn't finish what it was doing fast enough to catch the incoming data from the arduino (I think).
The problem that I'm having is that the output of this script has formatting issues that sometimes cut the first few characters off of a print function; I also occasionally get undesired non-alphabetical characters in the messages sometimes (only coming from the arduino). At first, I thought this was due to something related to the serial connection because every message from the Arduino seems to get cut, but as I've changed my script prints from the script that have nothing to do with info coming from the arduino are also getting cut. I've temporarily added a space or line break at the beginning of these messages to avoid having a bit of the messages cut off.
Another related issue is that the prints from the child process (that prints the incoming arduino messages) tend to alternate coming in before and after the prints from the parent. The end result of this is a bunch of confusing output like this:
So far, I'm thinking some sort of "buffer" needs to be made to deal with the order in which the messages come in or perhaps somehow make these messages print in the same spot every time to create some sort of consistency.TL;DR
I need to figure out a way to make the "interface" or output that's created more consistent. And I'm open to exploring new ways of handling the connection to my arduino. Perhaps forking was a bad idea? I know this question is a little vague, but I'm not sure where to look for answers. Any help is greatly appreciated.
Below is my code and..
My perl script (I apologize for the poor formatting):