Using RS-232 Interface Sessions
RS-232 interface sessions can be used to get or set the characteristics of the RS-232 interface. Examples of some of these characteristics are baud rate, parity, and flow control. There are specific interface session interrupts that can be used.
Subtopics are:
- Addressing RS-232 Interfaces
- SICL Functions for RS-232 Interface Sessions
- Interface Sessions Sample Programs
Addressing RS-232 Interfaces
To create an interface sessionon RS-232, specify the interface logical unit or SICL interface ID in the addr parameter of the iopen function. The interface logical unit and SICL interface ID are defined by running 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 interface sessions follow.
|
COM1 |
A SICL interface ID |
|
serial |
A SICL interface ID |
|
1 |
An interface logical unit |
These code samples open an interface session with the RS-232 interface.
C sample:
INST intf;
intf = iopen (“COM1”);
Visual Basic sample:
Dim intf As Integer
intf = iopen (“COM1”)
SICL Functions for RS-232 Interface Sessions
This section describes how some SICL functions are implemented for RS-232 interface sessions.
Interface Sessions Sample Programs
This section contains two sample programs for RS-232 interface device session programming.
Sample: RS-232 Interface Session (C)
/*ser_intf.c
This program gets the current configuration of the serial port, sets it to 9600 baud, no parity, 8 data bits, and 1 stop bit, and prints the old configuration.*/
#include <stdio.h>
#include <sicl.h>
main()
{
INST intf; /* interface session id */
unsigned long baudrate, parity, databits,
stopbits;
char *parity_str;
/* Log message and exit program on error */
ionerror (I_ERROR_EXIT);
/* open RS-232 interface session */
intf = iopen (“COM1”);
itimeout (intf, 10000);
/* get baud rate, parity, data and stop bits */
iserialstat (intf, I_SERIAL_BAUD, &baudrate);
iserialstat (intf, I_SERIAL_PARITY, &parity);
iserialstat (intf, I_SERIAL_WIDTH, &databits);
iserialstat (intf, I_SERIAL_STOP, &stopbits);
/* determine string to display for parity */
if (parity == I_SERIAL_PAR_NONE) parity_str =
“NONE”;
else if (parity == I_SERIAL_PAR_ODD)
parity_str = “ODD”;
else if (parity == I_SERIAL_PAR_EVEN)
parity_str = “EVEN”;
else if (parity == I_SERIAL_PAR_MARK)
parity_str = “MARK”;
else /*parity == I_SERIAL_PAR_SPACE*/
parity_str = “SPACE”;
/* set to 9600,NONE,8,1 */
iserialctrl (intf, I_SERIAL_BAUD, 9600);
iserialctrl (intf, I_SERIAL_PARITY,
I_SERIAL_PAR_NONE);
iserialctrl (intf, I_SERIAL_WIDTH,
I_SERIAL_CHAR_8);
iserialctrl (intf, I_SERIAL_STOP,
I_SERIAL_STOP_1);
/* Display previous settings */
printf(“Old settings: %5ld,%s,%ld,%ld\n”,
baudrate, parity_str, databits, stopbits);
/* close port */
iclose (intf);
/* This call is a no-op for WIN32 programs. */
_siclcleanup();
return 0;
}