Moxa V2416-T-XPE [57/88] Example to set the baudrate

Moxa V2416-W7E [57/88] Example to set the baudrate
V2416 Linux User's Manual Programming Guide
4-3
Example to set the baudrate
#include “moxadevice.h”
#include <termios.h>
struct termios term;
int fd, speed;
fd = open(“/dev/ttyS0”, 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 to get the baudrate
#include “moxadevice.h”
#include <termios.h>
struct termios term;
int fd, speed;
fd = open(“/dev/ttyS0”, 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: To work reliably, the inaccuracy should be less than 2%.
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.
2. If you use stty to get the serial information, you will get speed equal to 0 for the special baudrate.

Содержание

Похожие устройства

Скачать