User`s manual
UC-8410/8416/8418 LX User’s Manual Programmer’s Guide
5-14
Setinterface
The Serial Port Expansion Module has 8 serial ports, labeled ttyM0 to ttyM7. The ports support
RS-232, RS-422, and RS-485 2-wire and 4-wire operation modes with baudrate settings up to
921600 bps.
The default operation mode is set to RS-232. You can use the setinterface command to change the
serial port operation mode.
Usage: setinterface device-node [interface-no]
device-node -- /dev/ttyMn; n = 0,1,2,...
interface-no -- As shown in the following table:
interface-no Operation Mode
None Display current setting
0 RS-232
1 RS-485 2-wire
2 RS-422
3 RS-485 4-wire
The following example sets /dev/ttyM0 to RS-422 mode
Example for setting the baudrate
#include <moxadevice.h>
#include <termios.h>
struct termios term;
int fd, speed;
fd = open(“/dev/ttyM0”, O_RDWR);
tcgetattr(fd, &term);
term.c_cflag &= ~(CBAUD | CBAUDEX);
term.c_cflag |= B4000000;
tcsetattr(fd, TCSANOW, &term);
speed = 500000;
ioctl(fd, MOXA_SET_SPECIAL_BAUD_RATE, &speed);
Example for getting the baudrate
#include <moxadevice.h>
#include <termios.h>
struct termios term;
int fd, speed;
fd = open(“/dev/ttyM0”, O_RDWR);
tcgetattr(fd, &term);
if ( (term.c_cflag & (CBAUD|CBAUDEX)) != B4000000 )
{// follow the standard termios baud rate define} else
{ioctl(fd, MOXA_GET_SPECIAL_BAUD_RATE, &speed);}
root@Moxa:/# setinterface /dev/ttyM0 2
root@Moxa:~# setinterface /dev/ttyM0
Now setting is RS422 interface.
root@Moxa:~#