//
// MySerialport.h
#import <IOKit/IOTypes.h>
#import <Foundation/Foundation.h>
#include <stdio.h> /*标准输入输出定义*/
#include <stdlib.h> /*标准函数库定义*/
#include <unistd.h> /*Unix 标准函数定义*/
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h> /*文件控制定义*/
#include <termios.h> /*PPSIX 终端控制定义*/
#include <errno.h> /*错误号定义*/
//struct termios serialOption;
typedef NS_ENUM(NSUInteger, ORSSerialPortParity) {
ORSSerialPortParityNone = 0,
ORSSerialPortParityOdd,
ORSSerialPortParityEven
};
@protocol ORSSerialPortDelegate;
@interface MySerialport : NSObject
{
struct termios serialOption;
}
//@property (retain) NSString *recevString;
@property int fileDesc;
@property (retain) NSString *recevStr;
@property NSMutableString *allRece;
@property (nonatomic, copy) NSNumber *baudRate;
@property (nonatomic, readwrite) BOOL CTS;
@property (nonatomic, readwrite) BOOL DSR;
@property (nonatomic, readwrite) BOOL DCD;
#if OS_OBJECT_USE_OBJC
@property (nonatomic, strong) dispatch_source_t pinPollTimer;
@property (nonatomic, strong) dispatch_source_t pendingRequestTimeoutTimer;
@property (nonatomic, strong) dispatch_queue_t requestHandlingQueue;
@property (nonatomic, strong) dispatch_semaphore_t selectSemaphore;
#else
@property (nonatomic) dispatch_source_t pinPollTimer;
@property (nonatomic) dispatch_source_t pendingRequestTimeoutTimer;
@property (nonatomic) dispatch_queue_t requestHandlingQueue;
@property (nonatomic) dispatch_semaphore_t selectSemaphore;
#endif
/**
* The number of stop bits. Values other than 1 or 2 are invalid.
*/
@property (nonatomic) NSUInteger numberOfStopBits;
@property (nonatomic) ORSSerialPortParity parity;
/**
* A Boolean value indicating whether the serial port uses RTS/CTS Flow Control.
*/
@property (nonatomic) BOOL usesRTSCTSFlowControl;
/**
* A Boolean value indicating whether the serial port uses DTR/DSR Flow Control.
*/
@property (nonatomic) BOOL usesDTRDSRFlowControl;
/**
* A Boolean value indicating whether the serial port uses DCD Flow Control.
*/
@property (nonatomic) BOOL usesDCDOutputFlowControl;
/** ---------------------------------------------------------------------------------------
* @name Other Port Pins
* ---------------------------------------------------------------------------------------
*/
/**
* The state of the serial port's RTS pin.
*
* - YES means 1 or high state.
* - NO means 0 or low state.
*
* This property is observable using Key Value Observing.
*/
@property (nonatomic) BOOL RTS;
/**
* The state of the serial port's DTR pin.
*
* - YES means 1 or high state.
* - NO means 0 or low state.
*
* This property is observable using Key Value Observing.
*/
@property (nonatomic) BOOL DTR;
/**
* The state of the serial port's CTS pin.
*
* - YES means 1 or high state.
* - NO means 0 or low state.
*
* This property is observable using Key Value Observing.
*/
/**
* The state of the serial port's DSR pin. (read-only)
*
* - YES means 1 or high state.
* - NO means 0 or low state.
*
* This property is observable using Key Value Observing.
*/
/**
* The state of the serial port's DCD pin. (read-only)
*
* - YES means 1 or high state.
* - NO means 0 or low state.
*
* This property is observable using Key Value Observing.
*/
@property (nonatomic) BOOL shouldEchoReceivedData;
#if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_8
@property (nonatomic, weak) id<ORSSerialPortDelegate> delegate;
#else
@property (nonatomic, unsafe_unretained) id<ORSSerialPortDelegate> delegate;
#endif
-(void)openSerialport:(NSString *)dev;
-(void)setPortOptions;
-(BOOL)SendtoSerialPOrt:(NSString *)cmd;
-(void)close;
- (BOOL)isOpen;
- (void)receiveData:(NSString *)data;
@end
@protocol ORSSerialPortDelegate <NSObject>
@optional
/**
* Called any time new data is received by the serial port from an external source.
*
* @param serialPort The `ORSSerialPort` instance representing the port that received `data`.
* @param data An `NSData` instance containing the data received.
*/
//- (void)didReceiveData:(NSString *)data;
- (void)didReceiveData:(NSString *)data;
@end