Page tree
Skip to end of metadata
Go to start of metadata

The SmartServer IoT's Ethernet ports are eth0 and eth1, the two RS-485 serial ports are /dev/ttymxc2 and /dev/ttymxc4, and the four USB ports are /media/usb0-3.

SmartServer IoT RS-485 Port Settings

To use one of the RS-485 serial ports, you must set the bus type to Custom, which causes the remaining communication parameters for the port to be ignored. As a result, your custom RS-485 driver needs to implement the code to set the communication parameters for the port, and configure the port to operate in RS-485 mode.  See Sample Code for a Custom RS-485 Driver, below.

Sample Code for a Custom RS-485 Driver

The custom RS-485 driver needs to include code to configure the port for RS-485 use, and also set the communications parameters for the port.   The following example is written in C, but a nodeJS driver would need to do the same thing.

struct serial_rs485 rs485conf;

// Set up the port for RS485 mode, RTS to xmit etc.

memset(&rs485conf, 0, sizeof(rs485conf)); // Make sure all other RS485 port parameters are cleared
rs485conf.flags |= SER_RS485_ENABLED; // Enable RS485 mode
rs485conf.flags |= SER_RS485_RTS_ON_SEND; // Set logic level for RTS to 1 when sending
rs485conf.flags &= ~SER_RS485_RTS_AFTER_SEND; // Set logic level for RTS to 0 after sending
rs485conf.flags &= ~SER_RS485_RX_DURING_TX; // Enable receiving data while sending
if (ioctl (fd, TIOCSRS485, &rs485conf) < 0) { // Set up the port this way
// handle any errors

The serial port parameters either need to be set via code in the driver, the conf file listed above needs to be edited (JSON), or else something like stty needs to be used in the console to set this up manually.

struct termios SerialPortSettings; /* Create the structure */

// Set up the port attributes (baud rate, parity etc. 19,200 N81)

tcgetattr(g_fd, &SerialPortSettings); /* Get the current attributes of the Serial port */
cfsetispeed(&SerialPortSettings,B19200); /* Set Read Speed as 19200 */
cfsetospeed(&SerialPortSettings,B19200); /* Set Write Speed as 19200 */

SerialPortSettings.c_cflag &= ~PARENB; /* Disables the Parity Enable bit(PARENB),So No Parity */
SerialPortSettings.c_cflag &= ~CSTOPB; /* CSTOPB = 2 Stop bits,here it is cleared so 1 Stop bit */
SerialPortSettings.c_cflag &= ~CSIZE; /* Clears the mask for setting the data size */
SerialPortSettings.c_cflag |= CS8; /* Set the data bits = 8 */

SerialPortSettings.c_cflag &= ~CRTSCTS; /* No Hardware flow Control */
SerialPortSettings.c_cflag |= CREAD | CLOCAL; /* Enable receiver,Ignore Modem Control lines */

SerialPortSettings.c_oflag &= ~(ONLCR);
SerialPortSettings.c_iflag &= ~(IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR | IGNCR | ICRNL | IXON | IXOFF | IXANY);

SerialPortSettings.c_iflag &= ~(ICANON | ECHO | ECHOE | ISIG); /* Non Cannonical mode */

SerialPortSettings.c_oflag &= ~OPOST;/*No Output Processing*/

if((tcsetattr(g_fd,TCSANOW,&SerialPortSettings)) != 0) { /* Set the attributes to the termios structure*/
// Handle any errors
else {
printf("\n BaudRate = 19200 \n StopBits = 1 \n Parity = none");

  • No labels