Home AMX User Forum NetLinx Studio

the question about the reply and program and button event

DATA_EVENT[SHARP]
{
online:
{
SEND_COMMAND sharp,'SET BAUD 9600,8,N,1 485 DISABLE'
}
STRING:
{
reply=DATA.TEXT
}
}


button_event[tp,2]
{
push:
{
SEND_STRING SHARP,"'VOLM ?',$0D"
//this will change the reply
}
}



(***********************************************************)
(* THE ACTUAL PROGRAM GOES BELOW *)
(***********************************************************)
DEFINE_PROGRAM
wait 50
{

....
......
SEND_STRING SHARP,"'POWR????',$0D"
wait 5
{C=TV_REPLY}
.....
....

}



I have question about running program and running button_event ,when my program running in the above "wait 50",exactly after running "SEND_STRING SHARP,"'POWR????',$0D"",I push the button
and the reply that i need just be changed,because i push that button ,but i don't want this happen!
anyone has advice????
afte running the button event ,i want it will not do "C=TV_REPLY",instead of doing the whole "wait 50"!!!!
thanks

Comments

  • Spire_JeffSpire_Jeff Posts: 1,917
    If you want the C=TV_REPLY wait to be based on the button push, just move that part to the button event.

    As I look at the code, I think I see what you are trying to do. Are you trying to track power status and volume from the TV? If so, the way I do it is to parse the data in the DATA_EVENT section and store the information in the appropriate variables. If the TV sends back messages that are different for each thing you want to track, it is easier as you don't have to track the last message sent. If the device needs you to remember what was requested, you will have to write some sort of queuing program to hold messages and track the last message sent. (there is a thread that covers some queuing code examples somewhere)

    Here is a quick example of parsing the data in the DATA_EVENT:
    data_event[SHARP]{
    STRING:{
       select{
         active(find_string(data.text,'POWR',1)):{
            tvPower = atoi(data.text) // this might work if POWR0000 was the response to indicate Off and POWR0001 meant On.
          }
         active(find_string(data.text,'VOLM',1)):{
            tvVolume = atoi(data.text) 
          }
     
       }
    }
    }
    

    This is a starting point, but you really should look for a message termination character to insure you are dealing with only one message at a time. If you need to track last message sent, it will get a little more involved.

    Jeff
  • DHawthorneDHawthorne Posts: 4,584
    You need to buffer your responses , not replace them every time a new one comes in. You can then run through the buffer and parse it for whatever changed. You can buffer it yourself by making your assignment go something like, reply = "reply, DATA.TEXT", or you can use the built in (recommended) buffering by putting a CREATE_BUFFER statement in your online event.
  • Spire_Jeff wrote: »
    If you want the C=TV_REPLY wait to be based on the button push, just move that part to the button event.

    As I look at the code, I think I see what you are trying to do. Are you trying to track power status and volume from the TV? If so, the way I do it is to parse the data in the DATA_EVENT section and store the information in the appropriate variables. If the TV sends back messages that are different for each thing you want to track, it is easier as you don't have to track the last message sent. If the device needs you to remember what was requested, you will have to write some sort of queuing program to hold messages and track the last message sent. (there is a thread that covers some queuing code examples somewhere)

    Here is a quick example of parsing the data in the DATA_EVENT:
    data_event[SHARP]{
    STRING:{
       select{
         active(find_string(data.text,'POWR',1)):{
            tvPower = atoi(data.text) // this might work if POWR0000 was the response to indicate Off and POWR0001 meant On.
          }
         active(find_string(data.text,'VOLM',1)):{
            tvVolume = atoi(data.text) 
          }
     
       }
    }
    }
    

    This is a starting point, but you really should look for a message termination character to insure you are dealing with only one message at a time. If you need to track last message sent, it will get a little more involved.

    Jeff

    you give that code is ok.i also alread realized it .but it too complex. i have so many device like tv,air_condition,matrix and so on.
    i want ask using AMX programe to track the device status is worthy??? it's take so much my time .
  • wgqkakawgqkaka Posts: 16
    DHawthorne wrote: »
    You need to buffer your responses , not replace them every time a new one comes in. You can then run through the buffer and parse it for whatever changed. You can buffer it yourself by making your assignment go something like, reply = "reply, DATA.TEXT", or you can use the built in (recommended) buffering by putting a CREATE_BUFFER statement in your online event.

    i used buffering some time ago.but i found it has no differce from using the variable. anybody can explain the differce between the buffer and variabel .thanks
  • DHawthorneDHawthorne Posts: 4,584
    wgqkaka wrote: »
    i used buffering some time ago.but i found it has no differce from using the variable. anybody can explain the differce between the buffer and variabel .thanks

    You are assigning the incoming value directly to your variable. If you haven't processed it yet, the old value is lost. If you buffer it, the old data is kept, and the new data is added, and you can process it all without worrying about a button event causing the old to get overwritten.
  • wgqkakawgqkaka Posts: 16
    DHawthorne wrote: »
    You are assigning the incoming value directly to your variable. If you haven't processed it yet, the old value is lost. If you buffer it, the old data is kept, and the new data is added, and you can process it all without worrying about a button event causing the old to get overwritten.

    i see,thank you very much~~~
Sign In or Register to comment.