⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 msz_rab.lib

📁 modbus 运用事例
💻 LIB
📖 第 1 页 / 共 3 页
字号:
	return( serDgetc() );
}


int msXread(void *data, int length, unsigned long tmout)
{
	return( serDread(data, length, tmout) );
}

nodebug
int msSend(char *pcMess, unsigned wLen)
{
	int done;
	msDtx();	
	done = serDwrite(pcMess, wLen);
	msDrx();
	return done;
}

/* START FUNCTION DESCRIPTION *****************************************
msrDinit                         <MSZ_RAB.LIB>

NOTE: MSZ_RAB.LIB functions are generally not reentrant.

SYNTAX: int msrDinit(unsigned wAddr, unsigned long qBaud)

DESCRIPTION: Initialize serial port D as a Modbus RTU Slave.

PARAMETER1: slave address.
PARAMETER2: baud rate (bits per second).

RETURN VALUE: 1 if successful, 0 if unsupported baud rate.
END DESCRIPTION ******************************************************/
nodebug
int msrDinit(unsigned wAddr, unsigned qBaud)
{
	msrInit(wAddr, 1 + 35000u/qBaud);
	return msDinit(qBaud);
}

/*** BeginHeader */
#if ( _CPU_ID_ >= R3000 )
/*** EndHeader */

/*** BeginHeader msrEinit */
int msrEinit(unsigned, unsigned);
/*** EndHeader */

int msXgetc()
{
	return( serEgetc() );
}


int msXread(void *data, int length, unsigned long tmout)
{
	return( serEread(data, length, tmout) );
}

nodebug
int msSend(char *pcMess, unsigned wLen)
{
	int done;
	msEtx();	
	done = serEwrite(pcMess, wLen);
	msErx();
	return done;
}

/* START FUNCTION DESCRIPTION *****************************************
msrEinit                         <MSZ_RAB.LIB>

NOTE: MSZ_RAB.LIB functions are generally not reentrant.

SYNTAX: int msrEinit(unsigned wAddr, unsigned long qBaud)

DESCRIPTION: Initialize serial port E as a Modbus RTU Slave.
				 (for Rabbit 3000 or higher CPU's)

PARAMETER1: slave address.
PARAMETER2: baud rate (bits per second).

RETURN VALUE: 1 if successful, 0 if unsupported baud rate.
END DESCRIPTION ******************************************************/
nodebug
int msrEinit(unsigned wAddr, unsigned qBaud)
{
	msrInit(wAddr, 1 + 35000u/qBaud);
	return msEinit(qBaud);
}

/*** BeginHeader msrFinit */
int msrFinit(unsigned, unsigned);
/*** EndHeader */

int msXgetc()
{
	return( serFgetc() );
}


int msXread(void *data, int length, unsigned long tmout)
{
	return( serFread(data, length, tmout) );
}

nodebug
int msSend(char *pcMess, unsigned wLen)
{
	int done;
	msFtx();	
	done = serFwrite(pcMess, wLen);
	msFrx();
	return done;
}

/* START FUNCTION DESCRIPTION *****************************************
msrFinit                         <MSZ_RAB.LIB>

NOTE: MSZ_RAB.LIB functions are generally not reentrant.

SYNTAX: int   msrFinit (unsigned wAddr, unsigned long qBaud)

DESCRIPTION: Initialize serial port F as a Modbus RTU Slave.
					(for Rabbit 3000 or higher CPU's)          

PARAMETER1: slave address.
PARAMETER2: baud rate (bits per second).

RETURN VALUE: 1 if successful, 0 if unsupported baud rate.
END DESCRIPTION ******************************************************/
nodebug
int msrFinit(unsigned wAddr, unsigned qBaud)
{
	msrInit(wAddr, 1 + 35000u/qBaud);
	return msFinit(qBaud);
}

/*** BeginHeader */
#endif 	// #if (_CPU_ID_ >= R3000) 
/*** EndHeader */


/* START FUNCTION DESCRIPTION *****************************************
msAinit                         <MSZ_RAB.LIB>

NOTE: MSZ_RAB.LIB functions are generally not reentrant.

SYNTAX: 	int msAinit(unsigned qBaud)

DESCRIPTION: User function for
				 Initializing serial port A as a Modbus ASCII Slave.
				 
				 This function must reside in your application code.
				 Typical code for this function would be the following;
				 
int msAinit(unsigned qBaud)        
{
	// Open the serial port.  THIS MUST BE DONE PRIOR TO SETTING THE
	// DATA BITS AND PARITY SETTINGS.
	
	serAopen(qBaud); 
	  
	// setup parity.  Either PARAM_OPARITY, PARAM_EPARITY, PARAM_NOPARITY, 
	// or PARAM_2STOP  
	
	serAparity(PARAM_EPARITY);
	 
	// setup data bits. Either PARAM_7BIT, or PARAM_8BIT 
	 
	serAdatabits(PARAM_8BIT);
	
  	// Set the Serial port mode. Used for Zworld SBC's only.  
  	
	serMode(0);  
	
	return(1);
}
				 

PARAMETER1: slave address.
PARAMETER2: baud rate (bits per second).

RETURN VALUE: 1 if successful, 0 if unsupported baud rate.
END DESCRIPTION ******************************************************/


/* START FUNCTION DESCRIPTION *****************************************
msArx                         <MSZ_RAB.LIB>

NOTE: MSZ_RAB.LIB functions are generally not reentrant.

SYNTAX: 			void	msArx  (void)

DESCRIPTION: 	User defineable function for disabling the rs485
					transmitter.  This function is needed in your application
					code.  If you are doing RS232, you need only to have
					an empty function like
					
					void msArx(void)
					{
					}
					
					For rs485 control, you can do the following;

EXAMPLE:	  void msArx(void)
			  {
			    // Ensure that all the data has bent sent.
			    
			    while (serAwrUsed() || \
			    		  BitRdPortI(SASR,2) || \
			    		  BitRdPortI(SASR,3)); 
				
				// Turn off the RS485 transmitter by doing the following;
				
				//	PORT:				The parrallel port (PADR,PBDR,PCDR etc)          
				// PORTShadow: 	The Shadow register of the port
				//	OFF_VALUE:		1 or 0
				//	PORT_BIT:		parrallel port bit (0-7)
				
					BitWrPortI(PORT,&PORTShadow, OFF_VALUE, PORT_BIT);
					
				//  If your product is a Zworld SBC, you can do the following
				
					ser485Rx();
					
				//  Flush out the serial port read buffer, so you are ready for
				//  the next packet.
					
					serArdFlush();	 
			  }			

RETURN VALUE: none
END DESCRIPTION ******************************************************/

/* START FUNCTION DESCRIPTION *****************************************
msAtx                         <MSZ_RAB.LIB>

NOTE: MSZ_RAB.LIB functions are generally not reentrant.

SYNTAX: 			void	msAtx  (void)

DESCRIPTION: 	User defineable function for enabling the rs485
					transmitter.  This function is needed in your application
					code.  If you are doing RS232, you need only to have
					an empty function like
					
					void msAtx(void)
					{
					}
					
					For rs485 control, you can do the following;

EXAMPLE:	  void msAtx(void)
			  {
			    // Ensure that all the data has bent sent.
			    
			    / Turn on the RS485 transmitter by doing the following;      
				
				//	PORT:				The parrallel port (PADR,PBDR,PCDR etc)          
				// PORTShadow: 	The Shadow register of the port
				//	ON_VALUE:		1 or 0
				//	PORT_BIT:		parrallel port bit (0-7)
				
					BitWrPortI(PORT,&PORTShadow, ON_VALUE, PORT_BIT);
			    
			    				
				//  If your product is a Zworld SBC, you can do the following
				
					ser485Tx();
					
				
			  }			

RETURN VALUE: none
END DESCRIPTION ******************************************************/

/* START FUNCTION DESCRIPTION *****************************************
msBinit                         <MSZ_RAB.LIB>

NOTE: MSZ_RAB.LIB functions are generally not reentrant.

SYNTAX: 	int msBinit(unsigned qBaud)

DESCRIPTION: User function for
				 Initializing serial port B as a Modbus ASCII Slave.
				 
				 This function must reside in your application code.
				 Typical code for this function would be the following;
				 
int msBinit(unsigned qBaud)        
{
	// Open the serial port.  THIS MUST BE DONE PRIOR TO SETTING THE
	// DATA BITS AND PARITY SETTINGS.
	
	serBopen(qBaud); 
	  
	// setup parity.  Either PARAM_OPARITY, PARAM_EPARITY, PARAM_NOPARITY, 
	// or PARAM_2STOP  
	
	serBparity(PARAM_EPARITY);
	 
	// setup data bits. Either PARAM_7BIT, or PARAM_8BIT 
	 
	serBdatabits(PARAM_8BIT);
	
  	// Set the Serial port mode. Used for Zworld SBC's only.  
  	
	serMode(0);  
	
	return(1);
}
				 

PARAMETER1: slave address.
PARAMETER2: baud rate (bits per second).

RETURN VALUE: 1 if successful, 0 if unsupported baud rate.
END DESCRIPTION ******************************************************/

/* START FUNCTION DESCRIPTION *****************************************
msBrx                         <MSZ_RAB.LIB>

NOTE: MSZ_RAB.LIB functions are generally not reentrant.

SYNTAX: 			void	msBrx  (void)

DESCRIPTION: 	User defineable function for disabling the rs485
					transmitter.  This function is needed in your application
					code.  If you are doing RS232, you need only to have
					an empty function like
					
					void msBrx(void)
					{
					}
					
					For rs485 control, you can do the following;

EXAMPLE:	  void msBrx(void)
			  {
			    // Ensure that all the data has bent sent.
			    
			    while (serBwrUsed() || \
			    		  BitRdPortI(SBSR,2) || \
			    		  BitRdPortI(SBSR,3)); 
				
				// Turn off the RS485 transmitter by doing the following;
				
				//	PORT:				The parrallel port (PADR,PBDR,PCDR etc)          
				// PORTShadow: 	The Shadow register of the port
				//	OFF_VALUE:		1 or 0
				//	PORT_BIT:		parrallel port bit (0-7)
				
					BitWrPortI(PORT,&PORTShadow, OFF_VALUE, PORT_BIT);
					
				//  If your product is a Zworld SBC, you can do the following
				
					ser485Rx();
					
				//  Flush out the serial port read buffer, so you are ready for
				//  the next packet.
					
					serBrdFlush();	 
			  }			

RETURN VALUE: none
END DESCRIPTION ******************************************************/


/* START FUNCTION DESCRIPTION *****************************************
msBtx                         <MSZ_RAB.LIB>

NOTE: MSZ_RAB.LIB functions are generally not reentrant.

SYNTAX: 			void	msBtx  (void)

DESCRIPTION: 	User defineable function for enabling the rs485
					transmitter.  This function is needed in your application
					code.  If you are doing RS232, you need only to have
					an empty function like
					
					void msBtx(void)
					{
					}
					
					For rs485 control, you can do the following;

EXAMPLE:	  void msAtx(void)
			  {
			    // Ensure that all the data has bent sent.
			    
			    / Turn on the RS485 transmitter by doing the following;      
				
				//	PORT:				The parrallel port (PADR,PBDR,PCDR etc)          
				// PORTShadow: 	The Shadow register of the port
				//	ON_VALUE:		1 or 0
				//	PORT_BIT:		parrallel port bit (0-7)
				
					BitWrPortI(PORT,&PORTShadow, ON_VALUE, PORT_BIT);
			    
			    				
				//  If your product is a Zworld SBC, you can do the following
				
					ser485Tx();
					
				
			  }			

RETURN VALUE: none
END DESCRIPTION ******************************************************/

/* START FUNCTION DESCRIPTION *****************************************
msCinit                         <MSZ_RAB.LIB>

NOTE: MSZ_RAB.LIB functions are generally not reentrant.

SYNTAX: 	int msCinit(unsigned qBaud)

DESCRIPTION: User function for
				 Initializing serial port C as a Modbus ASCII Slave.
				 
				 This function must reside in your application code.
				 Typical code for this function would be the following;
				 
int msCinit(unsigned qBaud)        
{
	// Open the serial port.  THIS MUST BE DONE PRIOR TO SETTING THE
	// DATA BITS AND PARITY SETTINGS.
	
	serCopen(qBaud); 
	  
	// setup parity.  Either PARAM_OPARITY, PARAM_EPARITY, PARAM_NOPARITY, 
	// or PARAM_2STOP  
	
	serCparity(PARAM_EPARITY);
	 
	// setup data bits. Either PARAM_7BIT, or PARAM_8BIT 
	 
	serCdatabits(PARAM_8BIT);
	
  	// Set the Serial port mode. Used for Zworld SBC's only.  
  	
	serMode(0);  
	
	return(1);
}
				 

PARAMETER1: slave address.
PARAMETER2: baud rate (bits per second).

RETURN VALUE: 1 if successful, 0 if unsupported baud rate.
END DESCRIPTION ******************************************************/

/* START FUNCTION DESCRIPTION *****************************************
msCrx                         <MSZ_RAB.LIB>

NOTE: MSZ_RAB.LIB functions are generally not reentrant.

SYNTAX: 			void	msCrx  (void)

DESCRIPTION: 	User defineable function for disabling the rs485
					transmitter.  This function is needed in your application
					code.  If you are doing RS232, you need only to have
					an empty function like
					
					void msCrx(void)
					{
					}
					
					For rs485 control, you can do the following;

EXAMPLE:	  void msCrx(void)
			  {
			    // Ensure that all the data has bent sent.
			    

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -