Master to Master String - Gibberish
jabramson
Posts: 106
I have a master to master connection and I can see the String From correctly on the second master. However when I'm assigning that to a variable via DATA.TEXT on Master 2 I am just get gibberish. The firmware is the same on both units. Why would this be?
0
Comments
DEFINE_FUNCTION CHAR[100] fnStringToHex(CHAR cInString[])
{
LOCAL_VAR CHAR cTempByte;
LOCAL_VAR CHAR cTempString[2];
LOCAL_VAR CHAR cOutString[100];
CLEAR_BUFFER cOutString;
WHILE(LENGTH_ARRAY(cInString))
{
cTempByte = GET_BUFFER_CHAR(cInString); //Grab one byte from the input
cTempString = ITOHEX(cTempByte); //Convert that one byte to a two byte string representing the hex value in ASCII
IF(LENGTH_ARRAY(cTempString) == 2)
{
cOutString = "cOutString,'$',cTempString,','"; //Add a dollar sign to the beginning and a comma to the end, for readability
}
ELSE IF(LENGTH_ARRAY(cTempString) == 1)
{
cOutString = "cOutString,'$0',cTempString,','"; //Pad with a zero if the output of ITOHEX was ony one character long
}
}
SET_LENGTH_ARRAY(cOutString,LENGTH_ARRAY(cOutString) - 1); //Discard the last comma
cOutString = "'"',cOutString,'"'"; //Add some quotes, because I want them in the string I'll be passing to my terminal
RETURN cOutString; //Return the finished string - enjoy!
}
Well, what's not useful about hex? For example, let's make up a protocol for the discussion. Let's say the string coming back is a mix of hex and ascii.
Let's say the box comes back with the following string for a change in volume.
"$01,$01,$02,DVD:45,$FF" The first threer cells are bytes telling you the
unit ID
Power Stat
Zone Id
The given ASCII text name of the zone
The ASCII value of the volume
and the $FF is the string terminator.
Treat cells 1 through 3 as integers
So unit ID is something like..
there are many ways to do this and this is just an example for the sake of the discussion.
To get the text out just strip out the first three cells of the buffer. use Right String or Get_Buffer_Char or whatever. or search for the first hex value in the string over $20 which is where the ASCII chars start.
So something like.
now all that's left is "45,$FF"
so to get the volume from the ascii value is easy-peasy.
Hope that helps.
e
As the official spokesman for FORMAT, I feel compelled to point out that the variable cTempString and this code:
Can be replaced with this 1 line using the underappreciated FORMAT command:
Exit stage left...