Moxa Technologies UC-7420/7410 Example to set the baud rate, Example to get the baud rate

Models: UC-7420/7410

1 106
Download 106 pages 2.64 Kb
Page 85
Image 85

UC-7420/7410 User’s Manual

Programmer’s Guide

UART

The normal tty device node is located at /dev/ttyM0 … ttyM7, and the modem tty device node is located at /dev/cum0 … cum7.

UC-7420/7410 supports Linux standard termios control. The Moxa UART Device API allows you to configure ttyM0 to ttyM7 as RS-232, RS-422, 4-wire RS-485, or 2-wire RS-485. UC-7420/7410 supports RS-232, RS-422, 2-wire RS-485, and 4-wire RS485.

You must include <moxadevice.h>.

#define RS232_MODE

0

1

#define RS485_2WIRE_MODE

#define

RS422_MODE

2

3

#define

RS485_4WIRE_MODE

1.Function: MOXA_SET_OP_MODE

int ioctl(fd, MOXA_SET_OP_MODE, &mode)

Description

Set the interface mode. Argument 3 mode will pass to the UART device driver and change it.

2.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 commands for setting up special baud rates.

Function: MOXA_SET_SPECIAL_BAUD_RATE

Function: MOXA_GET_SPECIAL_BAUD_RATE

If you use this ioctl to set a special baud rate, the termios cflag will be B4000000, in which case the B4000000 define will be different. If the baud rate you get from termios (or from calling tcgetattr()) is B4000000, you must call ioctl with MOXA_GET_SPECIAL_BAUD_RATE to get the actual baud rate.

Example to set the baud rate

#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 to get the baud rate

#include

<moxadevice.h>

#include

<termios.h>

struct termiosterm;

int

fd, speed;

fd = open(“/dev/ttyM0”, O_RDWR); tcgetattr(fd, &term);

if ( (term.c_cflag & (CBAUDCBAUDEX)) != B4000000 ) {

//follow the standard termios baud rate define

}else {

ioctl(fd, MOXA_GET_SPECIAL_BAUD_RATE, &speed);

}

5-9

Page 85
Image 85
Moxa Technologies UC-7420/7410 user manual Example to set the baud rate, Example to get the baud rate