/***************************************************************************************************
 * File name:PortIO.m
 * Function:To realize connect and communicate to WIFI
 * Version:V1.0 Time:2013.08 Record:Encoding and debugging for the first time
 ***************************************************************************************************///

#import <Foundation/Foundation.h>
#import "ErrorCode.h"


//typedef     char		SInt8;
//typedef unsigned char	UInt8;
//typedef         short	UInt16;
//typedef unsigned short	uint16;
//typedef         int		SInt32;
//typedef unsigned int	UInt32;

@interface PortIO : NSObject
{
	SInt32	ConnectSuccessFlag;
}
@property (nonatomic, readwrite) SInt32	ConnectSuccessFlag;

- (NSMutableArray*)searchPort;

/***************************************************************************************************
 * function:Create connection software and printer according to IP address
 * Param list: DeviceName:	[in] IP address of printer
 *             TimeOut:		[in] the timeout of creating connection(ms)
 * return：Procrssing was success -- SUCCESS
 *         Could not execute process -- ERR_PROCESSING
 **************************************************************************************************/
- (SInt32)openPort:(NSString*)DeviceName TimeOut:(SInt32)TimeOut;

/***************************************************************************************************
 * function:Close port
 * Param list: none
 * return：Procrssing was success -- SUCCESS
 *         Could not execute process -- ERR_PROCESSING
 **************************************************************************************************/
- (SInt32)closePort;

/***************************************************************************************************
 * function:Write data to port
 * Param list: WriteBuffer:	[in] The sending data buffer.It stores data to be sent
 *             OffsetSize:	[in] Specify the offset value from the top of WriteBuffer
 *             WriteSize:	[in] the number of bytes that would be sent
 *             WriteTimeOut:[in] the timeout of writing data (ms)
 the number of bytes be wrote-- Positive value
 *          fail -- Negative value
 **************************************************************************************************/
- (SInt32)writePort:(const UInt8*)WriteBuffer OffsetSize:(SInt32)OffsetSize WriteSize:(SInt32)WriteSize WriteTimeOut:(SInt32)WriteTimeOut;

/***************************************************************************************************
 * function:Write data to port
 * Param list: WriteBuffer:	[in] The sending data buffer.It stores data to be sent
 *             OffsetSize:	[in] Specify the offset value from the top of WriteBuffer
 *             WriteSize:	[in] the number of bytes that would be sent
 *             WriteTimeOut:[in] the timeout of writing data (ms)
 *             PortID:      [in] the ID of port
 * return：the number of bytes wrote-- Positive value
 *          fail -- Negative value
 **************************************************************************************************/
- (SInt32)writePort:(const UInt8*)WriteBuffer OffsetSize:(SInt32)OffsetSize WriteSize:(SInt32)WriteSize WriteTimeOut:(SInt32)WriteTimeOut PortID:(SInt32)PortID;

/***************************************************************************************************
 * function:Read data from port
 * Param list: ReadBuffer:	[in] The receiving data buffer for storing received data. 
 *             OffsetSize:	[in] Specify the offset value from the top of ReadBuffer.
 *             ReadSize:	[in] the number of bytes which would be received
 *             ReadTimeOut: [in] the timeout of receiving data (ms)
 * return： the number of bytes read-- Positive value
 *          fail -- Negative value
 **************************************************************************************************/
- (SInt32)readPort:(UInt8*)ReadBuffer OffsetSize:(SInt32)OffsetSize ReadSize:(SInt32)ReadSize ReadTimeOut:(SInt32)ReadTimeOut;

/***************************************************************************************************
 * function:Read data from port
 * Param list: ReadBuffer:	[in] The receiving data buffer for storing received data.
 *             OffsetSize:	[in] Specify the offset value from the top of ReadBuffer.
 *             WriteSize:	[in] the number of bytes which would be read
 *             WriteTimeOut:[in] the timeout of receiving data (ms)
 *             PortID:      [in] the ID of port
 * return： the number of bytes read-- Positive value
 *          fail -- Negative value
 **************************************************************************************************/
- (SInt32)readPort:(UInt8*)ReadBuffer OffsetSize:(SInt32)OffsetSize ReadSize:(SInt32)ReadSize ReadTimeOut:(SInt32)ReadTimeOut PortID:(SInt32)PortID;

/***************************************************************************************************
 * function:Record communication data
 * Param list: recordFileName:	[in] the file name recorded
 * return： the number of bytes read-- Positive value
 *          fail -- Negative value
 **************************************************************************************************/
- (SInt32)recordCommunicationDataEnable:(NSString*)recordFileName;

/***************************************************************************************************
 * function:Record communication data
 * Param list: Data:	[in] the communication data would be record 
 *             Length:	[in] the length of communication data
 * return： the number of bytes read-- Positive value
 *          fail -- Negative value
 **************************************************************************************************/
- (SInt32)recordCommunicationData:(NSString*)msg Data:(const UInt8*)Data Length:(SInt32)Length;

@end

