Product Quick Links |
DI-149 Communication ProtocolAlthough DATAQ Instruments provides ready-to-run WinDaq software with its DI-149 Data Acquisition Starter Kits, programmers will want the flexibility to integrate the DI-149 in the context of their own application. To do so they want complete control over DI-149 hardware, which can be accomplished by using the device at the protocol level. This white paper describes how protocol-level programming of the DI-149 is implemented across the Windows and Linux operating systems. First, we'll describe the virtual COM operation of the DI-149's interface and how communicating with the DI-149 is accomplished via a COM port hooked by the operating system. Then we'll define the DI-149's command set and scan list architecture and finish with a description of the DI-149's binary and ASCII response formats. Note that all of the commands and their arguments described in this protocol are lower case unless otherwise stated. Virtual COM Port OperationInstalling the DI-149 driver package and connecting DI-149 hardware to the host computer's USB port results in a COM port being hooked by the operating system and assigned to the DI-149 device. Multiple DI-149 devices may be connected to the same PC without additional driver installations, which results in a unique COM port number assignment to each by the operating system. Hooking a COM port in this manner facilitates ease of programming from any operating system and programming language by simply writing commands to and reading responses from the port, but before any meaningful communication with a connected DI-149 can begin the controlling program must determine the COM port number assigned to the device. The method used for this varies as a function of the host operating system. Virtual COM Driver (Windows)DATAQ Instruments provides a minimum installation for Windows that you can download and use at no charge, even for OEM applications. This is a scaled-down version of the standard installation that omits WinDaq software and other utilities that are extraneous in a pure programming environment. The download provides a Microsoft-signed INF file that ensures trouble-free operation with Windows XP (32-bit only), and both 32- and 64-bit Windows Vista and Windows 7. The installation depends upon driver usbser.sys, a Windows component located in path %SystemDrive%\Windows\System32\Drivers. COM Port Number Discovery (Windows)Using the DI-149's vendor and product IDs, Windows' registry can be accessed programmatically to determine the COM port number that the operating system assigned to one or more connected DI-149s. The Vendor and Product ID combination for the DI-149 is: Vid_0683&Pid_1490. With this information and at least one connected DI-149, determining assigned COM port numbers is a two-step process:
COM port number assignments may also be determined manually from Windows' Device Manager in its Ports (COM & LPT) section. However, the assigned value will change depending upon the physical USB port connected to the DI-149, any other devices that may hook COM ports, and the apparently arbitrary whims of the Windows operating system. Virtual COM Driver (Linux)Linux has two different generic drivers, which are appropriate for a USB to COM port converter. The first is an Abstract Control Model driver designed for modem devices, and is simply named acm. The other one is a generic USB to serial driver named usbserial. COM Port Number Discovery (Linux)If support for the acm driver has been compiled in the kernel, Linux will automatically load it and a new terminal device will be created under /dev/ttyACMx, where x is the COM port number. The path /dev/serial/by-id/usb-0683_1490-* presents links to /dev/ttyACM* device files of currently plugged in DI-149 devices. The second driver, usbserial, must be loaded manually by using the modprobe command with the vendor ID and product ID values used by the DI-149: modprobe usbserial vendor=0x0683 product=0x1490 Once the driver is loaded, a new terminal entry appears and should be named /dev/ttyUSBx, where x is the COM port number. DI-149 Command Set OverviewThe DI-149 employs a simple ASCII character command set that allows complete control of the instrument. ASCII comes in handy when a terminal emulators such as HyperTerminal or PuTTY are used to experiment with the device outside of a programming language environment. All of the commands in the following table must be terminated with a carriage return character (x0D) except the digital output command Dhh.
* Commands and arguments are separated by a space (0x20) delimiter. Basic Communication CommandsThe DI-149 command set supports a number of basic command/response items that provide a simple means of ensuring the integrity of the communication link between either a terminal emulator or program. These commands elicit simple, yet useful responses from the instrument and should be employed as the programmer's first DI-149 communication attempt. If these commands don't work with a functioning DI-149 then a problem exists in the communication chain and further programming efforts will be futile until they are resolved. Responses to this set of commands include echoing the command, followed by a space (0x20), followed by the response, and ending with a carriage return (0x0d). For example, the command "info 1" generates the following response: info 1 1490(0x0D)
Scanning Commandsstop and start CommandsCommands stop and start define the active scanning state. Command stop terminates scanning, and command start initiates scanning. slist CommandThe DI-149 employs a scan list approach to data acquisition. A scan list is an internal schedule (or list) of channels to be sampled in a defined order. It is important to note that a scan list defines only the type and order in which data is to be sampled, not the sampled data itself. The DI-149's scan list supports three types of inputs: Analog channels; Counter/timer channels; Digital inputs. These three type definitions may be placed in the DI-149's scan list in any order that satisfies the requirements of the application. The DI-149's scan list is a maximum of 11 elements long, which allows a hardware capacity measurement that's configured to sample all eight analog channels, both counter/timer channels, and one 4-bit digital input port during one complete scan. Note that any analog, digital output, rate, or counter channel may appear in the scan list only once. Each entry in the scan list is represented by a 16-bit number, which is defined in detail in the DI-149 Scan List Word Definitions table below, and ten out of the eleven elements of the scan list initialize to 0xFFFF upon power-up. 0xFFFF defines the end of the scan list, and the act of writing any value to the first position of the scan list automatically fills the remaining 10 elements with 0xFFFF. The first item in the scan list initializes to 0x0000 (analog input channel 0) upon power up. Therefore, upon power up, and assuming that no changes are applied to the scan list, only analog input channel 0 is sampled when scanning is set to active by the start command. Setting scan list position 0 to the value 0xFFFF results in no data being returned when scanning is initiated. The slist command along with two arguments separated by a space character (0x20) is used to configure the scan list: slist offset config offset defines the index within the scan list and can range from 0 to 0xA to address a total of eleven possible positions. config is the 16-bit configuration parameter as defined in table DI-149 Scan List Word Definitions. For example, the command slist 5 x000a configures the sixth position of the scan list to specify data from the counter. Other examples follow: asc this command is required since we will use the xhhhh format in the commands that follow slist 0 x0008 configures the first scan list position to specify data from the digital input port slist 3 x0009 configures the fourth scan list position to specify data from the rate input channel slist 0 x0006 configures the first scan list position to specify data from analog channel 6 slist 5 xffff terminates the scan list Assuming that we wish to sample analog channels 2, 4, and 6, and the rate, counter, and digital inputs, the following scan list configuration would work: asc this command is required since we will use the xhhhh format in the commands that follow slist 0 x0002 slist 1 x0004 slist 2 x0006 slist 3 x0009 slist 4 x000a slist 5 x0008 Note that since the act of writing to scan list position 0 forces the remainder of the list to the value 0xFFFF, the above configuration is complete upon writing scan list position 5. Further any scan list position (except position 0) may be modified without affecting the contents of the rest of the list. † To be consistent with general programming standards, analog and counter channel numbers begin with 0 instead of 1 as indicated on the product label. The protocol also supports a range setting for frequency measurements, which applies ONLY when the output coding format selection is binary. When the ASCII format is selected scaling is handled transparently by the firmware and presented as a floating point number in the output data stream. If the binary output mode is selected frequency counts are provided that range from 0 to 16,383 (14-bit.) Counts may be converted to a frequency in Hertz by applying the following formula: Hz = (Range) • (counts) ÷ 16384 Where "Range" is defined in the following table. Refer to the instrument's specifications for the maximum measurable frequency as a function of burst rate.
*A range selection DOES NOT apply when the output coding format is ASCII. srate Scan rate CommandCommand srate defines scanning speed, or the rate at which the DI-149 scans through the items in the scan that you defined above. srate is specified with an integer (int) argument within the range of 75 to 65,535, and the resulting scan speed per scan list element is defined by the following equation: Sample rate per scan list element (Hz) = 750000 ÷ srate, where This approach results in a per channel sample rate ranging from 11.44 to 10,000 Hz, depending upon the number of enabled channels. The host program may achieve a further reduction in sample rate below 11.44 Hz by using selective sampling methods whereby every nth point is selected as the converted value. For example, a sample rate per scan list element of 5 Hz is achieved by applying an integer value of 30,000 to the srate command, and further selecting every 5th value from the reported data stream. Every 25th reading is effectively 1 Hz. Averaging every n values on each channel is more difficult but recommended since it reduces the noise by a factor of the square root of n. Sidebar: 12-bit ADC Results From A 10-bit ADC DeviceDuring the calibration process performed at DATAQ Instruments and before the DI-149 is shipped to a customer, known voltage values are applied to each of its analog input channels and a connected PC calculates the required scale and offset factors so the instrument meets or exceeds its accuracy specification. Those factors are written to non-volatile memory built into the DI-149 for the instrument's processor to apply going forward. An unavoidable problem is that this procedure consumes a small amount of the DI-149's dynamic ADC range. Since the DI-149 is speced as having ten bits of measurement resolution, and if we were to report only those ten bits, resulting values would show missing counts or codes. If you applied a very precise ramp to an analog channel and slowly changed the voltage between positive and negative full scale you'd see a response that for the most part changed by only one ADC count as the applied voltage passed through the ADC's bit resolution thresholds, but occasionally you'd also see the ramp jump, skipping one count and resulting in a discontinuity called a missing code. Moreover, the places where missing codes exist would be different from unit to unit and even from channel to channel within the same unit. Obviously, this situation is unacceptable. Fortunately, the DI-149's ADC and protocol are designed for 12 bits, allowing us to use this improved resolution to provide an accurate calibration at nearly the 10-bit level without missing codes, but with the incongruity that we report a 12-bit number for an instrument speced for 10 bits of ADC resolution. The DI-149 is actually not a 12-bit device, since there will be between 993 and 1,024 active counts within the 4,096 possible 12-bit combinations. Usually the DI-149 will register a four-count change for every 19.53 mV change of applied voltage, but sometimes it will register a 5 count change of 24.41 mV. This value is a composite of a four-count change of the 12-bit converter (or a one count change of the 10-bit converter) equal to 19.53 mV, plus a one count change of the 12-bit converter equal to 4.88 mV. These large changes are approximately evenly distributed, with at least seven 19.53 mV changes between each. The largest weighted average step size is 20.14 mV, yielding an effective average ADC resolution of 9.96 bits. A device with the minimum 993 active counts would have a total of (869) 19.53 mV steps and (124) 24.41 mV steps. Output Format CommandsThe DI-149 offers a selection of three output formats: binary, ASCII (analog channels in ADC counts), and floating point (analog channels scaled into floating point voltages.) These are specified using the DI-149's output format commands. Command asc specifies the delimited ASCII output format in base 10 with analog channels dispalyed in ADC counts; command float specifies the delimited ASCII output format in base 10 with analog channels dispalyed as floating point voltages; bin specifies the binary output format. In all format instances, values for enabled channels (analog and/or digital and/or count and/or rate) are output in precisely the same order that they were defined in the scan list through use of the slist command. bin Output Format CommandThe DI-149's fastest data output format is a compressed binary stream of one 16-bit word per enabled measurement. The least significant bit of the first byte in the binary output stream is always cleared and set in all other response bytes to allow the host program to synchronize with the data stream. The state of the two least significant digital input bits of the DI-149 DO (Remote event) and D1 (Remote stop/start) is embedded in the binary stream of each transmitted analog channel. A logic low applied to either bit on DI-149 hardware results in a '0' value inserted for that bit in the data stream. This default inclusion supports WinDaq software's real time remote event and remote stop/start features. The stream sequence repeats until data acquisition is halted by the stop command.
Binary Analog Channel CodingThe DI-149 transmits a 12-bit binary number for every analog channel conversion. Meaningful information is extracted from these readings by inverting the most significant bit, and treating the result as a two’s complement number. Note that counts will change roughly by four for each 19.5 mV step change in applied voltage to yield approximately 10 bits of resolution (see the Sidebar: 12-bit ADC Results From A 10-bit ADC Device section above for a detailed explanation). * ADC counts versus applied voltage may vary depending upon calibration differences between individual DI-149 units. asc Output Format CommandAnalog, digital and counter channel data in an ASCII decimal format may be easier to work with in some situations at the application programming level. The asc command instructs the DI-149 to output data using an ASCII decimal format. Each scan (row) of data in an ASCII decimal format consists of a preceding "sc" fixed character pair, then the ASCII decimal representation of the results of active scan elements. Any leading zeros are suppressed for speed, a space delimiter is used between fields, and a carriage return (0x0D) terminates each line. The asc command evoked before other commands also allows command arguments to use the xhhhh hexadecimal format. The bin mode may be evoked after the ASCII mode using the xhhhh format for configuration without affecting the predefined setup. Since use of the ASCII output mode greatly multiplies the number of bytes transmitted by the DI-149 (e.g. as many as ten bytes per analog channel as opposed to two in the binary mode), the ASCII mode does not support the full sample rate capacity of the DI-149. Care should be taken to ensure that the value set for srate conforms to the following whenever the ASCII output mode is selected: srate > 375 × (the number of active scan list elements) DI-149 ADC channel data is output as a decimal number ranging from -2048 to 2047 as defined in the Ideal DI-149 ADC Binary Coding table above. The number should be interpreted as ADC counts, and will change approximately four counts per ADC step. The following is a typical output with four analog channels enabled:
The single DI-149 digital input channel is represented as a 16-bit decimal number ranging from 0 to 15 according to the following table:
The DI-149 counter channel is output as decimal values ranging from 0 to 16383:
The DI-149 rate channel is output as an auto-ranging floating point number:
If all channels are enabled on the DI-149 in the order of analog input channels 0-7, the digital, rate, and counter channels, the typical ASCII decimal output may look like this:
float Output Format CommandThe float command works in tandem with the asc command. Where the latter shows analog channel values in ADC counts, the float command converts ADC counts into a floating point number scaled in volts. You may toggle between float and asc to display volts and ADC counts respectively. Digital Output CommandsTwo digital output commands are supported by the protocol, one that echoes the command and another that does not. The dout command will cause the DI-149 to echo the command and its arguments back to the issuing program. The D command is also supported by the protocol to perform the same function, but it does not echo. Since digital output states may be changed dynamically and asynchronously during data acquisition, echo suppression may be used to ensure that the echo does not corrupt the stream of acquired data flowing from the DI-149 to the controlling program. dout command (echoed)The dout command accepts one argument separated by a space (0x20) that defines the state of the digital output bits. The argument can be supplied as an ASCII decimal number. An ASCII hexadecimal value using the xh notation may also be used if the dout command has been preceded by the asc command. Note that all digital output bits are low true, a logic 1 written to a bit causes the port to sink current and assume a logic 0 state.
D command (not echoed)The D command (case sensitive) is used when an echo is not desired. The D command is evoked with a two-character argument without delimiters to define the state of the digital output bits. The argument is not case sensitive and is supplied as an ASCII hexadecimal number with a leading 0 (zero) character. Note that all digital output bits are low true, a logic 1 written to a bit causes the port to sink current and assume a logic 0 state.
Reset CommandsCurrently there is only one reset command used to force accumulated counts to zero:
DI-149 Product Page: http://www.dataq.com/products/startkit/di149.html. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||




Go to Mobile Site