亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? mssmartstar.c

?? modbus 運用事例
?? C
字號:
/********* Sample Program ****************************************************


MSSmartStar.c	Copyright(c) 2003 Z-World Engineering.
					
Legal Notice	This program has been written by the Technical Support Staff at 
					Z-World in response to several customer requests.  As such, it 
					has NOT had the testing and validation procedures which our 
					"standard" software products have.  It is being made available 
					as a sample.  There is no warranty, implied or otherwise. 

DESCRIPTION:	Sample program demonstrating modbus slave control via RS485
					for the SmartStar expandable system.
				
					This sample will allow control via a Modbus Master controller
					of the following;
					
					1. Relay output card
					1. Digital I/O card
					1. Analog input card (0-10VDC was used). 
						(Will read both RAW data and Calibrated VDC data.)
					
					The modbus master software used with this sample can be 
					downloaded (Demo Version) via the following company link.
					
					WinTECH Software Systems incorporated
					
					http://www.win-tech.com          

*****************************************************************************/

/******   Start of user configurable macros *********************************/

// This sets up the individual card locations, for this sample.  Put the
// slot number next to the corresponding macro.

// Relay card location

#define	RELAY_SLOT			1

// Digital IO card location

// this was setup using a single card with 16 inputs and 8 outputs, so the
// slot number will be the same for both.
#define	INPUT_SLOT			2
#define	OUTPUT_SLOT			2

// Analog input card location

#define	ADC_SLOT				0

// Define the number of channels for each type of input

// Number of analog inputs on that slot
#define	ADC_AMOUNT			10

// Number of relay outputs
#define	RELAY_AMOUNT		8

// Number of digitial I/O
#define	INPUT_AMOUNT		16
#define	OUTPUT_AMOUNT		8

// This sets up the MODBUS address.  It MUST be unique from any other modbus
// device that is on the bus.
#define	SLAVE_ADDRESS		0x01

// The baudrate used for the MODBUS protocol.
#define	MODBUS_BAUDRATE	9600	// 9600 is default, 19200 works to.

// Choose the protocol type, 0 for ASCII, 1 for RTU.  This MUST match the
// Modbus master protocol selection.

#define	MODBUS_TYPE			1	

/******  Done with user configurable macros *********************************/

// Setup up the serial port buffer size

#define	DINBUFSIZE	31
#define	DOUTBUFSIZE	31

// Modbus slave library, it also calls ms_rab.lib
#use		"msz_rab.lib"

//	Output Shadow Registers
char 		acShad[RELAY_AMOUNT + OUTPUT_AMOUNT + 1];

/*

/*=========================================================================*\
msDone:

	Called just after a received Modbus command has been
	processed and just before the reply is sent. This function is intended
	to be used to unlock resources that were locked by msStart(). Locking
	resources may or may not be required, depending on how the msIn(),
	msInput(), msOutRd() and msOutWr() functions are implemented in a
	particular Modbus slave application. Note that Modbus command handler
	functions in MS_RAB.LIB may make multiple calls to those functions while
	responding to a single Modbus command.
	
\*=========================================================================*/
		
nodebug
void msDone(void)
{
	// place any locked resources required.
}

/*=========================================================================*\
msStart:

	Called just before a received Modbus packet is processed,
	this function is primarily intended to be used to lock resources so
	that data returned in one Modbus response packet are atomic. Locking
	resources may or may not be required, depending on how the msIn(),
	msInput(), msOutRd() and msOutWr() functions are implemented in a
	particular Modbus slave application. Note that Modbus command handler
	functions in MS_RAB.LIB may make multiple calls to those functions while
	responding to a single Modbus command.

\*=========================================================================*/

nodebug
void msStart(void)
{
	// place any locked resources required.
}


/*=========================================================================*\
msDinit:
	Sets up and opens the serial port.  default settings are 8 data bits
	1 stop bit, no parity, no flow control.

\*=========================================================================*/

int msDinit(unsigned qBaud)
{
	// Open the serial port.  THIS MUST BE DONE PRIOR TO SETTING THE  
	// DATA BITS AND PARITY SETTINGS.

	serDopen(qBaud);

	// setup parity.  Either PARAM_OPARITY, PARAM_EPARITY, PARAM_NOPARITY,
	// or PARAM_2STOP

	serDparity(PARAM_EPARITY);

	// setup data bits. Either PARAM_7BIT, or PARAM_8BIT

	serDdatabits(PARAM_8BIT);

  	// Set the Serial port mode. Used for Zworld SBC's only.

	serMode(0);

	return(1);
}

/*=========================================================================*\
msDtx:
	This functions is used for enabling the RS485 transmitter.

\*=========================================================================*/

void msDtx()
{
	// Turn on the transmitter
	ser485Tx();
}

/*=========================================================================*\
msDrx:
	This functions is used for disabling the RS485 transmitter.

\*=========================================================================*/

void msDrx()
{	
	// Make sure all of the data has been sent by;
	// 1.) checking the write buffer for any bytes left
	// 2.) checking the status of the Write interrupt transmit bit (2).
	// 3.) checking the status of the Write interrupt data bit (3)
	while (serDwrUsed() || BitRdPortI(SDSR,2) || BitRdPortI(SDSR,3)); 
	// turn off the transmitter
	ser485Rx();
	// Since we echo what we send, flush the read buffer, so that you are
	// ready for the next packet.
	serDrdFlush();	 
}

/*=========================================================================*\
	msOutRd:	(01  Coil Status)
		Used for reading output coil status.  A user defined shadow register
		is required in your code which will need to be updated when digital/relay
		outputs are toggled. The function below only sends the value, it does
		not update it.
\*=========================================================================*/

int msOutRd(unsigned wCoil, int *pnState)
{
	//  Check to see if a valid output channel is being called.
	if (wCoil > (OUTPUT_AMOUNT + RELAY_AMOUNT) )	return MS_BADADDR;
	// copy the contents of the coil shadow element.
	*pnState = acShad[wCoil];
	return 0;
}

/*=========================================================================*\
	msOutWr:	(01  Coil Writing)  
		Used for Writing to individual output coils.  This sample sets up
		the first OUTPUT_AMOUNT of coils to be the digital, and the rest
		to be the RELAY_AMOUNT coils.  
\*=========================================================================*/

int msOutWr(unsigned wCoil, int bState)
{
	//  Check to see if a valid output channel is being called.  
	if ( wCoil > (OUTPUT_AMOUNT + RELAY_AMOUNT) )	return MS_BADADDR;
	//  update the shadow used in the msOutRd function.
	acShad[wCoil] = bState;
	// If the Coil is a Digital Output;
	if (wCoil <= OUTPUT_AMOUNT) digOut(ChanAddr(OUTPUT_SLOT,wCoil),bState);
	// If the coil is a Relay Output;
	else  relayOut( ChanAddr(RELAY_SLOT, wCoil - OUTPUT_AMOUNT) ,bState) ;
	
	return 0;
}

/*=========================================================================*\
	msIn:	(02:	Input Status)
		Used for reading the state of the individual digital inputs.    
\*=========================================================================*/

int msIn(unsigned wCoil, int *pnState)
{
	//  Check to see if a valid input channel is being called.    
	if (wCoil > INPUT_AMOUNT)	return MS_BADADDR;
	//  Read the input and store it.
	*pnState = digIn(ChanAddr(INPUT_SLOT, wCoil));
	return 0;
}

/*=========================================================================*\
	msRead:	(03:	Reading from a Holding Register)  
		Used (in this sample)    
		For reading the individual CALIBRATED value of each adc inputs.
		Since Modbus deals with unsigned ints (words), and our VDC input
		function returns a float, the function will need to store the value
		as two registers type casted into unsigned ints for the Modbus 
		protocol to accept properly.  How this is done must be the same for
		both the Master and the slave.  This example will put the Most 
		Significant word of the float into the odd register, and the least
		significant word into the even register. (ie register 1 and register
		2 will hold the float value of adc input 0, register 3 and 4 will
		hold adc input 1 etc.).  
\*=========================================================================*/

int msRead(unsigned wReg, unsigned *pwValue)
{
	static float calVal;
	static char  cVal[6];
	// Since it will take two registers per input, you must double the 
	// amount of register neccessary.
	if (wReg > (ADC_AMOUNT * 2) )	return MS_BADADDR;
	
	// if the input is odd the get the new adc value
	if ( !(wReg % 2) )
	{
  		// You must divide the wReg value by 2 when getting the proper channel	
		calVal = anaInVolts(ChanAddr(ADC_SLOT, wReg/2));    
		// move the adc float value int a holding array of 4 bytes
		*(float *) & cVal[0] = calVal;
		// copy the first 2 bytes of the holding array into the register value
		*pwValue = *(unsigned int *) &cVal[0];    
	}
	// if the register is even
	else
	{
		// copy the last 2 bytes of the holding array into the register value.
		// DO NOT recalculate the input value.
		*pwValue = *(unsigned int *) &cVal[2];	   
	}
	return 0;
}

/*=========================================================================*\
	msWrite:	(03:	Writing to Holding Register)  
		Not used in this sample.   
		This could be used for write to a DAC card channel, much like reading
		from a ADC card channel shown in msRead.
		
\*=========================================================================*/

nodebug
int msWrite(unsigned wReg, unsigned wValue)
{
	// Place code here.
	return 0;
}

/*=========================================================================*\
	msInput:	(04:	Input Register)
		Used (in this sample)
		For reading the individual RAW DATA of each adc input.  
\*=========================================================================*/

int msInput(unsigned wReg, unsigned *pwValue)
{
	if ( wReg > ADC_AMOUNT )return MS_BADADDR;
	// move the analog value into the register.
	*pwValue = anaIn(ChanAddr(ADC_SLOT, wReg));	
	return 0;
}

void main(void)
{
	auto int loop;
	
	// Clear the output shadow array at startup of this sample
	memset(acShad, 0, sizeof(acShad));	
	
	// initialize the SBC
	brdInit();
#if	(!MODBUS_TYPE)	 
	// Open Serial port D in ASCII mode 
	msaDinit(SLAVE_ADDRESS, MODBUS_BAUDRATE);
#else
	// Open Serial port D in RTU mode
	msrDinit(SLAVE_ADDRESS, MODBUS_BAUDRATE);  
#endif
	// If there are analog inputs required, get the cal. constants from the
	// eeprom.
	
	if (ADC_AMOUNT > 0)
	{
		for (loop = 0 ; loop < ADC_AMOUNT ; loop++)
			// read in the cal. constants.
			anaInEERd(ChanAddr(ADC_SLOT, loop));      
	}
	
	for( ;; )								
	{
		// This is the Modbus slave handler.
		msRun();
		
		//	Other Costates Here!!! (Make sure your code does not block.)
	}
}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
国产精品午夜在线观看| 在线观看免费一区| 欧美大片顶级少妇| 精品在线播放免费| 久久理论电影网| 成熟亚洲日本毛茸茸凸凹| 日本一二三不卡| 91亚洲大成网污www| 亚洲乱码一区二区三区在线观看| 白白色 亚洲乱淫| 亚洲精选视频在线| 欧美另类久久久品| 精彩视频一区二区| 日本一区二区三级电影在线观看 | 日韩一级黄色片| 91在线国产观看| 樱花草国产18久久久久| 欧美日韩一区二区三区免费看| 丝袜美腿亚洲综合| 久久综合九色综合97_久久久| www.成人在线| 亚洲不卡av一区二区三区| 精品国产乱码久久久久久久久| 成人精品在线视频观看| 亚洲成人自拍一区| 久久人人爽爽爽人久久久| 色综合色综合色综合| 蜜臀91精品一区二区三区| 中文字幕av免费专区久久| 欧美日本一区二区| 国产成人精品免费视频网站| 亚洲国产成人高清精品| 国产亲近乱来精品视频| 欧美偷拍一区二区| 国产成人av一区| 日韩中文字幕麻豆| 18欧美乱大交hd1984| 精品欧美一区二区三区精品久久 | 色94色欧美sute亚洲线路一ni| 水野朝阳av一区二区三区| 国产日韩av一区| 欧美精品 国产精品| 成人午夜激情在线| 麻豆91在线播放免费| 亚洲免费在线观看| 国产区在线观看成人精品 | 91精品在线麻豆| 波多野结衣在线一区| 久久av资源网| 亚洲成人自拍网| 一区二区三区在线观看动漫| 国产网站一区二区| 欧美成人三级电影在线| 欧美日韩国产片| 91视视频在线观看入口直接观看www | 欧美成人伊人久久综合网| 欧美视频中文字幕| 色哟哟在线观看一区二区三区| 国产精品一区二区在线看| 婷婷久久综合九色国产成人| 一区在线观看视频| 中文字幕乱码久久午夜不卡| 久久众筹精品私拍模特| 日韩精品中文字幕一区| 欧美精品一二三| 欧美亚洲一区二区三区四区| 成人综合婷婷国产精品久久| 狠狠色丁香婷婷综合| 久久福利资源站| 麻豆精品新av中文字幕| 琪琪一区二区三区| 日本成人在线一区| 大桥未久av一区二区三区中文| 国产福利精品一区二区| 国产精品一区二区黑丝| 国产成人精品免费| 成人综合日日夜夜| 99re视频这里只有精品| 99久久99久久精品国产片果冻| www.爱久久.com| 91麻豆精品秘密| 波多野结衣91| 91麻豆精东视频| 在线视频你懂得一区| 欧美日韩精品一区视频| 欧美日本国产一区| 91精品免费观看| 精品国产免费久久 | 欧美猛男超大videosgay| 欧美亚洲国产一区在线观看网站| 欧美性三三影院| 日韩一区二区三区免费看 | 亚洲成年人网站在线观看| 天天影视色香欲综合网老头| 日韩黄色片在线观看| 久久精品国产第一区二区三区| 国产一区 二区| gogo大胆日本视频一区| 欧美网站大全在线观看| 日韩视频一区二区三区| 国产丝袜美腿一区二区三区| 国产精品第13页| 亚洲午夜电影在线| 狠狠色丁香久久婷婷综合丁香| 成人av免费在线播放| 欧美亚洲国产怡红院影院| 欧美成人精品3d动漫h| 国产欧美日韩精品在线| 亚洲第四色夜色| 国模冰冰炮一区二区| 91一区一区三区| 日韩欧美亚洲一区二区| 一色桃子久久精品亚洲| 日本不卡一区二区三区高清视频| 国产美女精品在线| 在线观看三级视频欧美| 日韩欧美一区中文| 中文字幕一区二区三区视频| 日韩成人免费在线| 不卡一区二区在线| 日韩视频免费观看高清完整版| 国产精品久久久久影院亚瑟| 日韩国产精品久久久| 成人小视频免费观看| 日韩丝袜美女视频| 亚洲日穴在线视频| 极品少妇一区二区| 91福利区一区二区三区| 国产欧美1区2区3区| 日韩电影在线观看电影| 99久久伊人网影院| 久久久久久久性| 麻豆一区二区99久久久久| 色综合av在线| 国产精品乱码久久久久久| 国产精品538一区二区在线| 欧美男男青年gay1069videost | 51久久夜色精品国产麻豆| 国产精品女主播av| 久久国产麻豆精品| 精品视频资源站| 亚洲视频中文字幕| 成人精品视频一区二区三区| 精品久久久久久久一区二区蜜臀| 性感美女久久精品| 91免费在线视频观看| 中文字幕不卡一区| 国内精品伊人久久久久av一坑| 欧美情侣在线播放| 亚洲精品国产视频| 99麻豆久久久国产精品免费| 久久久久九九视频| 国产一区免费电影| 久久综合久久综合久久综合| 日本怡春院一区二区| 欧美色视频在线| 亚洲成人在线网站| 欧美日韩三级视频| 午夜精彩视频在线观看不卡| 91激情在线视频| 一区二区三区四区在线播放 | www.综合网.com| 国产精品久久久久aaaa樱花 | 亚洲精品菠萝久久久久久久| av电影在线观看完整版一区二区| 国产喂奶挤奶一区二区三区| 国产一区二区三区免费看| 26uuu精品一区二区在线观看| 蜜臀久久久久久久| 日韩欧美电影在线| 国产中文一区二区三区| 久久欧美一区二区| 粉嫩av亚洲一区二区图片| 中文字幕成人网| 91农村精品一区二区在线| 亚洲综合清纯丝袜自拍| 欧美三级中文字幕在线观看| 婷婷久久综合九色综合绿巨人 | 欧美三区在线视频| 亚洲国产精品久久不卡毛片| 欧美日韩精品专区| 日本中文在线一区| 国产精品美日韩| 97精品久久久久中文字幕| 一区二区三区四区精品在线视频| 在线观看成人免费视频| 天天色天天操综合| 欧美成人a视频| 成人av动漫网站| 午夜国产精品影院在线观看| 日韩一卡二卡三卡四卡| 粉嫩高潮美女一区二区三区| 亚洲欧洲精品成人久久奇米网| 欧美日韩亚洲不卡| 国产一区二区三区日韩| 亚洲欧美日韩中文字幕一区二区三区| 欧美性videosxxxxx| 国内成人精品2018免费看| 中文字幕中文字幕在线一区| 欧美日韩成人高清|