?? serial_connect.h
字號:
#ifndef __SERIAL_CONNECT__#define __SERIAL_CONNECT__#include "../../types/types.h"#define BYTETIMEOUT 10 // tenths of seconds#ifndef SUCCESS#define SUCCESS 1#endif#ifndef FAILURE#define FAILURE 0#endif#define SERIAL_PORT_CLOSED -1/************************************************************************ * RULES: * 1. You must call closeSerialPort with only the file descriptor * returned by openSerialPort. * 2. If you call openSerialPort twice without calling closeSerialPort, * you will get the same, already open, serial port desciptor back * (i.e. it will not open two streams to the same port) * even if you pass the function a new pathname. In other words, * there is a global flag that is set/reset by openSerialPort * and closeSerialPort that does not keep track of the pathname. * NOTE: this may be modified in the future * 3. If you try to call closeSerialPort with anything other than * the open serial port file descriptor as a parameter, then * it will instantly return failure. * 4. Examples of how to read/write from/to the serial port are * listed at the end of this file. ************************************************************************/// returns a useable file descriptor on success, -1 on errorint openSerialPort(char *serial_port_filepath);// returns SUCCESS on success, FAILURE on failureint closeSerialPort(int serial_port_file_descriptor);// flushes everything from input and output buffersint flushInputPort(int serial_port_file_descriptor);int flushOutputPort(int serial_port_file_descriptor);/******************************************************************************* * HOW TO USE SERIAL_CONNECT: * * 1. First, get a file descriptor: * * fd = openSerialPort(); * * 2. To write to the serial port: * * ret_val = write(fd, "ATZ\r", num_bytes_to_write); * if (ret_val < 0) { * fprintf(stderr, "write() of %d bytes failed!\n", num_bytes_to_write); * } * * 3. To read from serial port: * num_bytes_read = read(fd, &buffer, num_bytes_to_read); * if (num_bytes_read != num_bytes_to_read) { * fprintf(stderr, "read() of %d bytes failed!\n", num_bytes_to_read); * } * NOTE: for mica2 motes, always read only one byte at a time *******************************************************************************/#endif
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -