Using DASYLab to Communicate over RS-232

Last Modified: 3rd Jan 2013
Category: Data Acquisition > DASYLab
Platform: All
Version: All
Article Ref.: 13C72
»Return to previous search
»Print friendly version of this article.
1 person has found this article useful.

DASYLab 13C72 Figure 1: A simple DASYLab worksheet to read data from an instrument via RS-232. Open the Modules menu, and go to the Input/Output section. Paste an RS-232 input module onto the worksheet. (Click OK to the Select New input module at different Interface dialogue.) If an error opening serial interface message appears, ignore and close it. This message appears because the serial interface has not been configured yet. Figure 2: RS232 Input Selection dialogue You should now see an RS-232 Input module on the worksheet. Double click this module to open the configuration screen. Figure 3: Main RS-232 input Configuration Screen Set up the COM Port You will need to know the correct COM Port settings for your device. The settings are often configured from the panel of the device, or may be fixed and documented in the device manual. Click the Interface button and select the correct RS-232 port to which the device is attached, and the correct port settings. Finally, Click OK to return to the Main RS-232 Configuration Dialogue. Figure 4: RS-232 Interface Settings Configuring the Data Format If a manual for the device is available, refer to it to determine the format of the data return string, and whether any initialisation strings or command strings are required. If a manual is not available, you may be able to determine the format of the data return string using the DASYLab Monitor window. Click the RS232 Monitor Button, and the RS232 Monitor dialogue will appear. This window enables you to monitor the activity over the RS-232 interface. You can send custom command strings to the instrument, and you can use the Highlight Parsing option to test your Data Format configuration. Close the RS-232 monitor when you have determined the format of the data returned by the instrument. In the main RS-232 dialogue, expand the number of channels in the module to correspond to the number of fields which are being returned in each record by the instrument. For each field, you need to define a field format in the Data Format text box. For a single field record, or for delimited fields, this will typically be the character a (which signifies ASCII numerical value of any length) followed by one or more terminator or delimiter character. (The last field will use the terminator rather than the delimiter.) The DASYLab Help File contains an ASCII table, which you can refer to find the correct ASCII code for the terminators and delimiters. ASCII codes are written in the format \xHH where HH is the hexadecimal control character. Sample Data Format Codes: ASCII numerical field, comma delimited a\x2c ASCII numerical field, tab delimited a\x09 ASCII numerical field, terminated a\r ASCII numerical field terminated a\r\n ASCII numerical field terminated, ignore first three characters (e.g. because they are not numerical.) 3xa\r\n Advanced Note -------------- If the data format contains characters which are not numeric, or is very complex, you could write the string directly to a Global string. You can then create a string parsing expression to find substrings and perform other formatting. If you use this option, the data will not be available at the output pins of the RS-232 Input module, but must be accessed by reading the Global Strings. To write a terminated field to a Global String: $1\r\n Configuring more than 16 fields -------------------------------- DASYLab can parse up to 256 separate fields from an RS-232 interface. The single RS-232 input module allows the definition of up to 16 channels. To define additional channels, paste an additional RS-232 module into the worksheet and select the option "Channel Expansion from RS232 Master Module." The slave module uses the configuration of the existing master module, but allows you to configure format strings for additional channels. Figure 5: Defining more than 16 channels for an existing RS-232 device Configuring Data Requests The instrument typically returns data under one of three conditions: i) The user presses a button on the panel of the instrument. ii) The instrument returns data periodically, at timed intervals. iii) The PC generates a Data Request string, which prompts the instrument to return data. Options i) and ii) may be configured from the panel of the instrument, or by sending the instrument an initialization string. Option iii) can be configured in DASYLab. To set up a periodic Data Request, click the Options button from the main configuration screen, and select the option "Request Data". The sample interval at which the data request string is sent is user defined, the default value is one value every 1.00 second. (see Figure 5) The Data Request string is entered in the "Data Request Command" field of the Main RS-232 Input Dialogue (see Figure 3.) You can define a separate string per channel, but for many devices a single data request string will prompt the device to send a complete record; in which case a data request command should only be defined for the first field. Figure 6: Configuring Options for RS-232 Input module Figure 7: RS-232 configuration dialogue showing a Data Request Command. Figure 8: RS-232 configuration dialogue showing a Data Request Command and a Search String using binary syntax. Configuring an Initialisation String The start string is sent to the device when the worksheet first runs. This field is optional, but you can use it to send initialisation commands to the instrument. Configuring a Timeout/Reset String You can configure error handling to send the reset commands to the unit if no data is received within a user defined timeout period. Enable the Error handling restart on timeout option at the bottom of the RS232 Input module options dialogue (see Figure 6). The Reset String can also be sent to the device using an Action Module. Configuring a Stop String Configuration of this field is optional. Typically, this field can contain a command string to return control to the front panel of the instrument. Communicating with more than one Device DASYLab can communicate with up to 8 separate COM interfaces from a single worksheet. To configure additional devices on separate COM ports, paste an additional RS-232 module onto the worksheet and select the option "New RS232 Master Module at additional Serial Interface" Configuring Additional Commands You may have additional commands to configure, and wish to set up a button controlled interface to generate these commands on the DASYLab layout screen(s). To do this, use the RS-232 Output module from the Input/Output group in the modules menu. Post Script If a device supports the MODBUS protocol, you could use the DASYLab MODBUS module to communicate with it. If a device is provided with OPC server software, then you can connect to it via the DASYLab OPC module. How Do I? DASYLab All All en DASYLab

If you can't find a solution on the Knowledge Base then please contact us on the Technical Support Request Form or by email or by telephone on +44 (0) 203 695 7810