AzeoTech® DAQFactory® Serial / Ethernet Communications Guide
DAQFactory Serial / Ethernet Communications Guide DAQFactory for Windows, Version 5.34, July 18th, 2006. Copyright © 2001-2006 AzeoTech, Inc. All rights reserved worldwide. Documentation Version 1.00. Information in this document is subject to change without notice. AzeoTech is a registered trademark of AzeoTech, Inc. DAQFactory is a registered trademark of AzeoTech, Inc. Other brand and product names are trademarks of their respective holders. Copyright © 2001-2006 AzeoTech, Inc.
Overview DAQFactory can communicate with a wide variety of devices with serial (RS232/422/485) and Ethernet connections. This guide explains how to start communicating with your device and how to create a protocol to interpret the language your device speaks. Since serial and Ethernet communications are done almost identically, we’ll simply refer to it as serial communications. Ethernet is actually a serial technique, meaning bits of data are sent over the wire one after another.
port on your PC. For even more specialized devices, such as USB DAQ devices, the manufacturer should provide a DLL with functions you can call to communicate with the device. To use these devices in DAQFactory, you should use extern() function and perhaps create a user device. Bottom line: if you are trying to communicate with a USB device, and not a serial to USB converter (or device that appears as a serial port) you are reading the wrong guide. One more note about serial to USB converters.
Getting Started Enough of the fine print on USB devices. Let’s start communicating with your device. The first step when trying to setup a new serial device in DAQFactory is to initialize and test the communications. To do this, we’ll create a new communications port and use the DAQFactory monitor window to talk to it. 1) Start DAQFactory, or go File-New if you have already started DAQFactory. 2) Select Quick – Device Configuration from the DAQFactory main menu, then select New Serial / Ethernet Device.
New Serial: 4) If you are doing a serial (RS-232, RS-422 or RS-485) connection: in the window that appears, give your comm port a name, then specify the comm port number and its parameters. This information is usually available from your device’s manual. The default timeout value of 1000 is fine. Most likely flow control will be off. New Ethernet: 5) If you are doing an Ethernet connection: in the window that appears, give your connection a name, then enter the IP address of the device.
The Monitor Window 6) Once you have created your new port, click on the port in the port list so there is a check next to it, and then click the monitor button. This will display the DAQFactory serial monitor window. This window allows you to view the data being transmitted and received on the serial line. It also allows you to manually transmit data. This window is unique in several ways. First, it is what is called a modeless window.
characters, put a backslash and the three digit code. For example, if you needed to send it “Give me data” and a carriage return, you would put: Give me data\013 13 is the ASCII code for carriage return, so \013 sends a carriage return at the end. Other common codes are \010 for a line feed (LF), and \009 for tab. If you have no idea what to send, start with a carriage return: \013.
Mitsubishi uses a combined binary ASCII protocol, thus the combination of control codes (\002 and \003) and ASCII characters. For other devices or if you’d prefer to skip entering manual commands, you should jump ahead to the section on prebuilt protocols, leaving the monitor window open so you can see when the communications starts working. If DAQFactory doesn’t have a prebuilt protocol for your device, you probably should study the device’s instructions and manually calculate out a proper string.
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.
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).
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.
Binary and fixed field protocols: But first, we should talk a little more about binary protocols. The protocols so far have been primarily ASCII protocols. The only binary information is the carriage return that marks the end of the line of data.
Mid(datain,1,4) returns the 2nd through 5th 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.
installation directory. If it does not end in .ddp, or if it is not placed in the DAQFactory directory, it will not be loaded the next time you start DAQFactory. Once you have specified the protocol name and file name, you can begin creating the protocol. Let’s jump right in with an example. Let’s say you have a scale that simply outputs the weight every second as a number followed by a carriage return.
Channel.AddValue(strDevice, 0,"Input",0, StrToDouble(Parse(DataIn,0,","))) Channel.AddValue(strDevice, 0,"Input",1, StrToDouble(Parse(DataIn,1,","))) Endif All we added was the Parse() function to split the data apart and then two calls to AddValue to put the data into channels 0 and 1. The Parse command takes 3 parameters, the string to parse, the index you want to retrieve and the delimiter.
endif Of course you’ll need to set and clear the streamflag from somewhere. This can be done in the code that sends the stream start and stop commands to the device.
Advanced Communications The Poll() function in detail: Here is the script for the poll function with line numbers: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 function Poll(string out, until) // this function will poll the port with given string and read // the response until the given character.
being over used, the port may not come available within the timeout specified in the port. In this case, LockPort() returns 0 and we throw an error. We can’t do anything else, otherwise we’d defeat the purpose of locking the port in the first place. In line 15 we purge the port. This clears out any extraneous data on the port and is usually a good idea just to be sure nothing is left over from a previous request. Once purged, we can write the string out in line 17.
Ethernet Primer Since an IT person may not be available, here is a quick explanation of Ethernet communications and IP addressing and a few pointers at the end. Ethernet communications can be complicated, especially in large corporations. If you do not feel comfortable with this, you should contact an IT person. Assigning an incorrect IP address may bump another individual off the network and is not a good way to make friends.
4 billion computers directly connected to the Internet. Fortunately there are things called routers which allow you to connect multiple computers on a LAN (local area network) to a single IP address on the internet. Each computer on the LAN has its own IP address, but in order to communicate with computers on the internet the computer has to connect to the LAN’s router, called a gateway first.
hardware devices. You have to have both the correct IP address and port to communicate with a device over Ethernet. One final discussion: static versus dynamic IP addressing. To make the installation of new PC’s easier on the IT people, something called DHCP was invented. DHCP is a protocol used to automatically provide IP addresses to devices. The DHCP retains a list of IP addresses that can be used and when a new computer connects to the LAN, it finds the DHCP server and requests an IP address to use.
will probably not want to simply plug this device into your LAN. Instead, you should connect directly to the device with a crossover cable and assign your PC an IP address on the same subnet, 192.168.1.2 for example. 6) Be careful when you have multiple Ethernet connections. This is especially common on laptops that have both a wireless and wired connection. Depending on your settings, the two connections may be on completely different subnets which may prevent a connection.