User`s manual

UC-7408 User’s Manual Programmer’s Guide
5-11
Example to get the baud rate
#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);
}
Baud rate 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%
*The Inaccuracy should less than 2% for work reliably.
Special Note
1. If the target baud rate 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.
Digital I/O
Digital Output channels can be set to high or low. The channels are controlled by the function call
set_dout_state( ). The Digital Input channels can be used to detect the state change of the digital
input signal. The DI channels can also be used to detect whether or not the state of a digital signal
changes during a fixed period of time. This can be done by the function call, set_din_event ( ).
Moxa provides 5 function calls to handle the digital I/O state change and event handling.
Application Programming Interface
Return error code definitions:
#define DIO_ERROR_PORT -1
// no such port
#define DIO_ERROR_MODE -2
// no such mode or state
#define DIO_ERROR_CONTROL -3
// open or ioctl fail
#define DIO_ERROR_DURATION -4
// The value of duration is not 0 or not in the range,
40 <= duration <= 3600000 milliseconds (1 hour)
#define DIO_ERROR_DURATION_20MS -5
// The value of duration must be a multiple of 20 ms
#define DIO_OK 0