String from device
Leha
Posts: 37
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]
}
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]
}
0
Comments
See if that works better.
Jeff
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
I am not assured that it is a line! And how to learn what is it?
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]
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.
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
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]
}
}
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)
example
will return "sending 12345678901234567890123456789012345678901234567890$0D"
whereas
will return " sending 0$0d "