Home NetLinx Studio

Correct Usage Of CLEAR_BUFFER

klmyersklmyers Junior MemberPosts: 6
I have used on a number of jobs a queuing routine that places commands in a char array. I have code that checks the length of the q and if it equals the MAX_LENGTH ARRAY of that variable declared size (for any reason), I clear it. Would a CLEAR_BUFFER on that variable name remove all that is in there??? or just assign that variable="" (2 double quotes) work. What is the correct syntax to use? Thanks in advance

Comments

  • Joe HebertJoe Hebert Junior Member Posts: 2,159
    Hi klmyers,

    If you have a variable defined as CHAR cBuffer[1024] then,

    CLEAR_BUFFER cBuffer
    cBuffer = ?? (single quotes)
    cBuffer = ?? (double quotes)
    SET_LENGTH_ARRAY(cBuffer,0)
    SET_LENGTH_STRING(cBuffer,0)

    will all yield the same result and none of the above options will alter the data stored at the memory location of cBuffer, they each merely set the length to zero. You can confirm this by watching cBuffer in the debugger. Which one to use is just a matter of personal preference. I like CLEAR_BUFFER because it?s the easiest for me to type: Cl<tab><space><variable name> :)

    Joe
  • Marc ScheibeinMarc Scheibein Junior Member Posts: 669
    Keep in mind that the CLEAR_BUFFER is executed at the end of mainline! If you have a lot of EVENTs in queue, you may get into trouble that the buffer is not cleared like you expect.

    I got into that trouble in the past, so I'm using the BUFFER='' method, which will be executed Immediately.
    Originally posted by Joe Hebert
    Hi klmyers,

    If you have a variable defined as CHAR cBuffer[1024] then,

    CLEAR_BUFFER cBuffer
    cBuffer = ?? (single quotes)
    cBuffer = ?? (double quotes)
    SET_LENGTH_ARRAY(cBuffer,0)
    SET_LENGTH_STRING(cBuffer,0)

    will all yield the same result and none of the above options will alter the data stored at the memory location of cBuffer, they each merely set the length to zero. You can confirm this by watching cBuffer in the debugger. Which one to use is just a matter of personal preference. I like CLEAR_BUFFER because it?s the easiest for me to type: Cl<tab><space><variable name> :)

    Joe
  • Joe HebertJoe Hebert Junior Member Posts: 2,159
    Hi Marc,

    CLEAR_BUFFER doesn?t execute when it?s called?? That?s a new one on me. Do you know if that?s documented anywhere?

    Thanks for the insight. I guess I should switch to = ?? from now on.

    Joe

    Originally posted by Marc Scheibein
    Keep in mind that the CLEAR_BUFFER is executed at the end of mainline! If you have a lot of EVENTs in queue, you may get into trouble that the buffer is not cleared like you expect.

    I got into that trouble in the past, so I'm using the BUFFER='' method, which will be executed Immediately.
  • Marc ScheibeinMarc Scheibein Junior Member Posts: 669
    We were also surprised, but Peter Knapp from AMX told us this at a training.
    (But I used the BUFFER = '' also in the past - it was less to write in the times before auto suggestion ;-)
    Originally posted by Joe Hebert
    Hi Marc,

    CLEAR_BUFFER doesn?t execute when it?s called?? That?s a new one on me. Do you know if that?s documented anywhere?

    Thanks for the insight. I guess I should switch to = ?? from now on.

    Joe
  • DHawthorneDHawthorne Junior Member Posts: 4,584
    The end of mainline issue is not so important in NetLinx, at least not the way I code it. If I have more than 2-3 lines in DEFINE_PROGRAM, it's a lot. I suppose a lot depends on thread priority in Mainline.

    I most frequently use BUFFER = '' because it is most likely to describe at a glance what I am doing - setting a CHAR array (or whatever) to a null value. When doing what the original poster decribed, actually clearing a buffer because it got filled with junk, (modern comm ports never do that though, do they? /wink ). I use the CLEAR_BUFFER statement, again because it more accurately decribes what I am trying to do. In a case like that, end of mainline is fine.
Sign In or Register to comment.