User`s guide

function again, and return the result converted to a number. That’s it! Now you
can create multiple channels with the same I/O type and different channel
numbers and different commands will be sent to your device.
So far, we’ve assumed your device simply returns a number and a carriage return.
Most devices return extra stuff we don’t want. Often times this is simply the
command echoed back. Lets say our device returns “D” plus the value and a
carriage return. In this case we can’t just convert the result of the Poll() function
to a number because D doesn’t convert to any number in decimal. So we have to
change the code a little. Keeping it readable by splitting it into separate lines, it
would look like this:
private string dataout = "D" + DoubleToStr(Channel) + Chr(13)
private string datain = Poll(dataout,13)
return(StrToDouble(Mid(datain,1,10)))
Now lets get even more complicated and assume your device returns more than
one value with a single request. In this case, we’ll use a single channel to trigger
the read and then push the data into multiple channels. As an example, lets say
your device is polled with our original “D” plus carriage return, and it returns a
comma delimited list of 3 values followed by a carriage return. We’ll use channel
# 0 of our I/O type to trigger the read, and then put the data in channels 0,1 and
2:
if (Channel != 0)
return(NULL)
endif
private string datain = Poll("D"+Chr(13),13)
Channel.AddValue(strDevice,0,"GetData",1,StrToDouble(Parse(datain,1,",")))
Channel.AddValue(strDevice,0,"GetData",2,StrToDouble(Parse(datain,2,",")))
return(StrToDouble(Parse(datain,0,”,”)))
The first three lines ensure that we trigger the read from channel 0 only. This is
so we don’t have to worry about setting the Timing of channels 1 and 2 to 0.
Note that by returning NULL, we keep DAQFactory from adding a value to the
channel. The next line we do our standard Poll(). The following two lines stuff
the second and third values into channels 1 and 2. The Channel.AddValue()
function allows you to put data into a channel that you don’t know the name off.
It takes 5 parameters. The first 4 describe the channel (device type, device
number, I/O type, and channel number), the last contains the value to put in the
channel. strDevice is a local variable that contains the name of the device the
user created when using this protocol. You have to use strDevice because you
don’t know what a user might name their device. We then specified a D# of 0.
This means our channels will have to have a D# of 0, where previously it did not
matter. Next is a string with the name of our I/O Type. Finally we have the
channel number and the value to put in the channel. To retrieve the proper value,
we use the Parse() function. This function takes a string, the index into the string,
and the character used to delimit the string. In this case, the data is a comma
delimited string, and we want the second value (index 1 since its numbered from
0) for channel 1, and the third value for channel 2. Finally we return the first
value in the list to put it in channel 0.
That covers the primary types of poll / response protocols. Adapting to your
device is simply a matter of creating the correct output string and parsing the
input. Some protocols require more advanced functionality and that, along with
the details of how the Poll() function works is described at the end of this guide.