Parsing strings to turn off or on transport controls
Angelo_One
Junior Member
Trying to parse these two strings (below) coming back from a device to turn off or on transport control buttons. The command that I am sending works when I send it via Control a Device under the Diagnostics tab. Is there something that I'm missing or doing incorrect? Any advice would be greatly appreciated! Thank you in advance
DATA_EVENT [dvDVD_CD]
{
STRING:
{
LOCAL_VAR INTEGER cPowerStatus
LOCAL_VAR CHAR cDATA [100]
cDATA = DATA.TEXT
IF (FIND_STRING (cDATA,'$11,$02,$0D',1))
{
SEND_COMMAND dvTP_DVD_CD, "'^SHO-44.49,0'"
}
ELSE IF (FIND_STRING (cDATA,'$11,$01,$0D',1))
{
SEND_COMMAND dvTP_DVD_CD, "'^SHO-44.49,1'"
}
}
}
DATA_EVENT [dvDVD_CD]
{
STRING:
{
LOCAL_VAR INTEGER cPowerStatus
LOCAL_VAR CHAR cDATA [100]
cDATA = DATA.TEXT
IF (FIND_STRING (cDATA,'$11,$02,$0D',1))
{
SEND_COMMAND dvTP_DVD_CD, "'^SHO-44.49,0'"
}
ELSE IF (FIND_STRING (cDATA,'$11,$01,$0D',1))
{
SEND_COMMAND dvTP_DVD_CD, "'^SHO-44.49,1'"
}
}
}
Comments
-
Angelo_One wrote: »Trying to parse these two strings (below) coming back from a device to turn off or on transport control buttons. The command that I am sending works when I send it via Control a Device under the Diagnostics tab. Is there something that I'm missing or doing incorrect? Any advice would be greatly appreciated! Thank you in advance
DATA_EVENT [dvDVD_CD]
{
STRING:
{
LOCAL_VAR INTEGER cPowerStatus
LOCAL_VAR CHAR cDATA [100]
cDATA = DATA.TEXT
IF (FIND_STRING (cDATA,'$11,$02,$0D',1))
{
SEND_COMMAND dvTP_DVD_CD, "'^SHO-44.49,0'"
}
ELSE IF (FIND_STRING (cDATA,'$11,$01,$0D',1))
{
SEND_COMMAND dvTP_DVD_CD, "'^SHO-44.49,1'"
}
}
}
Your use of single quotes in the find_string command is likely to trip you up. It sounds like you are looking for hex characters not ASCII representation of hex characters. If the former is what you are trying to do use double quotes and see if that works better.
Paul -
Well first you should always concantenate your incoming data unless it's internal AMX coms.
cData = "cData,Data.Text";
Just in case there's a hiccup with the sending device.
Now in your find_string you're using single quotes when you should be using doubles. -
Greatly appreciated
I made the change to double quotes in place of the sungle quotes and the code is running now. Thanks for the input. You guys are awesome here.Your use of single quotes in the find_string command is likely to trip you up. It sounds like you are looking for hex characters not ASCII representation of hex characters. If the former is what you are trying to do use double quotes and see if that works better.
Paul -
Thanks I really appreciat the feedback on this topic
I made the change to double quotes in place of the sungle quotes and the code is running now. Thanks for the input. You guys are awesome here.Well first you should always concantenate your incoming data unless it's internal AMX coms.
cData = "cData,Data.Text";
Just in case there's a hiccup with the sending device.
Now in your find_string you're using single quotes when you should be using doubles. -
You're not done yet, read the comments in the example.
DATA_EVENT [dvDVD_CD] { STRING: { LOCAL_VAR INTEGER cPowerStatus; LOCAL_VAR CHAR cDATA[100]; cDATA = "cDATA,DATA.TEXT";//data needs to be removed from local vars as they're processed //or they'll remain and evaluate again & again on every event trigger WHILE(FIND_STRING(cDATA,"$0D",1))//some devices return more than 1 parsable string {// so use a while to grab & process every segment that ends with your delimiter ($0D). STACK_VAR cStr[100]; cStr = REMOVE_STRING(cDATA,"$0D",1);//always immediately remove the while condition to prevent infinite loops IF(FIND_STRING(cStr,"$11,$02",1))//now search the string section {// we also know we end with $0D so why waste time searching a longer string SEND_COMMAND dvTP_DVD_CD, "'^SHO-44.49,0'" } ELSE IF(FIND_STRING(cStr,"$11,$01",1)) { SEND_COMMAND dvTP_DVD_CD, "'^SHO-44.49,1'" } //cStr vanishes since it's a stack only to be re-created & repopulated on the next pass of the while if the condition is still true. } } }
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
