Get_buffer_char()?
lattanzi
Posts: 22
Hi there,
trying to make a long story short: i have to control an audio/video matrix 16x16 via RS232c.
From the protocol i found out that each command is like:
<AAh><55h><a set of different hex values>
and what the matrix answers is
<AAh><55h><another set of different hex values>
So far so good.
I wrote down some code:
DEFINE_CALL 'SET_MATRIX' (aSRC,aDST)
{
MATRIX_COMMAND = "$AA,$55,03,aSOURCE,aDESTINATION"
MATRIX_TYPEOF_COMMAND = 1 // ROUTING
SEND_STRING MATRIX,MATRIX_COMMAND
RETURN
}
I thought to use MATRIX_TYPEOF_COMMAND to trace the command i've sent so that response identification got simpler.
I'm now working on the DATA_EVENT which looks like:
STRING:
{
MATRIX_BUFF="MATRIX_BUFF,DATA.TEXT"
LOCAL_VAR CHAR aSTART[4]
LOCAL_VAR CHAR subSTR[255]
LOCAL_VAR CHAR aCOMMAND[255]
aSTART = "$AA,$55"
IF(FIND_STRING(MATRIX_BUFF,aSTART,1))
{
subSTR = REMOVE_STRING(MATRIX_BUFF,aSTART,1)
IF(FIND_STRING(MATRIX_BUFF,aSTART,1))
{
subSTR = REMOVE_STRING(MATRIX_BUFF,aSTART,1)
MATRIX_BUFF = "aSTART,MATRIX_BUFF"
aCOMMAND = LEFT_STRING(subSTR,LENGTH_ARRAY(subSTR)-4)
}
ELSE
{
aCOMMAND = MATRIX_BUFF
GET_BUFFER_CHAR(subSTR)
GET_BUFFER_CHAR(aCOMMAND)
}
}
my question is:
Have I got to clean the buffer and throw away the command i've already found? Shall I do it with GET_BUFFER_CHAR?
I'm preatty confused about this...any hint will be really appreciated!
Thanks!
trying to make a long story short: i have to control an audio/video matrix 16x16 via RS232c.
From the protocol i found out that each command is like:
<AAh><55h><a set of different hex values>
and what the matrix answers is
<AAh><55h><another set of different hex values>
So far so good.
I wrote down some code:
DEFINE_CALL 'SET_MATRIX' (aSRC,aDST)
{
MATRIX_COMMAND = "$AA,$55,03,aSOURCE,aDESTINATION"
MATRIX_TYPEOF_COMMAND = 1 // ROUTING
SEND_STRING MATRIX,MATRIX_COMMAND
RETURN
}
I thought to use MATRIX_TYPEOF_COMMAND to trace the command i've sent so that response identification got simpler.
I'm now working on the DATA_EVENT which looks like:
STRING:
{
MATRIX_BUFF="MATRIX_BUFF,DATA.TEXT"
LOCAL_VAR CHAR aSTART[4]
LOCAL_VAR CHAR subSTR[255]
LOCAL_VAR CHAR aCOMMAND[255]
aSTART = "$AA,$55"
IF(FIND_STRING(MATRIX_BUFF,aSTART,1))
{
subSTR = REMOVE_STRING(MATRIX_BUFF,aSTART,1)
IF(FIND_STRING(MATRIX_BUFF,aSTART,1))
{
subSTR = REMOVE_STRING(MATRIX_BUFF,aSTART,1)
MATRIX_BUFF = "aSTART,MATRIX_BUFF"
aCOMMAND = LEFT_STRING(subSTR,LENGTH_ARRAY(subSTR)-4)
}
ELSE
{
aCOMMAND = MATRIX_BUFF
GET_BUFFER_CHAR(subSTR)
GET_BUFFER_CHAR(aCOMMAND)
}
}
my question is:
Have I got to clean the buffer and throw away the command i've already found? Shall I do it with GET_BUFFER_CHAR?
I'm preatty confused about this...any hint will be really appreciated!
Thanks!
0
Comments
Then you could use CLEAR_BUFFER(MATRIX_BUFF) to clear the buffer.
Very usefull suggestion...i wonder if i should have known it...THANKS!!!
This is also a good idea (to watch and see), although as a rule of thumb you should not trust any non-AMX device to pass all data in a single string. Using a buffer is safest.
Also, on a side note, in Netlinx you don't have to use a variable to store trash in for REMOVE_STRING.