Please enable JavaScript to view this site.

DAQFactory User's Guide

Navigation: 16 Serial and Ethernet Communications

16.6 Low Level Comm

Scroll Prev Top Next More

In addition to using protocols to perform all the necessary communications, there are a variety of functions and variables you can call or set from sequence scripts to access the ports.  These can be used in user protocols, or in regular sequences.  All the functions and variables listed below start with Device.CommDeviceName. where CommDeviceName is the name you gave you Comm Device unless they are called from a user protocol.  Some of these functions may fail.  For example, if you try and read from a port and no data arrives within the timeout period.  When these functions fail they will throw an error.  The error will need to be caught in your sequence or the sequence will stop.

Functions:

For Both Serial and Ethernet:

InitComm(): Initializes the serial or ethernet port.  This is done automatically when you first try communications on the port.

ConfigureComm(): Displays the configuration window for the port.  Use this to allow the user to switch the communications settings.

Monitor(): Displays the monitor window for the port.  Use this to allow the user to view the low level communications information.

Write(string): Sends the given string to the port.  No carriage return or line feed is sent, so make sure and include it in your string if needed.

Read(Num Bytes): Reads the given number of bytes and returns the result in a string.  If a timeout occurs during the read then an error is generated.  You will not receive a partial string.  If you wish to simply read whatever is currently in the input buffer without waiting, do Read(0).  This is useful for polling applications when the size of the response is unknown and there is no end of line character.

Purge(): Clears out the input and output buffers.

ReadUntil(End Character): Reads from the port until the given byte is received. End Character should be the ASCII code of the byte.  For example, 13 for a carriage return.  If a timeout occurs before the end of character is found, an error is generated.

ReadUntil(Regular Expression): Reads from the port until the regular expression is matched. Regular expression should be a string.  If a timeout occurs before the end of character is found, an error is generated.  For example, the Allen Bradley DF1 protocol generates a Chr(10) and Chr(3) to mark the end of a frame, but only if there isn't another Chr(10) ahead of the combination.  To read a whole frame then, you would do:

 

ReadUntil("[^"+Chr(10)+"]" + Chr(10) + Chr(3))

For Serial Ports:

SetCommBreak(): Sets the comm port into a break state.  This is required for some protocols (SDI-12 for example).  While the port is set in break state, you cannot transmit or receive any traffic.

ClearCommBreak(): Clears the comm break state and allows communication again.

Variables:

There are different variables available for serial and ethernet type ports.  For this reason, these variables should not be accessed from a user protocol as it will fix the protocol to serial or ethernet.  When changing these variables, you must call InitComm() on the port to have them take effect.

For Both Serial and Ethernet:

Established: contains 1 if the connection is established, and 0 if not.  For serial ports this only indicates that the serial port could be opened.  It does not indicate whether there is a device connected to the port.  So, you will receive 0 for a serial port if the port doesn't exist, or if the port is in use by another application.  For Ethernet, there has to be a listening device at the desired IP / Port for a connection to be established, otherwise you will get 0.

LastReceiveTime: contains the DAQFactory timestamp of the last received data on the port.  This is useful for tracking active comms.

LastTransmitTime: contains the DAQFactory timestamp of the last sent data on the port.

PortName: a string containing the name of the communications port assigned to this device.  You can also set this variable to an existing port to change the port on the fly.  Just make sure you spell the port exactly how you named it.

ProtocolName: a string containing the name of the protocol assigned to this device.  You can also set this variable to an existing protocol to change the protocol on the fly.  Just make sure you spell the protocol exactly how it appears in the serial/ethernet configuration list.

Timeout: the timeout value of the port in milliseconds

For Serial Ports:

Baud: the baud rate on the port.  The following rates are supported: 110, 300, 600, 1200, 2400, 4800, 9600, 14400, 19200, 38400, 56000, 57600, 115200, 128000, 256000

Byte Size: the byte size on the port,

CTS: 0 or 1 depending on whether CTS is used.  Only applies if FlowControl is set to Manual.

DSR: 0 or 1 depending on whether DTR is used.  Only applies if FlowControl is set to Manual.

DSRSens: 0 or 1 depending on whether the DSR Sense is needed.  Only applies if FlowControl is set to Manual.

DTRControl: 0 = disable, 1 = enable, 2 = handshake.  Only applies if FlowControl is set to Manual.

FlowControl: a string: "None", "Hardware" or "Manual"

Parity: 0 = no parity, 1 = odd parity, 2 = even parity, 3 = mark parity, 4 = space parity

Port: the comm port number on your computer

RTSControl: 0 = disable, 1 = enable, 2 = handshake, 3 = toggle.  Only applies if FlowControl is set to Manual.

StopBits: 0 = one stop bit, 1 = 1.5 stop bits, 2 = two stop bits

For Ethernet Ports:

Address: a string containing the Ethernet address

Port: the Ethernet port to use