Bachelorthesis/Modbus-DLL/include/ModbusProtocolDLL/ModbusProtocolDLL.cpp

86 lines
2.4 KiB
C++
Raw Normal View History

/*-------------------------------------------------------------------
ModbusProtocolDLL.cpp
-------------------------------------------------------------------
(c) 2009 Vector Informatik GmbH. All rights reserved.
------------------------------------------------------------------- */
#include "StdAfx.h"
#include "ModbusProtocolDLL.h"
#include "ModbusProtocolAddOn.h"
2014-05-30 17:14:33 +02:00
#include "ModbusProtocol.h"
#include <fstream>
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
/*--------------------------------------------------------------------*/
//! Reply new ProtocolManager instance
/*!
This function is called on loading of this DLL by the IPB Packet API.
It must register the protocol of this DLL.
*/
STDAPI DllRegisterAddOn( NIPB::IAddOnRegistrar* registrar )
{
if (registrar == NULL)
{
return E_INVALIDARG;
}
2014-05-30 17:14:33 +02:00
std::ofstream log;
log.open("log.txt", std::ofstream::out);
//
// register the signal protocol at the IPB Packet Lib. For the protocol
2014-05-30 17:14:33 +02:00
// UDP is used.
//
2014-05-30 17:14:33 +02:00
ModbusProtocolAddOn *mbpao = new ModbusProtocolAddOn();
if (registrar->RegisterProtocol( "modbus", mbpao, "udp", ModbusProtocol::kServerPort, ModbusProtocol::kClientPort ) != NIPB::kOK)
{
2014-05-30 17:14:33 +02:00
log << "Could not register UDP 502 -> 50002\n";
log.close();
mbpao->Release();
return NIPB::kError;
}
2014-05-30 17:14:33 +02:00
/*if (registrar->RegisterProtocol( "modbus", mbpao, "udp", 0xFFFFFFFF, ModbusProtocol::kServerPort ) != NIPB::kOK)
{
log << "Could not register UDP 50002 -> 502\n";
log.close();
mbpao->Release();
return NIPB::kError;
}*/
log << "Registered Modbus for UDP\n";
log.close();
return S_OK;
}
/*--------------------------------------------------------------------*/
//! Return interface version
/*!
This DLL must support a proper version of the IBP Packet API.
*/
STDAPI DllGetApiVersion( unsigned long /*out*/*major, unsigned long /*out*/*minor, unsigned long /*out*/*structVersion )
{
if (major)
{
*major = IPB_PACKET_LIB_INTERFACE_VERSION_MAJOR;
}
if (minor)
{
*minor = IPB_PACKET_LIB_INTERFACE_VERSION_MINOR;
}
if (structVersion)
{
*structVersion = IPB_PACKET_LIB_STRUCT_VERSION;
}
return S_OK;
}
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////