AMX and iLight communication
udi
Posts: 107
I have a problem with doing a two-way communication between the AMX and the iLight.
In the TPDesign I draw a multi-state bargraph, I succeed in doing a level_event that when I raise or lower the bargraph level it would change the light. But now I am trying to do the opposite communication, meaning when the light is change (from other device) the bargraph will change correspondingly, for example if the light is raising in fade of 5 second the bargraph will raise slowly. In other words the bargraph will depend on the light.
I tried this code:
data_event[vLight]
{
string:
{
if (length_string(data.text))
{
// send_string 0, data.text
send_command g_dvaTouchPanels, "'!T',1,data.text"
//
// if there has been a channel or scene change
// use it to trigger updating the bargraphs
if (find_string(data.text,'L:[01:01]',1))
{
send_level g_dvaTouchPanels,1,(chan[CurrArea][1]*255/100)
}
}
}
}
But it didn’t work.
In the TPDesign I draw a multi-state bargraph, I succeed in doing a level_event that when I raise or lower the bargraph level it would change the light. But now I am trying to do the opposite communication, meaning when the light is change (from other device) the bargraph will change correspondingly, for example if the light is raising in fade of 5 second the bargraph will raise slowly. In other words the bargraph will depend on the light.
I tried this code:
data_event[vLight]
{
string:
{
if (length_string(data.text))
{
// send_string 0, data.text
send_command g_dvaTouchPanels, "'!T',1,data.text"
//
// if there has been a channel or scene change
// use it to trigger updating the bargraphs
if (find_string(data.text,'L:[01:01]',1))
{
send_level g_dvaTouchPanels,1,(chan[CurrArea][1]*255/100)
}
}
}
}
But it didn’t work.
0
Comments
Something like <address of light dimmer><level it's now at>
The data comes back in the form of a string.
As the programmer, you'll have to parse through the string and then do something along the lines of an atoi command to convert the ascii value coming to you in the string to an integer that can be sent to the bargraph.
There are several methods to get the value from the string and a lot depends upon how the string is structured. You could use remove_string to chop your way through the string for example. Let's say the command has a certain character like a ':' or ',' as a delimiter. (ex: Level:1,40 for dimmer 1, level 40% )
you do a remove_string(buffer,':',1) to get to the first number and then convert it to an integer (atoi) then do another remove_string(buffer,',',1 to get to the last number, the level.
There are many more ways to do this. This is just one example.
I'm guessing by your line of questions that you haven't had much or any training in AMX programming. You would do well to sign up for it. A lot of your questions would be covered in the first group of classes.
hope that helps.
I tried what you suggest but it didn’t work so well. I am trying that the bargraph will rise exactly like the light is rising if I am doing a fade of 5 second I want to see the fade in the bargraph
I am added the protocol and my code.
Thanks for any help that leads me in the right direction. Examples are very much appreciated.
Using the example message from the protocol manual: L:[3:10]:75
Here's what you can do. this is just an example. There are more elegant ways to do it. but it'll show the concept.
hope that helps.
I tryied what you told me and it yet doesn’t work, when I tuch the bargraph its going crazy.
I added in the code an send string 0," (something)" to see what transitive in the diagnostic tab
The code:
data_event[vlight]
{
string:
{ // example incoming string L:[3:10]:75
stack_var buffer[30]
stack_var address[10]
stack_var integer level
send_string 0,'
1
'
send_string 0,"DATA.TEXT"
if(find_string(data.text,'L:',1)) // it's a level command - parse the string.
{
buffer=data.text
remove_string(buffer,'[',1)
address=remove_string(buffer,']',1) // address string will be 3:10]
send_string 0,'
2
'
send_string 0,"address"
address=set_length_string(address,(length_string(address))-1) // strips off ']' at end
// now we have the address of 3:10in the variable 'address'
// buffer now contains ':75'
remove_string(buffer,':',1) // strips off ':' buffer is now '75'
send_string 0,'
3
'
send_string 0,"buffer"
level=atoi("buffer") // level now is integer 75.
send_level g_dvaTouchPanels,1,level // send the level to the TP.
IF(level = 0)
OFF[nLIGHT]
ELSE
ON[nLIGHT]
}
}
}
And in the diagnostic tab I get an error that I don’t anderstand
Line 27561 (16:04:36)::
1
Line 27562 (16:04:36):: L:[01:01]:19
Line 27563 (16:04:36)::
2
Line 27564 (16:04:36):: 01:01]
Line 27565 (16:04:36):: GetString - Error 1 Tk=0x0001 //////THE ERROR
Line 27566 (16:04:36):: CopyString (Reference) - Error 1 S=0x0000 D=0x1011 //////
Line 27567 (16:04:36)::
3
Line 27568 (16:04:36):: 19
What is the problem?
There's a space in the line:
address=set_length_string(address,(length_string(a ddress))-1) // strips off ']' at end
I'm not sure what you did here and I'm not sure how it even compiles. but what the command you have says to do is:
set the length of the array named 'address' to the length of the array named 'a' minus 1. So, if there is an array named 'a' and it's length is zero then you're trying to set the length of the array named 'address' to negative one. this is what's giving you the index error.
However it is still show the error
Oh, I see it now. My error. A typo on my part.
address=set_length_string(address,(length_string(a ddress))-1) // strips off ']' at end
should be
set_length_string(address,(length_string(a ddress))-1) // strips off ']' at end
send_level g_dvaTouchPanels,1,level
beacuse when I delete it the light isn't going crazy but the bargraph dosen't response to the data_event.
mybe I don't send the command correct?
I have attached the file, hopping someone tell me what is the problem in my file.
in my file i tried the command:
level=atoi(buffer)
and also:
level=atoi("buffer")
but it still doesn't work well.
What most of us do is disable the sending of data during the change of level on the touch panel. So, make your level a button also. When the user touches the TP to change the level, disable the send until they let go. (in fact just put all your sends on the 'release')
The other option is to make separate up/down buttons and make the level a display only.
Examples are very much appreciated
These are things covered in the programmer classes. I highly recommend you look into taking them. Contact your rep and they'll set them up for you.
I have another problem when I drag the bargraph the light dosen't change immediately as if there is a fading but in the code I did the command without fading:
send_command vLight,"'L:[01:01]:',itoa(level.value),':00'"