/*  Copyright (C) MOXA Inc. All rights reserved.

    This software is distributed under the terms of the
    MOXA License.  See the file COPYING-MOXA for details.
*/



/*
	Initialize Uart
	
	param:
		port  :	 port number	
				
	Return value:
		unsigned int :			return UART handle
*/
unsigned int mxsp_open(int port);

/*
	Get UART Mode
	
	param:
		(in)int index :	Port index (0,1)		
				
	Return value:
		int:		0 : RS232 Mode
					1 : RS485-2W Mode
					2 : RS422 Mode
					3 : RS485-4W Mode
*/
int mxsp_get_interface(unsigned int fd);

/*
	Set UART Mode
	
	param:
		(in)int index  :	Port index		
		(in)int mode   :	Port mode		
				
	Return value:
		int:			Current Mode. 
*/
int mxsp_set_interface(unsigned int fd,int mode);

/*
	close UART	
	param:
		(in)unsigned int fd  :	Handle of the open port		
				
	Return value:
		none
*/
void mxsp_close(unsigned fd);


/*
	sets the communication baudrate of a serial port	
	param:
		(in)unsigned int fd  :	Handle of the open port		
		(in)int  baudrate	: Specified baudrate.
				
	Return value:
		When successful, this function returns 0. If it does not return 0, you can consider it to be unsuccessful.
*/
int mxsp_set_baudrate (unsigned int fd, int baudrate);


/*
	gets the communication baudrate of a serial port	
	param:
		(in)unsigned int fd  :	Handle of the open port		
						
	Return value:
		When successful, this function returns a positive value. This function returns a negative value when an error
occurs.
*/
int mxsp_get_baudrate(unsigned int fd);


/*
	This function sets the number of data bits for communication through a serial port.	
	param:
		(in)unsigned int fd  :	Handle of the open port	
		(in)int bits	: data bits (5, 6, 7, or 8)
						
	Return value:
		When successful, this function returns 0.
*/
int mxsp_set_databits(unsigned int fd, int bits);

/*
	This function gets the number of data bits for communication through a serial port.	
	param:
		(in)unsigned int fd  :	Handle of the open port	
								
	Return value:
		When successful, this function returns the number of bits (5, 6, 7, or 8).
*/
int mxsp_get_databits(unsigned int fd);


/*
	This function sets the number of stop bits for communication through a serial port.	
	param:
		(in)unsigned int fd  :	Handle of the open port	
		(in)int bits	:	stop bits; 1, 2, or 3 (for 1.5)
								
	Return value:
		When successful, this function returns 0.
*/
int mxsp_set_stopbits(unsigned int fd, int bits);

/*
	This function gets the number of stop bits for communication through a serial port.	
	param:
		(in)unsigned int fd  :	Handle of the open port	
										
	Return value:
		When successful, this function returns the number of stop bits (1, 2, or 3).
*/
int mxsp_get_stopbits(unsigned int fd);

/*
	This function sets the parity of a serial port.	
	param:
		(in)unsigned int fd  :	Handle of the open port	
		(in) int parity	:	0: none, 1: odd, 2: even, 3: space, 4: mark, otherwise: none
										
	Return value:
		When successful, this function returns 0.
*/
int mxsp_set_parity(unsigned int fd, int parity);

/*
	This function gets the parity of a serial port.	
	param:
		(in)unsigned int fd  :	Handle of the open port	
											
	Return value:
		When successful, this function returns the parity of the open port (0, 1, 2, 3, or 4).
*/
int mxsp_get_parity(unsigned int fd);

/*
	This function sets the type of flow control for a serial port.	
	param:
		(in)unsigned int fd  :	Handle of the open port	
		(in)int mode	:	1: software, 2: hardware, otherwise: none
											
	Return value:
		When successful, this function returns 0.
*/
int mxsp_set_flow_control(unsigned int fd, int mode);

/*
	This function gets the type of flow control of a serial port.	
	param:
		(in)unsigned int fd  :	Handle of the open port	
													
	Return value:
		When successful, this function returns the type of flow control being used by that port. The function returns a
negative value when an error occurs.
*/
int mxsp_get_flow_control(unsigned int fd);

/*
	Initialize Expansion Digitial I/O module
	
	param:
		<index> module index (0,1).			
				
	Return value:
		HANDLE:			return digital I/O handle
*/
HANDLE mxdgio_epm3438_open(int index);


/*
	Clear Expansion Digitial I/O module's counter value
	
	param:
		None			
				
	Return value:
		int:			0 indicates success, -1 indicates failure.
*/
int mxdgio_epm3438_clear_counter(HANDLE fd);

/*
	Get Expansion Digitial I/O module's counter value
	
	param:
		(in)HANDLE fd  :	Handle of digital I/O			
				
	Return value:
		int:			0 indicates success, -1 indicates failure.
*/
int mxdgio_epm3438_get_counter(HANDLE fd);

/*
	Initialize Digitial I/O
	
	param:
		(in)HANDLE fd  :	Handle of digital I/O	
				
	Return value:
		HANDLE:			return digital I/O handle
*/

HANDLE mxdgio_open();

/*
	get digital input
	
	param:
		(in)HANDLE hDIO  :	Handle of digital I/O		
				
	Return value:
		int:			return digital input data 
*/
int mxdgio_get_input_signal(HANDLE fd, int port);

/*
	set digital output
	
	param:
		(in)HANDLE fd  :	Handle of digital I/O		
		(in)int port	 :	index of digital output bit		
	
	Return value:
		BOOL:			TRUE indicates success, FALSE indicates failure.
*/
int mxdgio_set_output_signal_high(HANDLE fd, unsigned int port);

/*
	set digital output
	
	param:
		(in)HANDLE fd  :	Handle of digital I/O		
		(in)int port	 :	index of digital output bit		
		
	Return value:
		BOOL:			TRUE indicates success, FALSE indicates failure.
*/
int mxdgio_set_output_signal_low(HANDLE fd, unsigned int port);

/*
	get digital output
	
	param:
		(in)HANDLE hDIO  :	Handle of digital I/O		
		(in)int port	 :	index of digital output			
	Return value:
		int:			return digital output data 
*/
int mxdgio_get_output_signal(HANDLE fd, int port);

/*
	close digital I/O
	
	param:
		(in)HANDLE hDIO  :	Handle of digital I/O		
				
	Return value:
		BOOL:			TRUE indicates success, FALSE indicates failure. 
*/
void mxdgio_close(HANDLE fd);

