beautypg.com

Rs232_close(), Rs-485 interface methods, Rs485_open() – Echelon i.LON SmartServer 2.0 User Manual

Page 243

background image

i.LON SmartServer 2.0 Programming Tools User’s Guide

229

The buf parameter specifies a pointer to the memory area containing the data to be written to the
RS-232 interface.

The length parameter specifies the maximum number of bytes that are to be read.

This method returns the number of bytes read 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-232 port.

EXAMPLE

The following example demonstrates a rs232_write()method that writes to the RS-232
interface.

rs232_write(RS232_fd, someBuffer, strlen(someBuffer));

rs232_close()

You can use the rs232_close()method in the Shutdown() routine to close the RS-232
interface.

SYNTAX

int rs232_close(int fd);

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

method.

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-232 port.

EXAMPLE

The following example demonstrates a rs232_close()method that ends an RS-232
connection.

rs232_close(fd);

RS-485 Interface Methods

You can use RS-485 interface methods to connect an FPM driver to the devices attached to the RS-485
serial port on the SmartServer, initialize the RS-485 connection, read and write values to the data
points on the devices, and close the RS-485 connection. For more information on connecting a device
to the RS-485 serial port, see the i.LON SmartServer 2.0 Hardware Guide.

rs485_open()

You can use the rs485_open()method in the Initialize() routine to open the RS-485 interface.

SYNTAX

int rs485_open(int BaudRate);

The BaudRate parameter specifies the baud rate at which RS-485 interface communicates with
the serial port. See the documentation for your RS-485 interface for more information on baud
rates supported for your device. The SmartServer hardware supports connections to any baud rate
up to 115,200 with a definable buffer size. The default value is 1,024 bytes. When setting the
baud rate, you should consider the number of bytes the interface sends over the network per
second, the calculations performed between poll cycles, and whether a hardware handshake
between the interface and the hardware device is required.

The method returns the file handle (a value greater than or equal to 0) on success, and it returns a
negative value on 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.