beautypg.com

Rs485_setparams(), Rs485_ioctl() – Echelon i.LON SmartServer 2.0 User Manual

Page 244

background image

230

Appendix A - Programmer’s Reference

Verify that the file handle is specified in a global variable so that you can reference it from the
Work()

and Shutdown() routines.

EXAMPLE

The following example demonstrates a rs485_open()method that opens an RS-485 connection
with a baud rate of 9600.

int fd = rs485_open(9600);

rs485_setparams()

You can use the rs485_setparams() method in the Initialize() routine to set the operating
parameters of the RS-485 interface. You should call this method to initialize the RS-485 interface
immediately after opening it with the rs485_open() method.

SYNTAX

int rs485_setparams(int fd, unsigned int BaudRate, EDataLength
DataLength, EParity Parity, EStopBits StopBits);

The fd parameter is the file handle returned when the RS-485 interface was opened with the
rs485_open()

method.

The BaudRate parameter specifies the baud rate at which RS-485 interface communicates with
the serial port.

The DataLength parameter specifies the data bit size to be used for messages sent by the RS-
485 interface. You can specify a bit size of 5, 6, 7, or 8 bits.

The Parity parameter specifies the parity bit to be used for messages sent by the RS-485
interface. A parity bit is an extra bit used to check for errors in groups of data bits transferred
between devices. You can specify a parity bit that is odd or even.

The StopBits parameter specifies the number of stop bits to be used for messages sent by the
RS-485 interface.

For more information on these options, see the FPMLibrary.h file in the
iLON/Development/eclipse/plugins/com.echelon.eclipse.ilon100.fpm_0.9.0/compiler/echelon/fpm
/include folder in your L

ON

W

ORKS

directory

This method returns the 0 upon success, and it returns -1 upon failure. A failure could occur if
another FPM is using the interface, or if the interface is not properly connected to the RS-485 port.

EXAMPLE

The following example demonstrates a rs485_setparams()method:

rs485_setparams(fd, 9600, eDL8Bit, ePNone, eSB1);

rs485_ioctl()

You can use the rs485_ioctl() method in the Initialize() routine to send commands to the
RS-485 interface.

SYNTAX

int rs485_ioctl(int fd, int cmd, int data);

The fd parameter specifies the file handle that was returned when the RS-485 interface was
opened with the rs485_open() method.

The cmd parameter specifies the command to be sent to the RS-485 interface. The data
parameter specifies the corresponding value to be used with the cmd parameter. The values for
the cmd and data parameters are defined in the FPMLibrary.h file in the