User`s guide
Give your I/O type a name (say GetData) and leave the rest in their default
settings and hit OK. This adds the new I/O type to the protocol and gives a blank
box for entering code for this I/O Type. With the Poll function DAQFactory already
created for you, this is really easy and requires only one line of code:
return(StrToDouble(Poll("D"+chr(13),13)))
Starting from the inside we have “D” + chr(13). This is simply a string containing
D plus a carriage return (ASCII code 13). The chr() function simply takes an
ASCII code number and creates the corresponding character. The Poll() function
takes the string to output as its first parameter. The second parameter, 13, is the
end of line character for the reply from your device. The Poll() function will return
the entire string received up to this end of line character. So, moving out, we
take this string and send it to the StrToDouble() function which converts our
string into a number. So if the reply was “3248”, it would convert it to the
number 3248. In almost every case you’ll need to convert the string reply from
your device into a number. Finally, we return that number from our I/O type
function. This will put it in the channel.
To use this I/O type we have to apply the protocol to our new serial / Ethernet
device. First close the protocol configuration window by hitting OK. This will save
the new protocol. Now in the device configuration window, check your
communication port and put a check next to your new protocol. Give your device
a name, say, MyDevice, and hit OK. Now if you go to the channel table and
create a new channel you will see MyDevice listed in combo box in the Device
column. If you select the MyDevice device type you will see GetData in the I/O
type column. The D# and Channel number are not used in the code we wrote. If
you select a timing of 1 and hit apply, DAQFactory will start sending out D and
carriage return every second waiting for a reply. If you open the monitor on the
comm port you will see this.
That is the simplest of polling routines, and in many cases this is all you need. If
you had different commands to get different values, you would simply create
more I/O types and send a different command to the Poll function.
Getting a little more advanced, we’ll assume that your device has multiple
channels. Let’s say the command is still “D”, but with the channel number after.
For example, D5 plus carriage return would return the data from channel 5 on
your device. Ideally we want to use a single I/O type function and use the
channel number specified in the channel table. Fortunately, DAQFactory passes
several private variables to your I/O type function that describe the channel. This
includes the device number, channel number and more. For now, we’ll just use
the channel number. Fortunately, the code isn’t that much more complicated. To
make it easier to read, though, we’ll split it into a couple lines:
private string dataout = "D" + DoubleToStr(Channel) + Chr(13)
return(StrToDouble(Poll(dataout,13)))
The first line creates the output string. Its just like before, but we put the
channel in the middle. The Channel variable is a number, so we need to convert it
to a string too using the DoubleToStr() function. Then, we simply call the Poll()