Multi-Tech Systems 92U12616852 ユーザーズマニュアル

ページ / 76
USING LINUX WITH H5 DEVICES
Example
Close the ttyACMx file.
if(close(fd) < 0)
{
/* Error Management Routine */
} else {
/* File Closed */
}
Test Program()
The following simple C program is useful to test the modem issuing an AT command. The program opens the
/dev/ttyACM0 interface and calls the write() and the read() function to send an AT command and receive the
subsequent output.
#include <stdio.h> /* Standard input/output definitions */
#include <string.h> /* String function definitions */
#include <unistd.h> /* UNIX standard function definitions */
#include <fcntl.h> /* File control definitions */
#include <errno.h> /* Error number definitions */
#include <termios.h> /* POSIX terminal control definitions */
#define USB "/dev/ttyACM0"
#define BUFSIZE 1000
#define BAUDRATE B115200
int open_port(char *port)
{
struct termios options;
int fd;
fd = open(port, O_RDWR | O_NOCTTY | O_NDELAY);
if (fd == -1)
{
printf("open_port: Unable to open the port - ");
}
else
{
printf ( "Port %s with file descriptor=%i",port, fd);
fcntl(fd, F_SETFL, FNDELAY);
tcgetattr( fd, &options );
cfsetispeed( &options, BAUDRATE );
cfsetospeed( &options, BAUDRATE );
options.c_cflag |= ( CLOCAL | CREAD);
options.c_cflag &= ~(CSIZE | PARENB | CSTOPB | CSIZE);
options.c_cflag |= CS8;
options.c_cflag &= ~CRTSCTS;
options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);
options.c_iflag &= ~(IXON | IXOFF | IXANY | ICRNL | INLCR |
IGNCR);
options.c_oflag &= ~OPOST;
if ( tcsetattr( fd, TCSANOW, &options ) == -1 )
printf ("Error with tcsetattr = %s\n", strerror ( errno )
);
MultiConnect
TM
PCIe MTPCIE-H5/MTPCIE-BW Developer Guide
73