twintriode
Technical User
Hi All -
I am having some troubles reading from a serial device in perl. I can send commands with the following code:
I can get a return ack but it is always read as an 'x' The correct basic ack from this device should be 0x78. With printf I can specify that the the input will be in hex format. Is there a way to do that in the other direction when using some kind of read?
Here is the code I am using for the retun:
key is always x when a valid command has been received and executed by the device.
So far I have just programmed using x as the ack, but I now need to be able to read the correct hex.
When I use cutecom I am receiving the correct hex back from the device.
Can anyone point me in the right direction? How can I tell perl to let me read raw hex from the device?
Thanks
I am having some troubles reading from a serial device in perl. I can send commands with the following code:
Code:
my $e1 = '\x'."$_[0]";
my $e2 = '\\'."$_[1]";
my $e3 = '\\'."$_[2]";
my $e4 = '\\'."$_[3]";
my $e5 = '\\'."$_[4]";
my $e6 = '\\'."$_[5]";
#### Send Command Bytes
system "printf '$e1$e2$e3$e4$e5$e6' > /dev/ttyS0";
I can get a return ack but it is always read as an 'x' The correct basic ack from this device should be 0x78. With printf I can specify that the the input will be in hex format. Is there a way to do that in the other direction when using some kind of read?
Here is the code I am using for the retun:
Code:
open(REC, "/dev/ttyS0");
#...
system "printf '$e1$e2$e3$e4$e5$e6' > /dev/ttyS0";
#### Sleep for a bit more than 65ms to make sure we give time for a return
usleep(80000);
ReadMode "ultra-raw";
$key = ReadKey -1, *REC;
ReadMode "normal";
print "key is $key\n";
key is always x when a valid command has been received and executed by the device.
So far I have just programmed using x as the ack, but I now need to be able to read the correct hex.
When I use cutecom I am receiving the correct hex back from the device.
Can anyone point me in the right direction? How can I tell perl to let me read raw hex from the device?
Thanks