"An unhandled exception of type 'System.TypeInitializationException'
occurred in Modbus.dll
Additional information: The type initializer for
'Modbus.IO.ModbusRtuTransport' threw an exception."
Here is code (
#include "stdafx.h"
#using <mscorlib.dll>
#using <System.dll>
#using "Modbus.dll"
#using "log4net.dll"
using namespace System;
using namespace System::IO::Ports;
using namespace Modbus::Device;
int main(array<System::String ^> ^args)
{
Console::WriteLine(L"Hello World");
SerialPort^ port = gcnew SerialPort("COM2");
port->BaudRate = 9600;
port->DataBits = 8;
port->Parity = System::IO::Ports::Parity::None;
port->StopBits = System::IO::Ports::StopBits::One;
port->Open();
// create modbus master
ModbusSerialMaster^ master = ModbusSerialMaster::CreateRtu(port);
unsigned char slaveID = 1;
unsigned short startAddress = 5;
unsigned short numRegisters = 1;
unsigned short register5 = master->ReadHoldingRegisters(slaveID,
startAddress, numRegisters)[0];
Console::WriteLine(String::Format("Register 5: {0}", register5));
Console::WriteLine("Press any key to exit.");
Console::ReadKey();
// return 0;
}
I registered Modbus.dll by 'regasm'.
Can anyone help me?
jackrz
On May 29, 7:24 pm, micro...@micromax.pl wrote:
> Hi
> I tried to write sample in VC++ 2005 and after compilation I received
> the following run-time error:
>
> "An unhandledexceptionof type 'System.TypeInitializationException'