Perl serial communication ACK response

I am trying to use Perl to provide serial communication between two applications on PCs. I have never attempted serial comms programming before in perl, my experience is mostly TCP stream reading and database access.
What has me beat at the moment is how to handle the ACK/NAK signalling responses. Basically what I need to do is to have the perl script send an ASCII ACK to the other PC via serial, wait for a response which should alos be ASCII ACK for ok or NAK for no.
If the response is ACK then it will send another stream of data and await another ACK/NAK response.
Any help hopefully with an example code as to what Ineed to do to handle these responses is greatly appreciated.

Who is Participating?
ChristoferDutzConnect With a Mentor Commented:
Hey common! I did answer and I asked you some questions ... questions you didn't respond to.
As far as I know, ACK and NAK are simple ASCII Cahracters, so try just sending these:

ASCII Table and their encoding.
GerryArmstrongAuthor Commented:
Ok, guess that makes sense. This is the code I have so far, I know it is probably full of errors and not very resilient but do you think it will work for the purpose of testing? I assume that I should receive the NAK response and have the ASCII code 025 printed to screen.
use Device::SerialPort;
$Port = "/dev/ttyS0";
$ob = Device::SerialPort->new($PORT) || die "Can't Open $PORT: $!";
$ob->baudrate(9600) || die "failed setting baudrate";
$ob->parity("none") || die "failed setting parity";
$ob->databits(Cool || die "failed setting databits";
$ob->stty_icrnl(1) || die "failed setting convert cr to new line";
$ob->handshake("none") || die "failed setting handshake";
$ob->write_settings || die "no settings"; 
print "\n\n $msg sent.\n\n";
sleep 1; #delay for reply to be sent
print "$result";
undef $ob;

Open in new window

I have to admit that I am not very familiar with perl itself, but I have done quite some implementing serial port communication with serial hardware. So in general I think your code should be correct. I don't know If you have to manually flush data to the socket if "send" simply writes to a buffer.

Is the data you are sending being recieved at the other end? Serial communication is sort of tricky, as you have to set both to the same speed, handshake, parity etc.
is not ascii code 006, the ACK character.  It is 3 characters, zero, zero, six.  If you want the ACK character, you need:
    $msg = "\x06";

Other than that, what trouble are you having?
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.