Home AMX User Forum NetLinx Studio
Options

String from device

Please help to compare a line, It is necessary to execute action if in line from the device is (60)!!!
WHAT IS NOT CORRECT?



DEFINE_VARIBLE
SRING_FROM_DEVICE[50]
V INTEGER

DEFINE_EVENT

DATA_EVENT[DV_LIGHTS]
{
STRING:
{
SRING_FROM_DEVICE=DATA.TEXT
LIGTS_CONTROL(SRING_FROM_DEVICE)
}
}

DEFINE_FUNCTION LIGHTS_CONTROL(STRING_FROM_DEVICE)
{
V=FIND_STRING(STRING_FROM_DEVICE, '60' ,1)
IF(V=1)
{
ON[TP,100]
}
ELSE
{
OFF[TP,100]
}
ON[TP,100]
}

Comments

  • Options
    Spire_JeffSpire_Jeff Posts: 1,917
    Try this:
    DEFINE_VARIBLE
    char SRING_FROM_DEVICE[50]
    INTEGER v
    
    DEFINE_EVENT
    
    DATA_EVENT[DV_LIGHTS]
    {
    STRING:
    {
    SRING_FROM_DEVICE=DATA.TEXT
    LIGHTS_CONTROL(SRING_FROM_DEVICE)
    }
    }
    
    DEFINE_FUNCTION LIGHTS_CONTROL(char STRING_FROM_DEVICE[])
    {
    if(FIND_STRING(STRING_FROM_DEVICE, '60' ,1))
    {
    ON[TP,100]
    }
    ELSE
    {
    OFF[TP,100]
    }
    } 
    

    See if that works better.

    Jeff
  • Options
    LehaLeha Posts: 37
    ?
    Spire_Jeff wrote: »
    Try this:
    DEFINE_VARIBLE
    char SRING_FROM_DEVICE[50]
    INTEGER v
    
    DEFINE_EVENT
    
    DATA_EVENT[DV_LIGHTS]
    {
    STRING:
    {
    SRING_FROM_DEVICE=DATA.TEXT
    LIGHTS_CONTROL(SRING_FROM_DEVICE)
    }
    }
    
    DEFINE_FUNCTION LIGHTS_CONTROL(char STRING_FROM_DEVICE[])
    {
    if(FIND_STRING(STRING_FROM_DEVICE, '60' ,1))
    {
    ON[TP,100]
    }
    ELSE
    {
    OFF[TP,100]
    }
    } 
    

    See if that works better.

    Jeff

    Whether it will work if a line from the device (30, statcx60,32)?
  • Options
    Spire_JeffSpire_Jeff Posts: 1,917
    Leha wrote: »
    Whether it will work if a line from the device (30, statcx60,32)?

    Is (30, statcx60,32) an ASCII string, or is it a mix of ASCII and decimal/hex code? If the string is literally "'(30, statcx60,32)'", the find_string should be true.

    Jeff
  • Options
    LehaLeha Posts: 37
    Spire_Jeff wrote: »
    Is (30, statcx60,32) an ASCII string, or is it a mix of ASCII and decimal/hex code? If the string is literally "'(30, statcx60,32)'", the find_string should be true.

    Jeff

    I am not assured that it is a line! And how to learn what is it?
  • Options
    Spire_JeffSpire_Jeff Posts: 1,917
    There are a couple of ways to see what it is. You could connect your computer to the device directly and monitor the incoming strings using hyperterminal. You could use the device notifications and monitor strings coming into the processor. You could use send_string 0,"data.text" and watch diagnostics.

    Pick the one that works for you, but understand that some of the methods that use the processor could be cut off if a $00 code comes in.

    Jeff

    P.S.
    You should also be looking at a manual that defines the protocol being used. Without this, it can be done, but it is fairly difficult and very prone to unexpected strings not being interpreted.
  • Options
    LehaLeha Posts: 37
    Spire_Jeff wrote: »
    There are a couple of ways to see what it is. You could connect your computer to the device directly and monitor the incoming strings using hyperterminal. You could use the device notifications and monitor strings coming into the processor. You could use send_string 0,"data.text" and watch diagnostics.

    Pick the one that works for you, but understand that some of the methods that use the processor could be cut off if a $00 code comes in.

    Jeff

    P.S.
    You should also be looking at a manual that defines the protocol being used. Without this, it can be done, but it is fairly difficult and very prone to unexpected strings not being interpreted.

    I used Netlinkdiagnostic, comes string from device [80,36, statcp, 60,30]
  • Options
    Spire_JeffSpire_Jeff Posts: 1,917
    I think that is showing ASCII, so the code I posted should work. Is it not working properly?

    Jeff

    P.S.
    In the function, make sure you remove the last ON[TP,100] statement as I did. The statement gets executed regardless of the condition.
  • Options
    LehaLeha Posts: 37
    Spire_Jeff wrote: »
    I think that is showing ASCII, so the code I posted should work. Is it not working properly?

    Jeff

    P.S.
    In the function, make sure you remove the last ON[TP,100] statement as I did. The statement gets executed regardless of the condition.

    Works only when is not present 60 in line.
  • Options
    Spire_JeffSpire_Jeff Posts: 1,917
    I suppose I should ask you want you want the code to do? If you simply want everything to be exactly opposite, you could just switch the code in the IF section with the code in the ELSE section.

    If you could describe what you want to happen in a little more detail, I might be able to suggest a change to the code.

    Jeff
  • Options
    LehaLeha Posts: 37
    new

    On a picture the answer from the device. The program does not work, where an error?


    PROGRAM_NAME='AMX'

    DEFINE_DEVICE

    MIO_R4 = 128:1:0

    LIGHT = 5001:5:0


    DEFINE_VARIABLE

    VOLATILE CHAR STRING_FROM_DEVICES[50]

    DEFINE_EVENT

    DATA_EVENT [LIGHT]
    {
    ONLINE:
    {
    SEND_COMMAND LIGHT,"'SET BAUD 9600,N,8,1 485 Disable'"
    }
    }

    DATA_EVENT [LIGHT]
    {
    STRING:
    {
    STRING_FROM_DEVICES = DATA.TEXT
    LIGHT_CONTROL(STRING_FROM_DEVICES)
    }
    }

    DEFINE_FUNCTION LIGHT_CONTROL (CHAR STRING_FROM_DEVICES[50])
    {

    IF(FIND_STRING(STRING_FROM_DEVICES[50],'60',1))
    {
    ON[dvTP6,3000]
    }
    else
    {
    Off[dvTP6,3000]
    }
    }
  • Options
    HedbergHedberg Posts: 671
    I don't now if this is the only problem with your code or not, but look at this line:


    IF(FIND_STRING(STRING_FROM_DEVICES[50],'60',1))

    You are trying to perform the find_string function which requires a string as the argument.

    STRING_FROM_DEVICES[50]

    is a single character. In my opinion, this shouldn't even compile, but apparently it does.

    If you want to evaluate a string with this function it should be:

    FIND_STRING(STRING_FROM_DEVICES,'60',1)

    Also, you are using the same variable name (STRING_FROM_DEVICES) for both a global variable and a variable local to your function. The way that you have it will probably work as intended, but it might be confusing.
  • Options
    LehaLeha Posts: 37
    Hedberg wrote: »
    I don't now if this is the only problem with your code or not, but look at this line:


    IF(FIND_STRING(STRING_FROM_DEVICES[50],'60',1))

    You are trying to perform the find_string function which requires a string as the argument.

    STRING_FROM_DEVICES[50]

    is a single character. In my opinion, this shouldn't even compile, but apparently it does.

    If you want to evaluate a string with this function it should be:

    FIND_STRING(STRING_FROM_DEVICES,'60',1)

    Also, you are using the same variable name (STRING_FROM_DEVICES) for both a global variable and a variable local to your function. The way that you have it will probably work as intended, but it might be confusing.

    If to write so should work?

    FIND_STRING (STRING_FROM_DEVICES, ' 60 ', 1)
  • Options
    That looks like it should work. the STRING_FROM_DEVICES is a CHAR variable of 50 characters, containing the string. STRING_FROM_DEVICES [50] as part of a function or argument is the 50th character in the string.

    example
    CHAR STRING_FROM_DEVICES [50] = " '12345678901234567890123456789012345678901234567890' "
    
    SEND_STRING 0, " 'sending ', STRING_FROM_DEVICES, $0D " 
    

    will return "sending 12345678901234567890123456789012345678901234567890$0D"

    whereas
    SEND_STRING 0, " 'sending ', STRING_FROM_DEVICES [50], $0D "
    

    will return " sending 0$0d "
Sign In or Register to comment.