Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

Re: Detect STX and ETX hex in received string

by jagexCoder (Novice)
on Nov 29, 2012 at 01:58 UTC ( #1006142=note: print w/replies, xml ) Need Help??

in reply to Detect STX and ETX hex in received string

thanks for the assistance guys, I would like to further add that the packets (the payload, not STX/ETX) that are coming in are coming as a 'String of characters' in ASCII hex format. So the STX will be sent as a '2' and ETX will be sent as a '3'. The packets in between, for example if the payload has a '15' it will be sent as 2 bytes '1' and '5'. I did something like this:
my @buffer = {}; # Create an empty buffer array my $byte = ""; sub readSerialPort { # $byte contains the incoming data from the other host on the ser +ial line # The buffer ensures that all the data is stored in one location. # Read from the buffer and manually empty it after processing! # sleep 3; $byte=$port->input; if ($byte eq chr(02)) { print "STX was found! " . $byte . "\n"; do { push(@buffer, $byte); } while ($byte != chr(03)); if ($byte eq chr(03)) { print "ETX was found! " . $byte . "\n"; } } } print "\nContents of byte is " . $byte . "\n". print "\nContents of buffer is " . @buffer . "\n".
I am using Docklight to send the serial commands, if I transmit in hex: "02 32 34 23 23 23 03" the output is showing:
Contents of buffer is 1 1 Contents of byte is 24###
I was expecting the buffer to show [02|32|34|23|23|23|03]. Also because since it shows the buffer char array as 1, I can't do ,buffer[0], buffer[1] etc if I want to pick out certain parts of the received string of characters (which I will need to later on to distinguish between the payload and CRC between the STX and ETX). Any ideas? Is my code in the right direction? Thanks EDIT: I would like to mention that the "byte" array is displayed properly, though on the forum the STX and ETX is not showing however it is showing just fine on my console window.

Replies are listed 'Best First'.
Re^2: Detect STX and ETX hex in received string
by jagexCoder (Novice) on Nov 30, 2012 at 05:20 UTC
    Solved the issue..thanks for your help everyone.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1006142]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (4)
As of 2020-11-01 02:23 GMT
Find Nodes?
    Voting Booth?
    My favourite web site is:

    Results (291 votes). Check out past polls.