locked
How to use Modbus.dll from www.nmodbus.com

    Question

  • This *.dll is good but it is written with C#. My question is "how to use it in VB.NET" and specifically with Express edition AND with "custom message". On that page there is similar question but answer is limited because guys are C# gurus and VB.NET is unfamiliar to them.

    I tried "add your own custom messages" without success.

    Demo program is like


    Program C# from www.nmodbus.com
    ushort testAddress = 120;
    ushort[] testValues = new ushort[] { 10, 20, 30, 40, 50 };
    CustomReadHoldingRegistersRequest readRequest = new CustomReadHoldingRegistersRequest(3, SlaveAddress, testAddress, (ushort) testValues.Length);
     
    ushort[] originalValues = Master.ExecuteCustomMessage<CustomReadHoldingRegistersResponse, ushort>(readRequest);
    ushort[] newValues = Master.ExecuteCustomMessage<CustomReadHoldingRegistersResponse, ushort>(readRequest);

     

    Program VB.NET (my version)
    Dim scT As New TcpClient
    With scT
    .Connect("192.168.0.3", 502)
    End With
    mbMaster = ModbusIpMaster.CreateIp(scT)


    Dim SlaveAddress As Byte = 18
    Dim answer(128) As UShort

    Dim readRequest As Object
    readRequest = New CustomMessages.CustomReadHoldingRegistersRequest(3, SlaveAddress, 0, 4)

    (CustomMessages namespace is available when C# is compiled)


    ..so far so good but now a problem...

    answer = mbMaster.ExecuteCustomMessage(xxxyyy)(readRequest)

     

    I can not find out out what to write inside round brackets?

    My application is somewhat similar like this but I have to change C# even I do not
    have previous experience with C#. Application is "Modbus Read File Record 0x14/0x06"
    which is not supported by this dll.
    When above application runs then I can write new command to be used with Modbus.dll..

     

    modbus.dll is available from internet page www.nmobus.com

     

    Help needed please!

     

    Wednesday, August 06, 2008 8:21 AM

All replies

  • Most of .NET is written in C#. The dll you want to use is written in C#.  Add it to your project and reference it as you would a framework dll.

    Wednesday, August 06, 2008 8:42 AM
  • I added it to my project as reference. My problem is that I can not find the way how to use it. I have tried it few weeks now without success (mbmaster.ExecuteCustomCommand() etc. etc.). All other internal commands run well but CustomCommand is another thing.
    I think that I post this same question to nmodbus too..

    regards
    Wednesday, August 06, 2008 11:25 AM
  • How have you included the custom response and request classes?  If you're having problems converting the samples to VB, load them in SharpDevelop and convert to VB.

    Wednesday, August 06, 2008 11:55 AM
  • Well..

    I found from source files "how to use" help.

    One question still..

    How to change command below to VB.NET?

     

    ushort[] originalValues = Master.ExecuteCustomMessage<CustomReadHoldingRegistersResponse, ushort>(readRequest);

     

    from source files..

    public class CustomReadHoldingRegistersResponse : IModbusMessage

    {

    }

     

    regards

    hessu

    Monday, August 11, 2008 6:05 PM
  • If your asking this question about how to convert that code then I can assume that your fairly new to vb and .net, there is very little difference in how you would write that in vb and c,  an experienced programmer can read either and fairly quickly realise how to write it in their preferred language.

    Your new to it all which is great, because you have the opportunity to switch languages now!!!

    I am not another VB basher, in fact VB is near and dear to me and I code in it frequently but I wish that I had started with C#. This is for the simple and indisputable reason that more people use C# so there are more code examples out there, more coders to help you and therefore its easier to learn!

    Its not really about the language, vb and c# are just a syntax that let you get at the fantastic  .net framework which provides the heavy lifting and so you can port any knowledge you have built up in VB directly into the C# and all you have to do is deal with the differences in syntax (which would appear very subtle to a beginner). If you have written less than a few thousand lines of code in your time then you are at the point where you can switch to C# very easily, all you have to deal with is declaring vars, running loops and jamming a colon on the end of everything and you have basically made the change - you could be comfortable in c# in a day or two!

    Man I wish someone had told me this when I started programming, they did actually but I ignored them the same way I ignored my parents about cigarette smoking and see how far that got me too.  It would be an easier run for you in C# so unless your tied to VB for some reason consider it!

    Good luck

    Wednesday, May 02, 2012 4:29 AM
  • If your asking this question about how to convert that code then I can assume that your fairly new to vb and .net, there is very little difference in how you would write that in vb and c,  an experienced programmer can read either and fairly quickly realise how to write it in their preferred language.

    Your new to it all which is great, because you have the opportunity to switch languages now!!!

    I am not another VB basher, in fact VB is near and dear to me and I code in it frequently but I wish that I had started with C#. ...<snip>

    I'm sure they have converted it by now, or moved onto pottery, or something: 3 1/2 years is a long time to wait for a reply...

    Stephen J Whiteley

    Wednesday, May 02, 2012 2:36 PM