Multiple 232 commands in succession
vegastech
Junior Member
Patient fellow forum'ers: Why doesn't this work? If I look in debugger, I see the string sent out 4 times:
Here is the code:
Line 1 (18:46:51):: FADEDIM,60,[1:1]$0D$0A Line 2 (18:46:51):: FADEDIM,70,[1:2]$0D$0A Line 3 (18:46:51):: FADEDIM,80,[1:3]$0D$0A Line 4 (18:46:51):: FADEDIM,90,[1:4]$0D$0A
Here is the code:
BUTTON_EVENT[dvTPLight,30] //send lighting preset 1 to all 4 light zones
{
PUSH:
{
local_var integer i
FOR(i=1;i<=4;i++)
{
SEND_STRING dvLight, "'FADEDIM,',itoa(uLightPresets[1].nZone[i].nIntensity),',[1:',itoa(i),']',$0D,$0A"
SEND_STRING 0, "'FADEDIM,',itoa(uLightPresets[1].nZone[i].nIntensity),',[1:',itoa(i),']',$0D,$0A"
I am trying to send light levels to 4 different lights in succession, and I think the serial port should be ok with this, yeah? Also, here is the data_event I'm using for this:
DATA_EVENT[dvLight] // Lighting Control
{
STRING:
{
local_var char sLightFB[20]
local_var char sDump[20]
local_var integer nLightUnit
local_var integer nLightZone
local_var integer nLightLev
sLightFB = DATA.TEXT
IF(FIND_STRING(sLightFB,'FADE',1)) //Format is FADEDIM,50,[1:2],$0D,$0A
{
sDump = REMOVE_STRING(sLightFB,',',1) //removes the fadedim,
//sDump1 = REMOVE_STRING(sLightFB,',',1) //removes the 50,
nLightLev = atoi(REMOVE_STRING(sLightFB,',',1)) //removes 50, converts
nLightUnit = atoi(REMOVE_STRING(sLightFB,':',1)) //removes [1:, converts
nLightZone = atoi(REMOVE_STRING(sLightFB,']',1))
SEND_LEVEL dvTPLight, (nLightZone+9), (nLightLev*255/100)
}
}
}
I feel like it's the data event giving me issues. How can I straighten it out so that it looks at each line coming in, and not just the first one? Comments
-
Have a look at the time stamp on the terminal output...they're all the same - terminal can deal with this coz it just needs to write it to the screen, but the serial port / connected device can't.
You need time injected between your lighting device strings.
Since you have a nice little FOR loop going, IMHO it would be best to build yourself a stack handler where you can feed multiple commands into it (like from your FOR) and it executes them in line with the timing guidlines of the device - say with a 200ms minimum wait between instructions.
The way it is right now, your lighting device strings all hit the port at the same time and the lighting system will be left simply scratching its head.
HTH -
From the Lutron protocol manual:Patient fellow forum'ers: Why doesn't this work? If I look in debugger, I see the string sent out 4 times:Line 1 (18:46:51):: FADEDIM,60,[1:1]$0D$0A Line 2 (18:46:51):: FADEDIM,70,[1:2]$0D$0A Line 3 (18:46:51):: FADEDIM,80,[1:3]$0D$0A Line 4 (18:46:51):: FADEDIM,90,[1:4]$0D$0A
Here is the code:BUTTON_EVENT[dvTPLight,30] //send lighting preset 1 to all 4 light zones { PUSH: { local_var integer i FOR(i=1;i<=4;i++) { SEND_STRING dvLight, "'FADEDIM,',itoa(uLightPresets[1].nZone[i].nIntensity),',[1:',itoa(i),']',$0D,$0A" SEND_STRING 0, "'FADEDIM,',itoa(uLightPresets[1].nZone[i].nIntensity),',[1:',itoa(i),']',$0D,$0A"Each command is made up of fields, separated by commas, and terminated with a carriage return <CR> = $0D Hex.
And:Some commands allow parameters to be omitted, and a default value will be used. In this case, the delimiting commas must still be used
The FADEDIM command syntax is:FADEDIM, <intensity>, <fade time>, <delay time>, <address 1>, ..., <address n>
Your output looks like this:Line 1 (18:46:51):: FADEDIM,60,[1:1]$0D$0A
You don?t need the $0A and you need the delimiting commas for fade and delay. So your output should really look like this:Line 1 (18:46:51):: FADEDIM,60,,,[1:1]$0D
So try changing this:SEND_STRING dvLight, "'FADEDIM,',itoa(uLightPresets[1].nZone[i].nIntensity),',[1:',itoa(i),']',$0D,$0A"
To this:SEND_STRING dvLight, "'FADEDIM,',itoa(uLightPresets[1].nZone[i].nIntensity),',[b],,[/b][1:',itoa(i),']',$0D"
And see if that gets you any further.
Lutron should be able to handle 4 commands in succession, however, I would do what Stephen Bolton suggested and build yourself a queue. -
Sorry, I'm still pretty new to programming - what's a stack handler, and how do I create one?
-
-
Good link. Now that I am armed with several pages (more) of notes, I see that this is definitely beneficial with larger scale projects, and when needing to send multiple (like 10+) commands consistently (and quickly). For my purposes, just needing to send 4 commands for a lighting scene, could I just add a wait at the end of the FOR loop to accomplish the poor man's (translated as new guy's) programming?
-
Not really...the wait in the for wouldn't do anything, and the wait after won't help you. You could manually send all four strings with waits, but writing a queue is quite easy. (I've probably written them in 10 or more different ways and most of them very quickly)
-
I would start with sending the 4 commands in succession, just make sure they're the correct commands. If you have problems, then build a queue. Lutron's stuff is usually pretty bullet-proof in my experience.
-
Sending Levels
I am working the same problem and having trouble with my Data Event sending a level. Any suggestions appreciated.
DATA_EVENT[dvLights]
{
STRING:
{
IF(FIND_STRING(DATA.TEXT,"'DL'",1)) // DL,[1:4],50,$0D,$0A
{
STACK_VAR CHAR strTemp[24] INTEGER nZone INTEGER nLevel;
strTemp = DATA.TEXT; // hold string in temp
SET_LENGTH_ARRAY(strTemp, LENGTH_STRING(strTemp)-2); // DL,[1:4],50,~~~~$0D,$0A
(******************)
SEND_STRING 0, "'<<<dvLights strTemp= ', strTemp";
(******************)
REMOVE_STRING(strTemp,':',1); // DL,[1:~~~~4],50
nZone = ATOI(GET_BUFFER_CHAR(strTemp)); // 4~~~~],50,
nLevel = ATOI(strTemp); // 50,
SEND_LEVEL dvTP_Lights,nZone,(nLevel/255); // as per example - level bargraph (nZone #4) will go to (nLevel 50%)
(******************)
SEND_STRING 0, "'<<<dvLights nZone= ', ITOA(nZone), ' - nLevel= ', ITOA(nLevel)";
(******************)
}
}
}
Notifications:
Line 1 (18:47:48):: Level Value To [10001:12:1] - Level 9 Value= 112
Line 2 (18:47:48):: Level Value To [10001:12:1] - Level 9 Value= 109
Line 3 (18:47:48):: Level Value To [10001:12:1] - Level 9 Value= 107 -
I am working the same problem and having trouble with my Data Event sending a level. Any suggestions appreciated.
DATA_EVENT[dvLights] { STRING: { IF(FIND_STRING(DATA.TEXT,"'DL'",1)) // DL,[1:4],50,$0D,$0A { STACK_VAR CHAR strTemp[24] INTEGER nZone INTEGER nLevel; strTemp = DATA.TEXT; // hold string in temp SET_LENGTH_ARRAY(strTemp, LENGTH_STRING(strTemp)-2); // DL,[1:4],50,~~~~$0D,$0A (******************) SEND_STRING 0, "'<<<dvLights strTemp= ', strTemp"; (******************) REMOVE_STRING(strTemp,':',1); // DL,[1:~~~~4],50 nZone = ATOI(GET_BUFFER_CHAR(strTemp)); // 4~~~~],50, nLevel = ATOI(strTemp); // 50, SEND_LEVEL dvTP_Lights,nZone,(nLevel/255); // as per example - level bargraph (nZone #4) will go to (nLevel 50%) (******************) SEND_STRING 0, "'<<<dvLights nZone= ', ITOA(nZone), ' - nLevel= ', ITOA(nLevel)"; (******************) } } }Notifications:
Line 1 (18:47:48):: Level Value To [10001:12:1] - Level 9 Value= 112
Line 2 (18:47:48):: Level Value To [10001:12:1] - Level 9 Value= 109
Line 3 (18:47:48):: Level Value To [10001:12:1] - Level 9 Value= 107
You can use [code][/code] blocks to put your code in, that way it's easier to read for us.
If you can tell us what exactly is going wrong, as it's unclear to me right now where things are going wrong for you. Is the lvl not being send? Or are you simply getting the wrong value?
btw your lvl should be lvl/100*255 if you're using a 1-255 bargraph -
Update
The code compiles but is not sending the strings to the program nor are the levels showing up on the TP.
DATA_EVENT[dvLights]
{
STRING:
{
IF(FIND_STRING(DATA.TEXT,"'DL'",1)) // DL,[1:4],50,$0D,$0A
{
STACK_VAR CHAR strTemp[24] INTEGER nZone INTEGER nLevel;
strTemp = DATA.TEXT; // hold string in temp
SET_LENGTH_ARRAY(strTemp, LENGTH_STRING(strTemp)-2); // DL,[1:4],50,~~~~$0D,$0A
(******************)
SEND_STRING 0, "'<<<dvLights strTemp= ', strTemp";
(******************)
REMOVE_STRING(strTemp,':',1); // DL,[1:~~~~4],50
nZone = ATOI(GET_BUFFER_CHAR(strTemp)); // 4~~~~],50,
nLevel = ATOI(strTemp); // 50,
SEND_LEVEL dvTP_Lights,nZone,(nLevel/255); // as per example - level bargraph (nZone #4) will go to (nLevel 50%)
(******************)
SEND_STRING 0, "'<<<dvLights nZone= ', ITOA(nZone), ' - nLevel= ', ITOA(nLevel)";
(******************)
}
}
} -
The code compiles but is not sending the strings to the program
If you're trying to find the output from your SEND_STRING 0, look in the Diagnostics tab, not Notifications.
Also check the min/max properties on your touchpanel bargraphs.
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