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

📄 siemens_mpi.cpp

📁 本源代码演示了通过串口利用MPI协议与西门子PLC S7-300系统通讯的实现方式。
💻 CPP
📖 第 1 页 / 共 2 页
字号:
//Time			:2009-04-25 
//Modify person	:
//Time			:
//Version		:V1.0.0
//////////////////////////////////////////////////////////////////////////
int WINAPI PLC_R_QW(int deviceNo,int amount,void* buffer)
{
	int error;
	error = a_field_read(deviceNo,amount*2,buffer);
	return error;
	
}


//////////////////////////////////////////////////////////////////////////
//Function name	:PLC_W_QW
//Input			:int deviceNo  
//				:int amount:number of data to be write
//				:void* buffer:store the value     
//Output		:error code
//Remark		:write the Q's Word
//Global		:
//Call function	:a_field_write
//Author		:
//Time			:2009-04-25 
//Modify person	:
//Time			:
//Version		:V1.0.0
//////////////////////////////////////////////////////////////////////////
int WINAPI PLC_W_QW(int deviceNo,int amount,void* buffer)
{
	int error;
	error = a_field_write(deviceNo,amount*2,buffer);
	return error;
}


//////////////////////////////////////////////////////////////////////////
//Function name	:PLC_R_QD
//Input			:int deviceNo  
//				:int amount:number of data to be read
//				:void* buffer:store the result     
//Output		:error code
//Remark		:read the Q's DWord
//Global		:
//Call function	:a_field_read
//Author		:
//Time			:2009-04-25 
//Modify person	:
//Time			:
//Version		:V1.0.0
//////////////////////////////////////////////////////////////////////////
int WINAPI PLC_R_QD(int deviceNo,int amount,void* buffer)
{
	int error;
	error = a_field_read(deviceNo,amount*4,buffer);
	return error;
}


//////////////////////////////////////////////////////////////////////////
//Function name	:PLC_W_QD
//Input			:int deviceNo  
//				:int amount:number of data to be write
//				:void* buffer:store the value     
//Output		:error code
//Remark		:write the Q's DWord
//Global		:
//Call function	:a_field_write
//Author		:
//Time			:2009-04-25 
//Modify person	:
//Time			:
//Version		:V1.0.0
//////////////////////////////////////////////////////////////////////////
int WINAPI PLC_W_QD(int deviceNo,int amount,void* buffer)
{
	int error;
	error = a_field_write(deviceNo,amount*4,buffer);
	return error;
}


//////////////////////////////////////////////////////////////////////////
//Function name	:PLC_R_MW
//Input			:int deviceNo  
//				:int amount:number of data to be read
//				:void* buffer:store the result     
//Output		:error code
//Remark		:read the M's Word
//Global		:
//Call function	:m_field_read
//Author		:
//Time			:2009-04-25 
//Modify person	:
//Time			:
//Version		:V1.0.0
//////////////////////////////////////////////////////////////////////////
int WINAPI PLC_R_MW(int deviceNo,int amount,void* buffer)
{
	int error;
	error = m_field_read(deviceNo,amount*2,buffer);
	return error;
}


//////////////////////////////////////////////////////////////////////////
//Function name	:PLC_W_MW
//Input			:int deviceNo  
//				:int amount:number of data to be write
//				:void* buffer:store the value     
//Output		:error code
//Remark		:write the M's Word
//Global		:
//Call function	:m_field_write
//Author		:
//Time			:2009-04-25 
//Modify person	:
//Time			:
//Version		:V1.0.0
//////////////////////////////////////////////////////////////////////////
int WINAPI PLC_W_MW(int deviceNo,int amount,void* buffer)
{
	int error;
	error = m_field_write(deviceNo,amount*2,buffer);
	return error;
}


//////////////////////////////////////////////////////////////////////////
//Function name	:PLC_R_MD
//Input			:int deviceNo  
//				:int amount:number of data to be read
//				:void* buffer:store the result     
//Output		:error code
//Remark		:read the Q's DWord
//Global		:
//Call function	:m_field_read
//Author		:
//Time			:2009-04-25 
//Modify person	:
//Time			:
//Version		:V1.0.0
//////////////////////////////////////////////////////////////////////////
int WINAPI PLC_R_MD(int deviceNo,int amount,void* buffer)
{
	int error;
	error = m_field_read(deviceNo,amount*4,buffer);
	return error;
}


//////////////////////////////////////////////////////////////////////////
//Function name	:PLC_W_MD
//Input			:int deviceNo  
//				:int amount:number of data to be write
//				:void* buffer:store the value     
//Output		:error code
//Remark		:write the M's DWord
//Global		:
//Call function	:m_field_write
//Author		:
//Time			:2009-04-25 
//Modify person	:
//Time			:
//Version		:V1.0.0
//////////////////////////////////////////////////////////////////////////
int WINAPI PLC_W_MD(int deviceNo,int amount,void* buffer)
{
	int error;
	error = m_field_write(deviceNo,amount*4,buffer);
	return error;
}


//////////////////////////////////////////////////////////////////////////
//Function name	:PLC_R_DBW
//Input			:int blockNo,DB block
//				:int deviceNo  
//				:int amount:number of data to be read
//				:void* buffer:store the result     
//Output		:error code
//Remark		:read the DB's word
//Global		:
//Call function	:db_read
//Author		:
//Time			:2009-04-25 
//Modify person	:
//Time			:
//Version		:V1.0.0
//////////////////////////////////////////////////////////////////////////
// int WINAPI PLC_R_DBW(int blockNo,int deviceNo,int amount,void* buffer)
// {
// 	int error;
// 	error = db_read(blockNo,deviceNo,&amount,buffer);
// 	return error;
// }
int WINAPI PLC_R_DBW(int blockNo,int deviceNo,int amount,void* buffer)
{
	int error;
	int amount2 = 2*amount;
	error = d_field_read(blockNo,deviceNo,amount2,buffer);
	return error;
}

//////////////////////////////////////////////////////////////////////////
//Function name	:PLC_W_DBW
//Input			:int blockNo,DB block
//				:int deviceNo  
//				:int amount:number of data to be write
//				:void* buffer:store the value     
//Output		:error code
//Remark		:read the DB's Word
//Global		:
//Call function	:db_write
//Author		:
//Time			:2009-04-25 
//Modify person	:
//Time			:
//Version		:V1.0.0
//////////////////////////////////////////////////////////////////////////
// int WINAPI PLC_W_DBW(int blockNo,int deviceNo,int amount,void* buffer)
// {
// 	int error;
// 	error = db_write(blockNo,deviceNo,&amount,buffer);
// 	return error;
// }

int WINAPI PLC_W_DBW(int blockNo,int deviceNo,int amount,void* buffer)
{
	int error;
	int amount2 = 2*amount;
	error = d_field_write(blockNo,deviceNo,amount2,buffer);
	return error;
}


//////////////////////////////////////////////////////////////////////////
//Function name	:PLC_R_DBD
//Input			:int blockNo,DB block
//				:int deviceNo  
//				:int amount:number of data to be read
//				:void* buffer:store the result     
//Output		:error code
//Remark		:read the DB's Dword
//Global		:
//Call function	:db_read
//Author		:
//Time			:2009-04-25 
//Modify person	:
//Time			:
//Version		:V1.0.0
//////////////////////////////////////////////////////////////////////////
// int WINAPI PLC_R_DBD(int blockNo,int deviceNo,int amount,void* buffer)
// {
// 	int error;
// 	int amount2 = 2*amount;
// 	error = db_read(blockNo,deviceNo,&amount2,buffer);
// 	return error;
// }
int WINAPI PLC_R_DBD(int blockNo,int deviceNo,int amount,void* buffer)
{
	int error;
	int amount2 = 4*amount;
	error = d_field_read(blockNo,deviceNo,amount2,buffer);
	return error;
}

//////////////////////////////////////////////////////////////////////////
//Function name	:PLC_W_DBD
//Input			:int blockNo,DB block
//				:int deviceNo  
//				:int amount:number of data to be write
//				:void* buffer:store the value     
//Output		:error code
//Remark		:read the DB's DWord
//Global		:
//Call function	:db_write
//Author		:
//Time			:2009-04-25 
//Modify person	:
//Time			:
//Version		:V1.0.0
//////////////////////////////////////////////////////////////////////////
// int WINAPI PLC_W_DBD(int blockNo,int deviceNo,int amount,void* buffer)
// {
// 	int error;
// 	int amount2 = 2*amount;
// 	error = db_write(blockNo,deviceNo,&amount2,buffer);
// 	return error;
// }
int WINAPI PLC_W_DBD(int blockNo,int deviceNo,int amount,void* buffer)
{
	int error;
	int amount2 = 4*amount;
	error = d_field_write(blockNo,deviceNo,amount2,buffer);
	return error;
}


//////////////////////////////////////////////////////////////////////////
//Function name	:PLC_R_T
//Input			:int deviceNo  
//				:int amount,numbers of data to be read
//				:int* buffer,store the result     
//Output		:error code
//Remark		:read the T's Word
//Global		:
//Call function	:t_field_read
//Author		:
//Time			:2009-04-25 
//Modify person	:
//Time			:
//Version		:V1.0.0
//////////////////////////////////////////////////////////////////////////
int WINAPI PLC_R_T(int deviceNo,int amount,short* buffer)
{
	int error;
	error = t_field_read(deviceNo,amount,buffer);
	return error;
}


//////////////////////////////////////////////////////////////////////////
//Function name	:PLC_R_C
//Input			:int deviceNo  
//				:int amount,numbers of data to be read
//				:int* buffer,store the result     
//Output		:error code
//Remark		:read the C's Word
//Global		:
//Call function	:z_field_read
//Author		:
//Time			:2009-04-25 
//Modify person	:
//Time			:
//Version		:V1.0.0
//////////////////////////////////////////////////////////////////////////
int WINAPI PLC_R_C(int deviceNo,int amount,void* buffer)
{
	int error;
	error = z_field_read(deviceNo,amount*2,buffer);
	return error;
}


//////////////////////////////////////////////////////////////////////////
//Function name	:Gp_to_Float
//Input			:void* gpValue,gp type float 
//				:void*flValue,IEEE type float
//Output		:
//Remark		:change the gp type float to IEEE type float
//Global		:
//Call function	:gp_to_float
//Author		:
//Time			:2009-04-25 
//Modify person	:
//Time			:
//Version		:V1.0.0
//////////////////////////////////////////////////////////////////////////
void WINAPI Gp_to_Float(void* gpValue,void*flValue)
{
	gp_to_float(gpValue,flValue);
}


//////////////////////////////////////////////////////////////////////////
//Function name	:Float_to_Gp
//Input			:void*flValue,IEEE type float
//				:void* gpValue,gp type float 
//Output		:
//Remark		:change the IEEE type float to gp type float
//Global		:
//Call function	:float_to_gp
//Author		:
//Time			:2009-04-25 
//Modify person	:
//Time			:
//Version		:V1.0.0
//////////////////////////////////////////////////////////////////////////
void WINAPI Float_to_Gp(void* flValue,void* gpValue)
{
	float_to_gp(flValue,gpValue);
}


//////////////////////////////////////////////////////////////////////////
//Function name	:OpenPLC
//Input			:int nr,number of PLC
//				:char* device,a name of link,uaually use "S7ONLINE"
//				:adr_table_type* adr_table,address table
//Output		:error code
//Remark		:link the pc and plc
//Global		:
//Call function	:load_tool
//Author		:
//Time			:2009-04-25 
//Modify person	:
//Time			:
//Version		:V1.0.0
//////////////////////////////////////////////////////////////////////////
int WINAPI OpenPLC(int nr,char* device,adr_table_type* adr_table)
{
	int error;
	error = load_tool(nr,device,adr_table);
	return error;
}


//////////////////////////////////////////////////////////////////////////
//Function name	:ClosePLC
//Input			:
//Output		:error code
//Remark		:end the link
//Global		:
//Call function	:unload_tool
//Author		:
//Time			:2009-04-25 
//Modify person	:
//Time			:
//Version		:V1.0.0
//////////////////////////////////////////////////////////////////////////
int WINAPI ClosePLC()
{
	int error;
	error = unload_tool();
	return error;
}


//////////////////////////////////////////////////////////////////////////
//Function name	:New_ss
//Input			:int no,PLC's address
//Output		:error code
//Remark		:activate the plc(only use in more than one plc)
//Global		:
//Call function	:new_ss
//Author		:
//Time			:2009-04-25 
//Modify person	:
//Time			:
//Version		:V1.0.0
//////////////////////////////////////////////////////////////////////////
int WINAPI New_ss(int no)
{
	int error;
	error = new_ss(no);
	return error;
}
#ifdef __cplusplus
    } /* extern "C" */
#endif

⌨️ 快捷键说明

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