User`s guide
Mid(datain,1,4) returns the 2
nd
through 5
th
characters, thus skipping the first
code which should be 15, our command code echoed back to us.
AscA(...) converts those 4 characters into an array of 4 numbers. This is the
exact opposite of ChrA(). Actually, if you did ChrA(AscA("abc")) you'd get the
string "abc".
To.Long(...) converts an array of bytes to a single long value, which we then
return. The To. functions are the opposite of the From. functions. From.
functions convert a from a number to bytes, while the To. functions convert to a
number from bytes.
Binary protocols aren't much more complicated than ASCII protocols as long as
you remember that a string is just a series of numbers, each between 0 and 255.
Fixed field length protocols are equally easy, though you need to make a small
modification to the Poll function, but that's why we coded it in DAQFactory script.
Creating a Protocol to Accept non-polled Data
While the majority of devices use the poll / response method, there are still a fair
number of common devices that simply stream their data without prompting.
Some common examples of this are GPS devices (and most anything that uses
the NMEA protocol), and scales. For these types of devices we use the OnReceive
event of an user protocol to capture and parse data as it comes in. To create an
user protocol, click on the New Protocol button in the Ethernet / Serial device
window. This will open the Protocol configuration window:
This window is very similar to the user device window, but that is not terribly
important at this time. At the top you should specify a name for your protocol.
This can be just about anything, though like all names in DAQFactory, it should
start with a letter and have only letters, numbers, or the underscore. You will
also have to specify a file name for the protocol. Protocols are stored separate to
your document in a text file. This allows you to use a protocol on multiple
documents and even share the protocol with other DAQFactory users. Because it
is stored in a separate file you will need to make sure and copy the protocol file if
you move your document to another computer. When specifying the protocol file,
you should make sure that the file ends in .ddp and stored in your DAQFactory