Moxa V2401-CE [66/108] Example to get the baudrate

Moxa V2401-CE [66/108] Example to get the baudrate
V2401/2402 Series Linux User’s Manual Programmer Guide
4-3
3. Function: MOXA_GET_OP_MODE
int ioctl(fd, MOXA_GET_OP_MODE, &mode)
Description Get the interface mode. Argument 3 mode will return the interface mode.
There are two Moxa private ioctl control definitions for setting up special baudrates.
MOXA_SET_SPECIAL_BAUD_RATE
MOXA_GET_SPECIAL_BAUD_RATE
If you use this ioctl to set a special baudrate, the termios cflag will be B4000000, in which case
the B4000000 define will be different. If the baudrate you get from termios (or from calling
tcgetattr()) is B4000000, you must call ioctl with MOXA_GET_SPECIAL_BAUD_RATE to
get the actual baudrate.
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);
}

Содержание

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

Скачать