Home AMX User Forum NetLinx Studio

Weird behaviour on an index count

Hi there.
I'm running the following code on a NI-2100 master (on the DEFINE_PROGRAM section):
WAIT 3
{
IF (ENVIANDO <> 1)
{
INDICE = INDICE +1
IF (INDICE = 9)
{
INDICE = 1
}
CLEAR_BUFFER BUFFERDX
ENVIA_uDX("01,(30 + INDICE), 00")
WAIT 3
{
SEND_STRING 0, "'INDICE = ', INDICE, ' BUFFER = ', BUFFERDX"
IF(VERIFICA_BUFFER(BUFFERDX))
{
COMANDO = MID_STRING(BUFFERDX,1,1)
NVARIAVEL = MID_STRING(BUFFERDX,2,1)
VALOR = MID_STRING(BUFFERDX,3,1)
NIVELENV = VALOR
IF(INDICE == 8)
{
SEND_COMMAND DVTP_BARRA, "'^TXT-3,0,', ITOA(NIVELENV),'?C'"
}
ELSE
{
SEND_LEVEL DVTP_NIVEIS, (NVARIAVEL - 30), NIVELENV
}
}
}
}
}

I'm Brazilian, so the names of the variables are written in portuguese. Here goes a quick and basic translation/explanation of what it is supposed to do:
INDICE = INDEX
BUFFERDX is a buffer that is associated on the DEFINE_START section with a device to which I'm sending strings . The device is a programmable logic controller from a local brand, which the company I work for usually uses to control lights and windows on site.
ENVIA_uDX is a function that simply sums the bytes on the strings, attaches the result on the ending of the string and send it to the device

This whole code asks the device for the values of 8 specific variables (one at a time - according to the index value) and updates a touch panel (mvp-7500) with the received answers.
As seen in code, I'm sending the index value to the terminal along with the device's answer related to it. I have had no problems on communication, but had a small problem with the index counting. It counts up to seven with no problem at all, but when it receives the value 8, it's as if it had received no value at all.
The terminal shows something like:

INDICE = 1 , BUFFER = Answer 1
INDICE = 2 , BUFFER = Answer 2
INDICE = 3 , BUFFER = Answer 3
INDICE = 4 , BUFFER = Answer 4
INDICE = 5 , BUFFER = Answer 5
INDICE = 6 , BUFFER = Answer 6
INDICE = 7 , BUFFER = Answer 7
INDICE = , BUFFER = Answer 8


Is there something wrong with that little piece of code?

Thanks in advance and sorry for my lame english.

Comments

  • mpullinmpullin Posts: 949
    Maybe your SEND_STRING is interpreting the decimal value 8 as a backspace and displaying nothing, as opposed to showing something like $08 (the value 8). You probably want to convert that to an ASCII character before you display it.

    Change:
    SEND_STRING 0, "'INDICE = ', INDICE, ' BUFFER = ', BUFFERDX"

    to
    SEND_STRING 0, "'INDICE = ', itoa(INDICE), ' BUFFER = ', BUFFERDX"
  • jp1016jp1016 Posts: 32
    Thanks for the answer, but I think it can't be that, because when I change the terminal from ASCII representation to Hexadecimal or to decimal, It will still not display the value 8 on the byte of the string that in the upper lines represent the index value. Something Like:

    $44$05$45
    $44$06$45
    $44$07$45
    $44$45
    $44$01$45
    $44$02$45

    And so on...


    Ain't it weird?
  • jp1016jp1016 Posts: 32
    Nevermind. Just me being stupid. Thanks anyway.
  • Your index is incrementing while you are in the 2nd nested wait. This would cause you to miss some of the count.
Sign In or Register to comment.