Using RS-232 Device Sessions
An RS-232 device session allows direct access to a device, regardless of the type of interface to which the device is connected. The specifics of the interface are hidden from the user.
This topic provides an overview of RS-232 interfaces, including typical hardware configuration, using the Connection Expert utility, and an example of a configuration using SICL.
The subtopics are:
- Addressing an RS-232 Device
- SICL Functions for RS-232 Device Sessions
- Device Session Sample Programs
Addressing an RS-232 Device
To create a device session, specify the interface logical unit or symbolic name, followed by a device logical address of 488. The device address of 488 tells SICL that communication is with a device that uses the IEEE-488.2 standard command structure.
For other interfaces (such as GPIB), SICL supports the concept of primary and secondary addresses. However, for RS-232, the only primary address supported is 488. SICL does not support secondary addressing on RS-232 interfaces.
NOTE: If a device does not “speak” IEEE-488.2, you can still use SICL to communicate with the device. However, some SICL functions that work only with device sessions may not operate correctly. See SICL Functions for RS-232 Device Sessions for details.
The interface logical unit and symbolic name are defined by running Connection Expert.
 Click here to learn how to launching Keysight Connection Expert.
Click here to learn how to launching Keysight Connection Expert.
                                            
There are two methods to launch Connection Expert (CE):
From the Application Finder:
- 
                                                            Open the Application Finder on your Linux machine.
- 
                                                            Use any of the following ways to launch Connection Expert:- 
                                                                    Search for Connection Expert and click to launch the application.
- 
                                                                    Or, search for IO Control and launch it. In the IO Control application, click on the Connection Expert application to it.
 
- 
                                                                    
- 
                                                            Open your preferred web browser.
- 
                                                            Enter the URL in the format: https://<IP Address of the machine where IO Libraries Suite is installed>:4211.
 For example: https://10.17.68.235:4211.
Some example addresses for RS-232 device sessions:
	COM1,488
	serial,488
                                        Examples of opening a device session with an RS-232 device:
C sample:
	INST dmm;
	dmm = iopen (“com1,488”);
                                        Visual Basic sample:
	Dim dmm As Integer
	dmm = iopen (“com1,488”
                                        SICL Functions for RS-232 Device Sessions
This section describes how some SICL functions are implemented for RS-232 device sessions. There are specific device session interrupts that can be used.
| Function | Description | 
| iprintf, iscanf, ipromptf | SICL’s formatted I/O routines depend on the concept of an EOI indicator. Since RS-232 does not define an EOI indicator, SICL uses the newline character (\n) by default. 
 You cannot change this with a device session. However, you can use the iserialctrl function with an interface session. See in this topic for details. | 
| ireadstb | Sends the IEEE 488.2 command *STB? to the instrument, followed by the newline character (\n). It then reads the ASCII response string and converts it to an 8-bit integer. This will work only if the instrument understands this command. | 
| itrigger | Sends the IEEE 488.2 command *TRG to the instrument, followed by the newline character (\n). This will work only if the instrument understands this command. | 
| iclear | Sends a break, aborts any pending writes, discards any data in the receive buffer, resets any flow control states (such as  | 
| ionsrq | Installs a service request handler for this session. Service requests are supported for both device sessions and interface sessions. See SICL Functions for RS-232 Device Sessions in this topic for details. | 
Device Session Sample Programs
This section contains two sample programs for RS-232 interface device session programming.
Sample: RS-232 Device Session (C)
This sample program takes a measurement from a DVM using a SICL device session. This sample program was tested with a 34401A digital voltmeter. When you run the program with a serial connection to the 34401A, be sure that DTR/DSR flow control is set for the serial port. Otherwise, the program will appear not to work.
/* ser_dev.c
                                        
	This example program takes a measurement from a DVM using a SICL device session.*/
#include <sicl.h>
                                        
#include <stdio.h>
#include <stdlib.h>
#if !defined(WIN32)
                                        
	#define LOADDS __loadds
#else
	#define LOADDS
#endif
void SICLCALLBACK LOADDS error_handler (INST id,
                                        
  int error) {
  	printf (“Error: %s\n”, igeterrstr (error));
                                        
  	exit (1);
  }
main()
                                        
  {
  	INST dvm;
  	double res;
  	/* Log message and terminate on error */
                                        
  	ionerror (error_handler);
  	/* Open the multimeter session */
                                        
  	dvm = iopen (“COM1,488”);
  	itimeout (dvm, 10000);
  	/* Prepare the multimeter for measurements */
                                        
  	iprintf (dvm,”*RST\n”);
  	iprintf (dvm,”SYST:REM\n”);
  	/* Take a measurement */
                                        
  	iprintf (dvm,”MEAS:VOLT:DC?\n”);
  	/* Read the results */
                                        
  	iscanf (dvm,”%lf”,&res);
  	/* Print the results */
                                        
  	printf (“Result is %f\n”,res);
  	/* Close the voltmeter session */
                                        
  	iclose (dvm);
  	/* This call is a no-op for WIN32 programs */
                                        
  	_siclcleanup();
  	return 0;
                                        
  }
Sample: RS-232 Device Session (Visual Basic)
This sample program takes a measurement from a DVM using a SICL device session. This sample program was tested with a 34401A digital voltmeter. When you run the program with a serial connection to the 34401A, be sure that DTR/DSR flow control is set for the serial port. Otherwise, the program will appear not to work.
Option Explicit
                                        
'''''''''''''''''''''''''''''''''''''''''''''''
'  ser_dev.bas
'  This example program takes a measurement from
‘ a DVM using a SICL RS-232 device session.
'''''''''''''''''''''''''''''''''''''''''''''''
Sub Main()
                                        
  Dim dvm As Integer
                                        
  Dim res As Double
  Dim argcount As Integer
  ' Open the multimeter session
                                        
  ' "COM1" is the SICL Interface name as defined
  ‘ in Connection Expert
  ' Change this to the SICL name you have defined
  dvm = iopen("COM1,488") 
  ' Set timeout to 10 sec
                                        
  Call itimeout(dvm, 10000)
  ' Prepare the multimeter for measurements
                                        
  argcount = ivprintf(dvm, "*RST" + Chr$(10),
    0&)
   argcount = ivprintf(dvm, "SYST:REM" +
     Chr$(10), 0&)
  ' Take a measurement
                                        
  argcount = ivprintf(dvm, "MEAS:VOLT:DC?" +
    Chr$(10))
  ' Read the results
                                        
  argcount = ivscanf(dvm, "%lf", res)
  ' Print the results
                                        
  MsgBox "Result is " + Format(res),
    vbExclamation
  ' Close the multimeter session
                                        
  Call iclose(dvm)
  ' Tell SICL to cleanup for this task
                                        
  Call siclcleanup
End Sub
                                        
 (Windows only)
 (Windows only)