Moxa UC-8416-T-LX [66/90] Baudrate inaccuracy

Moxa UC-8418-LX [66/90] Baudrate inaccuracy
UC-8410/8416/8418/8430 Programmer's Guide
5-14
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);}
Baudrate inaccuracy
Divisor = 921600/Target Baud Rate. (Only Integer part)
ENUM = 8 * (921600/Target - Divisor) ( Round up or down)
Inaccuracy = (Target Baud Rate 921600/(Divisor + (ENUM/8))) / Target Baud Rate * 100%
E.g.,
To calculate 500000 bps
Divisor = 1, ENUM = 7,
Inaccuracy = 1.7%
NOTE: The Inaccuracy should less than 2% for the device to work reliably.
Special Note
1. If the target baudrate is not a special baudrate (e.g., 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800,
2400, 4800, 9600, 19200, 38400, 57600, 115200, 230400, 460800, 921600), the termios cflag will be set
to the same flag.
root@Moxa:/# setinterface /dev/ttyM0 2
root@Moxa:~# setinterface /dev/ttyM0
Now setting is RS422 interface.
root@Moxa:~#

Содержание

Скачать