NEC Projector Feedback and buffers
TUTech
Posts: 70
I'm trying to get the feedback to work on an NEC Projector. Trying to light the ON/OFF buttons on the control panel. Sometimes the remote control gets used to turn the projector on or off.
This is what I have. It does compile, but doesn't do anything.
It is being controlled as an actual device, not a virtual.
DEFINE_DEVICE
Projector = 5001:1:0
DEFINE_CONSTANT
(*Projector power status*)
PROS_ON = 1
PROS_OFF = 2
DEFINE_VARIABLE
PRO_Buffer[100]
PRO_Status
DEFINE_START
CREATE_BUFFER Projector,PRO_Buffer
DEFINE_PROGRAM
SEND_STRING Projector,”$00,$81,$00,$00,$00,$81” //Running Sense
WAIT 10
IF (PRO_Buffer =’ $81$01@$01$02$E5’)
PRO_Status = PROS_ON
[TP,9] = (PRO_Status = PROS_ON) //Turn on “ON” button
IF (PRO_Buffer =’ $81$01@$01$00$E3’)
PRO_Status = PROS_OFF
[TP,10] = (PRO_Status = PROS_OFF) //Turn on “OFF” button
CLEAR_BUFFER PRO_BUFFER
1)The response that I am supposed to get is $22$00$01$xx$00 CKS, the above responses are consistent when using "Control a Device"
2)I know they are Hex, but as far as the buffer and NetLinx is concerned they are just characters?
3)Should the whole thing go into a DATA_EVENT?
4)Most of the examples on the forum show using DATA.TEXT which is followed by a comment that you should NOT use DATA.TEXT on an actual device?
5)I could use FIND_STRING, but is it necessary?
6)I tried using single quotes inside of double quotes, but it won't compile.
Thanks
This is what I have. It does compile, but doesn't do anything.
It is being controlled as an actual device, not a virtual.
DEFINE_DEVICE
Projector = 5001:1:0
DEFINE_CONSTANT
(*Projector power status*)
PROS_ON = 1
PROS_OFF = 2
DEFINE_VARIABLE
PRO_Buffer[100]
PRO_Status
DEFINE_START
CREATE_BUFFER Projector,PRO_Buffer
DEFINE_PROGRAM
SEND_STRING Projector,”$00,$81,$00,$00,$00,$81” //Running Sense
WAIT 10
IF (PRO_Buffer =’ $81$01@$01$02$E5’)
PRO_Status = PROS_ON
[TP,9] = (PRO_Status = PROS_ON) //Turn on “ON” button
IF (PRO_Buffer =’ $81$01@$01$00$E3’)
PRO_Status = PROS_OFF
[TP,10] = (PRO_Status = PROS_OFF) //Turn on “OFF” button
CLEAR_BUFFER PRO_BUFFER
1)The response that I am supposed to get is $22$00$01$xx$00 CKS, the above responses are consistent when using "Control a Device"
2)I know they are Hex, but as far as the buffer and NetLinx is concerned they are just characters?
3)Should the whole thing go into a DATA_EVENT?
4)Most of the examples on the forum show using DATA.TEXT which is followed by a comment that you should NOT use DATA.TEXT on an actual device?
5)I could use FIND_STRING, but is it necessary?
6)I tried using single quotes inside of double quotes, but it won't compile.
Thanks
0
Comments
I dump all that into a buffer and then execute a set of find_String commands once the buffer sees a checksum.
I had the best luck running that through a function to convert to a hex array. Here is the function that I found on these forums.
Now in the main define program I have this:
I personally liked this method because I don't have to parse through each returned Hex in the string and instead just dump it into an array. No counting needed and the array ID lines up with the returned string.
I would not put this kind of thing in Define_program. You'll see a lot of debate on the forum as to when to use Def_Prog (or even if at all - of which I am in that camp). But either way I'd not put anything processor intensive in Def_Program. the best practice is to limit it to feedback only, not string processing.
You might want to look at using the Data_Event in Define_Event.
This is just a simple example but you'll get the idea.
Yes I noticed, a lot of debate!!
I made a Data_Event. It worked, except the Send_String to send the Running Sense. I had to put it in the Define Programming. I also had to make the ON/OFF button mutually exclusive or else they would both turn on and stay on.
DEFINE_MUTUALLY_EXCLUSIVE
([TP,9],[TP,10])
DEFINE_START
CREATE_BUFFER Projector,PBUFFER
CLEAR_BUFFER PBUFFER
DEFINE_EVENT
DATA_EVENT [Projector]
{
STRING:
{
IF(LENGTH_STRING(PBUFFER))
{
SELECT
{
ACTIVE(FIND_STRING(PBUFFER,"$81,$01,'@',$01,$02,$E5",1)):
{PROJ_Status=PROS_ON
[TP,9] = (PROJ_Status=PROS_ON)}
ACTIVE(FIND_STRING(PBUFFER,"$81,$01,'@',$01,$00,$E3",1)):
{PROJ_Status=PROS_OFF
[TP,10] = (PROJ_Status=PROS_OFF)}
}}
PBUFFER=""
}
}
DEFINE_PROGRAM
WAIT 300
SEND_STRING Projector,"$00,$81,$00,$00,$00,$81" //Running Sense
Paul
A side issue for you...
the two feedback statements are a bit unnecessary. Since you've already done the string operatoion to determine the status of the projector and set the stat variable to "on" or "off" you don't need to redo the check in the statement where you check again and make the TP button go on or off. Just go ahead and turn the button on or off.
or you could do this as well.
or even better you could put this into a function or call so you could also update the button feedback outside the data event of the projector as in the case of a TP coming online and needing current feedback.
-or-
-or-
-or-
there's a lot of layers to this onion.
Perhaps you haven't seen the issue, but it exists. If your device sends back "Long string of text," you might get two events, one with "Long string," and the other "of text." I have not seen it happen with IP communications, but have seen it a lot with RS-232. It determines the "end" of data by looking for a pause in the flow ... I couldn't tell you how long a pause it looks for, but I can tell you that if your devices pauses or hiccups, you are going to get a broken response if you aren't buffering it somehow. Probably the more modern your equipment is, the less likely there will be an issue, but test it extensively if you want to be sure.
The end result is a pretty stuttery message. AMX just doesn't handle this very well. I find myself doing both what Paul does by appending incoming data.text event messages to the end of my buffer and waiting patiently for the darned thing to quick spewing (looking for a true end terminatior) or letting Create_Buffer do it for me.
I've found that Create_Buffer seems to do a pretty okay job of this kind of thing. I'm not sure just why. But, I've seen cases whwere data.text gets a bit confussed and will drop chunks within the 2K data packages. Not always, nor even predictibly.
Honestly, I usuallly try data.text first and bail in favor of Create_Buffer if I find it starting to misbehave.
But, that's just me.
That answers my question about data.text. It would work unless I a really long response or got an error in the return.
One HEX character ($FF) is 255 bytes. Does Data.text see it as 255 or two characters?
That makes sense about the button feedback. It was more than necessary, but I was glad I had something that worked!! LOL. I used that method somewhere else in the code where I had 5 variables so that's why I came up with it.
I wrote another block using ON[TP,9] OFF[TP,10] etc. I'll have to wait until the room is available to test it.
I'm working on this room a block at a time.
One more question.
Shouldn't the request for status (Wait 300 Send_string "Running Sense") be in the same DATA_EVENT? I tried it, but it wouldn't compile. (I know I can also use FOR(Count=0;Count<300;Count++). Should it go in the same STRING event or under a COMMAND event?
David