Rs485_write(), Rs485_close() – Echelon i.LON SmartServer 2.0 User Manual
Page 246

232
Appendix A - Programmer’s Reference
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-485 port.
EXAMPLE
The following example demonstrates a rs485_read()method that reads data from the RS-485
interface.
rs485_read(fd, someBuffer, 1);
rs485_write()
You can use the rs485_write()method in the OnTimer()routine to write data to the RS-485
interface.
SYNTAX
int rs485_write(int fd, unsigned char * buf, int length);
The fd parameter specifies the file handle returned when the RS-485 interface was opened with
the rs485_open() method.
The buf parameter specifies a pointer to the memory area containing the data to be written to the
RS-485 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-485 port.
EXAMPLE
The following example demonstrates a rs485_write()method that writes to the RS-485
interface.
rs485_write(fd, someBuffer, strlen(someBuffer));
rs485_close()
You can use the rs485_close()method in the Shutdown() routine to close the RS-485
interface.
SYNTAX
int rs485_close(int fd);
The fd parameter is the file handle returned when the RS-485 interface was opened with the
rs485_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-485 port.
EXAMPLE
The following example demonstrates a rs485_close()method that ends an RS-485
connection.
rs485_close(fd);