Parsing strings to turn off or on transport controls
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
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
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.
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.
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.
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. } } }