How to include NModbus

1,250 views
Skip to first unread message

caspar_h...@hotmail.com

unread,
Aug 20, 2007, 8:59:50 AM8/20/07
to NModbus
I like to use NModbus for some hobby and studying but I can't get the
implementation included... I like to use NModbus in a C++ or C#
project environment.

Can you tell me with which software I can include the NModbus
implementation and in what way?

Thanx in advance,

With kind regards,

Caspar

sja...@gmail.com

unread,
Aug 20, 2007, 10:17:24 AM8/20/07
to NModbus
Copy the Modbus and log4net dlls into the same directory and add a
reference to the Modbus dll.

Scott

caspar_h...@hotmail.com

unread,
Aug 21, 2007, 3:07:15 AM8/21/07
to NModbus
How do I add such a reference in Visual Studio using C++?

Caspar

Scott Alexander

unread,
Aug 21, 2007, 10:27:41 AM8/21/07
to NModbus...@googlegroups.com

caspar_h...@hotmail.com

unread,
Aug 22, 2007, 7:28:50 AM8/22/07
to NModbus
What I did was:

#using "Modbus.dll"

And I have copied the .dll file in the main project directory..

But I always get the message:

fatal error C1190: managed targeted code requires '#using
<mscorlib.dll>' and '/clr' option


I've no idea what I'm doing wrong..

On 21 aug, 16:27, "Scott Alexander" <sja...@gmail.com> wrote:
> http://support.microsoft.com/kb/310674
>
> On 8/21/07, caspar_het_sp...@hotmail.com <caspar_het_sp...@hotmail.com>

Jacob Carpenter

unread,
Aug 22, 2007, 11:51:13 AM8/22/07
to NModbus...@googlegroups.com
caspar--

It sounds like you're selecting the wrong type of C++ project from
within Visual Studio. I don't know what version of Visual Studio you
have, but in VS 2005 (and 2008 Beta 2) Professional, in the "New
Project" dialog, "Visual C++" is an expandable tree node. If you click
the plus sign (or arrow on Vista) to expand the node, you should see
something like:
- ATL
- CLR
- General
- MFC
- Smart Device
- Win32

To reference NModbus in a C++ project, you want to select from the CLR
group of project types. This will enable the compiler switch (/clr)
required to reference the NModbus assembly.

Hope that helps, and good luck
Jacob.

caspar_h...@hotmail.com

unread,
Aug 27, 2007, 5:36:35 AM8/27/07
to NModbus
Ah! I see.. Thank you very much!
I'm working with VS 2003.. But under C++ projects I see:

- .NET
- ATL
- MFC
- Win32
- General

So I think I need a new(er) version of VS.. I hope I can get one and
then getting started :)

Kind regards,

Caspar

On 22 aug, 17:51, "Jacob Carpenter" <jacobcarpen...@gmail.com> wrote:
> caspar--
>
> It sounds like you're selecting the wrong type of C++ project from
> within Visual Studio. I don't know what version of Visual Studio you
> have, but in VS 2005 (and 2008 Beta 2) Professional, in the "New
> Project" dialog, "Visual C++" is an expandable tree node. If you click
> the plus sign (or arrow on Vista) to expand the node, you should see
> something like:
> - ATL
> - CLR
> - General
> - MFC
> - Smart Device
> - Win32
>
> To reference NModbus in a C++ project, you want to select from the CLR
> group of project types. This will enable the compiler switch (/clr)
> required to reference the NModbus assembly.
>
> Hope that helps, and good luck
> Jacob.
>

caspar_h...@hotmail.com

unread,
Aug 29, 2007, 6:32:34 AM8/29/07
to NModbus
Now I'm using Visual C++ Express Edition (a 30 days trial) and I think
the including is succeeded.
But now I have the following problem;

I always getting the following message:
An unhandled exception of type 'System.IO.FileNotFoundException'
occurred in Unknown Module.

Additional information: Could not load file or assembly 'Modbus,
Version=1.2.0.0, Culture=neutral, PublicKeyToken=null' or one of its
dependencies.

What am I doing wrong this time?

Kind regards,

Caspar

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
My code now:
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#include "stdafx.h"
#include <iostream>
#include <string>

#using "Modbus.dll"
#using "log4net.dll"

using namespace std;

using namespace System;
using namespace System::Diagnostics;
using namespace System::IO::Ports;
using namespace System::Threading;
using namespace Modbus;
using namespace Modbus::Device;

void main()
{
SerialPort port("COM2");

// configure serial port
port.BaudRate = 9600;
port.DataBits = 8;
//port.Parity = Even;
//port.StopBits = StopBits.One;
port.Open();

// create modbus master
IModbusSerialMaster^ master;
//IModbusSerialMaster^ CreateRtu(port);

unsigned char slaveID = 10;
unsigned short startAddress = 10;
unsigned short registers = 5;

// write three registers
master->ReadHoldingRegisters(slaveID, startAddress, registers);

cin.get();
}
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

caspar_h...@hotmail.com

unread,
Aug 29, 2007, 6:32:34 AM8/29/07
to NModbus

Kind regards,

Caspar

#using "Modbus.dll"
#using "log4net.dll"

using namespace std;

cin.get();
}
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

caspar_h...@hotmail.com

unread,
Aug 29, 2007, 7:22:01 AM8/29/07
to NModbus
Is there also an example of a Modbus master in C++..?

I think I'm using a lot of function confusedly.. So I can see how it
works and build it to my own requirements..

On 27 aug, 11:36, caspar_het_sp...@hotmail.com wrote:

Reply all
Reply to author
Forward
0 new messages