Home AMX User Forum AMXForums Archive Threads AMX Applications and Solutions
Options

Get_buffer_char()?

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!

Comments

  • Options
    mpullinmpullin Posts: 949
    You can make things easier on yourself by defining your buffer in DEFINE_START with CREATE_BUFFER(dvMATRIX,MATRIX_BUFF). This automatically manages your Matrix buffer for you (don't need a line like MATRIX_BUFF = MATRIX_BUFF,DATA.TEXT).

    Then you could use CLEAR_BUFFER(MATRIX_BUFF) to clear the buffer.
  • Options
    lattanzilattanzi Posts: 22
    Cool!

    Very usefull suggestion...i wonder if i should have known it...THANKS!!!
  • Options
    JustinCJustinC Posts: 74
    That is a good suggestion, another thing you could do is watch the port and see if the device sends all the data back in a single string, if it does you can just use DATA.TEXT and it clears automatically after every pass.
  • Options
    mpullinmpullin Posts: 949
    JustinC wrote:
    That is a good suggestion, another thing you could do is watch the port and see if the device sends all the data back in a single string, if it does you can just use DATA.TEXT and it clears automatically after every pass.

    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.
  • Options
    JustinCJustinC Posts: 74
    I understand that completely, for more precise feedback I do use buffers, but I have found that most devices send data back in a single string.


    Also, on a side note, in Netlinx you don't have to use a variable to store trash in for REMOVE_STRING.
Sign In or Register to comment.