This is probably something simple. I can write to the serial port easy in the perl script. I can't seem to read from it though.
The Arduino code works fine from the Arduino17 IDE serialmonitor. I know the problem is in the perl code because i used this exact code in a C# program that i made that works fine.
Example: perl arduino.pl test
This will send ~test~ to the arduino
It will strip the '~' chars from it (used as terminal chars)
Then shoot it back to me "test"
Perl Code
# Arduino Bridge
my $msg = shift;
use Device::SerialPort;
use strict;
use warnings;
my $result;
# Set up the serial port
# 19200, 81N on the USB ftdi driver
my $port = Device::SerialPort->new("/dev/tty.usbserial-A6008nhG");
$port->databits(8);
$port->baudrate(9600);
$port->parity("none");
$port->stopbits(1);
$port->write("~" . "$msg" . "~");
print "TX: ~$msg~ \n";
# receive
$result = $port->lookfor();
print "RX: $result\n";
$port->close();
Arduino Code
char incomingByte; // for incoming serial data
char cmdMsg[100];
void
setup ()
{
Serial.begin (9600);
//digitalWrite (13, HIGH); //turn on debugging LED
}
byte nextByte() {
while(1) {
if(Serial.available() > 0) {
byte b = Serial.read();
return b;
}
}
}
// MAIN CODE
void
loop ()
{
int cmd = nextByte();
if(cmd == 126)
{
char charIn = 0;
byte i = 0;
while (charIn != 126) // wait for header byte again
{
charIn = nextByte();
if(charIn != 126)
{
cmdMsg[i] = charIn;
i += 1;
}
}
Serial.print (cmdMsg);
//Serial.println("gotit");
}
}
Again if i'm doing something dumb i'm sorry.