I would like to make sure I follow best practices and will give it a try!
Thanks!
toggle quoted message
Show quoted text
--- In Crestron@..., "mjrtoo2000" <mjrtoo@...> wrote:
As a side note, the method you're using has been discussed in great detail the last few weeks and I think the majority of people would consider the the method your using to be not ideal. The CHANGE statement without a gather causes multiple threads to be spawned wen new data is received, the REMOVE statement causes the entire buffer to be re-evaluated each time new data is received rather than when using a GATHER which suspends the loop, and re-evaluates the buffer on a character basis from where it was suspended, not from the beginning.
I think the conclusion here is that WHILE(1) / GATHER inside the FUNCTION_MAIN (or in a push statement to be able to start/stop the loop) is a superior way to handle this type of code. Oh, and you're not doing it in the code below, but avoid calling a function from within a WHILE(1) loop if you're receiving a lot of data, put the parsing routine inside the loop, it saves A LOT of overhead.
Might be splitting hairs if you're not receiving a lot of data on rx$, but good practice is good practice.
(hopefully that's not all wrong... ;) )
--- In Crestron@..., "etienneterblanche" <etienne@> wrote:
Hi,
I need to extract the a section of the following string to get the current status of an indoor Daikin unit.
Tx$ to CoolMaster = stat3 101\x0D\x0A
Rx$ from CoolMaster = \x0D\x0A101 OFF 32C 24C Low Dry OK 1\x0D\x0AOK\x0D\x0A\x0D\x0A
I currently use the following, but for some reason it doesn't update any of the serial outputs.
Some notes:
1) UID$ = 3 digit serial I'm passing to the SIMPL+ module
2) The first 3 characters of the REMOVE string must match UID$. In this example it is "101".
3) The rest of the sections within the REMOVE string always starts at the same char position within the string.
----------------------------------------------------------------------
CHANGE Rx$
{
WHILE (FIND("\x0D",Rx$,3))
{
tempStr = REMOVE("\x0D",Rx$,3);
VAL1 = ATOI(UID$);
VAL2 = ATOI(LEFT(tempStr, 5));
IF (VAL2 = VAL1)
{
Status$ = mid(tempStr, 7, 3);
Set_Temp$ = mid(tempStr, 11, 3);
Room_Temp$ = mid(tempStr, 15, 3);
Fan_Speed$ = mid(tempStr, 19, 4);
Operation$ = mid(tempStr, 24, 4);
tempStr = "";
}
ELSE
{
tempStr = "";
VAL1 = 0;
VAL2 = 0;
}
}
}
----------------------------------------------------------------------
Thank you!!
Et