Master to Master String - Gibberish
jabramson
Junior Member
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?
Comments
-
Check the variable type you are assigning as your string buffer. My guess is that the string coming in as not ASCII. So, the hex values coming in are being represented as ASCII.
-
It is a hex string coming in. How do I convert that to something useful? I only see HEXTOI, but this does contain ASCII as well.
-
If you want to just look at it live, the debugger in NetLinx Studio can be set to display the hex values. If you want to print it out to the terminal or elsewhere, you'll need to write something to change each byte to an ASCII string, e.g., convert the following single example byte: "$02" into a three byte ASCII string: '$02' (shown in hex: "$24,$30,$32"), then send it to the terminal. Here's an example:
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!
} -
It is a hex string coming in. How do I convert that to something useful? I only see HEXTOI, but this does contain ASCII as well.
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..integer Unit_id; integer Power_Stat; integer Zone_id; Unit_ID=buffer[1] Power_Stat=buffer[2] Zone_id=buffer[3]
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.DEFINE_Variable Zone_Name[10] GET_BUFFER_CHAR(buffer)// strips off first buffer cell GET_BUFFER_CHAR(buffer)// next cell GET_BUFFER_CHAR(buffer)// next cell Zone_Name=remove_string(buffer,':',1) // Zone_Name will be "DVD:" // then strip off the last ":" and you'll have your text.
now all that's left is "45,$FF"
so to get the volume from the ascii value is easy-peasy.DEFINE_VARIABLE integer current_vol current_vol=atoi(buffer)
Hope that helps.
e -
FORMAT plugIf you want to just look at it live, the debugger in NetLinx Studio can be set to display the hex values. If you want to print it out to the terminal or elsewhere, you'll need to write something to change each byte to an ASCII string, e.g., convert the following single example byte: "$02" into a three byte ASCII string: '$02' (shown in hex: "$24,$30,$32"), then send it to the terminal. Here's an example:
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!
}
As the official spokesman for FORMAT, I feel compelled to point out that the variable cTempString and this code: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 }
Can be replaced with this 1 line using the underappreciated FORMAT command:cOutString = "cOutString,FORMAT('$%02X,',cTempByte)"
Exit stage left...
Categories
- All Categories
- 2.5K AMX General Discussion
- 922 AMX Technical Discussion
- 514 AMX Hardware
- 502 AMX Control Products
- 3 AMX Video Distribution Products
- 9 AMX Networked AV (SVSI) Products
- AMX Workspace & Collaboration Products
- 3.4K AMX Software
- 151 AMX Resource Management Suite Software
- 386 AMX Design Tools
- 2.4K NetLinx Studio
- 135 Duet/Cafe Duet
- 248 NetLinx Modules & Duet Modules
- 57 AMX RPM Forum
- 228 MODPEDIA - The Public Repository of Modules for Everyone
- 943 AMX Specialty Forums
- 2.6K AMXForums Archive
- 2.6K AMXForums Archive Threads
- 1.5K AMX Hardware
- 432 AMX Applications and Solutions
- 249 Residential Forum
- 182 Tips and Tricks
- 146 AMX Website/Forums