Moxa W406-T-LX [66/74] C library

Moxa W325A-LX [66/74] C library
W315A/325A Linux User's Manual Programmer's Guide
6-7
#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 error
Divisor = 921600/Target Baud Rate. (Only Integer part)
ENUM = 8 * (921600/Targer - Divisor) ( Round up or down)
Inaccuracy = (Target Baud Rate – 921600/(Divisor + (ENUM/8))) * 100%
E.g., to calculate 500000 bps:
Divisor = 1, ENUM = 7,
Error = 1.7%
(The error should be less than 2% for reliable data transmission.)
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.
C Library
GPRS/SIM/SMS
The definition header file includes the entire API library, located at “/usr/local/arm-linux/include/libsms”.
unsigned int cellular_modem_open(void);
Description: Opens a cellular modem handle for later use.
Arguments: None
Return Value: Pointer to a cellular modem handle. Returns 0 on failure.
Remarks: Every cellular modem API needs the cellular modem handle parameter, so you must use this
function first in your APIs.

Содержание

Скачать