Script problems


Recommended Posts

Hi

I am using the script below to send a poll and retrieve the data via a custom protocol.

I,Dig_input_status_1,25,input,numeric

private string dataout = "$03" + DoubleToStr(6) + Chr(13)

private string datain = Poll(dataout,13)

return (Mid(datain,2,1))

ENDIO

I have a channel called Dig_input_1 where the polled data is called from.

If I setup a variable value display with the expression Dig_input_1[0] the data shown is correct - the hex representation of the input data.

When I setup a LED display and put in the expression (Dig_input_1[0] & 0x2) to try to change the led status when 0x2 is a valid input there is no action. If I simulate the display with the expression (0x2 & 0x2) it works correctly.

Can someone please advise where I am going wrong.

Link to comment
Share on other sites

You are returning the value as a string. You can do boolean math on a string. Change that last line to:

return(strToDouble(Mid(datain,2,1)))

Note, if the value is a Hex representation, not decimal representation, you'll need to do:

return(strToDouble("0x" + Mid(datain,2,1)))

Link to comment
Share on other sites

One more question that I found today.

These scripts work

private string dataout = "#01" + DoubleToStr(3) + Chr(13)

private string dataout = "$03" + DoubleToStr(6) + Chr(13)

but when I use the following it gives an error

private string dataout = "@05DO0" + DoubleToStr(1) + Chr(13)

Is there something wrong with using the @ symbol or am I doing something wrong. When I monitor the sent data in the comms window I see the 05DO01 but the @ is missing and the module does not respond.

This is the command description from the manual :

@AADO

Name Set Digital Output

Description Sets the values of the module

Link to comment
Share on other sites

The @ sign when placed as the first character of a string is used by the translation feature of DAQFactory to indicate that the phrase may be translated. When a matching phrase is not in the currently selected language (which would be true in your case since you didn't setup any languages), it just strips the @. To actually put an @ sign first in a string, do two of them. Only the first will be stripped:

"@@05DO0"

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.