Multiple 232 commands in succession
vegastech
Posts: 369
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?
0
Comments
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
And:
The FADEDIM command syntax is:
Your output looks like this:
You don?t need the $0A and you need the delimiting commas for fade and delay. So your output should really look like this:
So try changing this:
To this:
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.
Jeff
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
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)";
(******************)
}
}
}
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.