/********************************************************************************* * Copyright: (C) 2018 LingYun IoT System Studio * All rights reserved. * * Filename: comport.h * Description: This head file is for the common TTY/Serial port operator library * * Version: 1.0.0(10/17/2018~) * Author: Guo Wenxue * ChangeLog: 1, Release initial version on "10/17/2018 03:33:25 PM" * ********************************************************************************/ #ifndef __COMPORT_H_ #define __COMPORT_H_ #include #include #include #include #include #include #include #include #include #include #include #include #include #ifndef DEVNAME_LEN #define DEVNAME_LEN 32 #endif //#define COM_DEBUG #ifdef COM_DEBUG #define COM_PRINT(format,args...) printf(format, ##args) #else #define COM_PRINT(format,args...) do{} while(0); #endif typedef struct comport_s { char devname[DEVNAME_LEN]; unsigned char databit, parity, stopbit, flowctrl; long baudrate; int fd; int frag_size; } comport_t; /* * description: Open the comport specified by $comport * * input args: $comport: corresponding comport point * $devname: The comport device name path, such as '/dev/ttyS3' * $baudrate: The baudrate, such as 115200 * $settings: The databit,parity,stopbit,flowctrl settings, such as '8N1N' * * return value: The comport opened file description, <0 means failure */ extern int comport_open(comport_t *comport, const char *devname, long baudrate, const char *settings); /* * description: close comport * input args: $comport: corresponding comport point */ extern void comport_close(comport_t *comport); /* * description: write $send_bytes bytes data from $buf to $comport * return value: 0: write ok <0: write failure */ extern int comport_send(comport_t *comport, char *buf, int send_bytes); /* * description: read data from $comport in $timeout to $buf no more than $bufsize bytes * return value: the actual read data bytes, <0: read failure */ extern int comport_recv(comport_t *comport, char *buf, int bufsize, unsigned long timeout); #endif