Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Jun 20 23:19
    linbo690 opened #185
  • Apr 14 04:31
    Hoan96 synchronize #184
  • Mar 13 07:55
    Hoan96 synchronize #184
  • Mar 13 07:44
    Hoan96 synchronize #184
  • Mar 12 04:39
    Hoan96 opened #184
  • Jan 04 16:35
    MPapst commented #150
  • Jan 04 16:32
    ChangeTheCode commented #150
  • Jan 04 15:46
    MPapst commented #150
  • Jan 04 14:55
    ChangeTheCode commented #150
  • Jan 04 14:33
    MPapst commented #150
  • Jan 04 14:24
    ChangeTheCode commented #150
  • Dec 07 2020 09:14
    pvakharwala commented #183
  • Dec 07 2020 09:08
    Fonta88 commented #183
  • Dec 05 2020 16:02
    pvakharwala commented #183
  • Dec 05 2020 16:01
    pvakharwala commented #182
  • Dec 03 2020 11:47
    Fonta88 commented #183
  • Oct 14 2020 14:13
    stefurios edited #183
  • Oct 14 2020 14:12
    stefurios edited #183
  • Oct 14 2020 14:11
    stefurios edited #183
  • Oct 14 2020 14:11
    stefurios opened #183
Ghost
@ghost~561e7019d33f749381a9572c
Reviewing docs.. doesn't seem to be any api for specifying slave exception handling. Example code I have (previous version of nmodbus) was setting an exception handler on the slave. Seems this has been removed from nmodbus4?
Richard Lawley
@richardlawley
Can you point at the previous example?
Ghost
@ghost~561e7019d33f749381a9572c
not sure if you mean reference the example here or point to the old dll in my present project. I'm about to try the latter, but had been hoping to use the presently maintained version of nmodbus. Seems like this would be a common problem.. start slave, run... , dispose slave, exception in thread!
Richard Lawley
@richardlawley
I'm not a maintainer, but have this library in production use (replacing the older non-maintained version) with no problems. You'll need to provide more details, such as a stack trace and a code sample.
Ghost
@ghost~561e7019d33f749381a9572c
When the exception occurs, there's no symbols, just assembly code. Reassuring that there shouldn't be odd issues like this. Best way to post a code sample here?
Ghost
@ghost~561e7019d33f749381a9572c
This is the entire slave minus the data writing/reading with the datastore. Test were run with this exact code. I get either the ArgumentException or a NullReference Exception on every test while the application is closing. For the test, I have a master running trying to do some reads periodically. Test case is to start the app, wait a few seconds, close the app. Code...
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Modbus;
using Modbus.Device;
using Modbus.Data;
using Modbus.Message;
using System.Net;
using System.Net.Sockets;

namespace ModbusLib
{
    class Slave : Link
    {
        TcpListener slaveTcpListener;
        Modbus.Device.ModbusSlave slave;

        private byte SlaveID = 1;   // making this a non-config item for now

        public Slave(string aName, tMsgHandler aMsgHandler)
            :base(aName, aMsgHandler)
        {}

        public override void Start()
        {
            IPAddress ip = new IPAddress(0);

            if (IPAddress.TryParse(IpAddress, out ip) == false)
            {
                Error("Could not parse IP Address for link: " + Name);
                return;
            }

            try
            {
                slaveTcpListener = new TcpListener(ip, TcpPort);
            }
            catch (Exception e)
            {
                Error("Could not start modbus slave " + Name + ". Exception: " + e.ToString());
                return;
            }

            slaveTcpListener.Start();

            slave = Modbus.Device.ModbusTcpSlave.CreateTcp(SlaveID, slaveTcpListener);
            slave.DataStore = Modbus.Data.DataStoreFactory.CreateDefaultDataStore();

            slave.Listen();
        }
        protected override void Dispose(bool disposing)
        {
            if (slaveTcpListener != null)
            {
                slaveTcpListener.Stop();
                slave.Dispose();
            }
        }
    }
}
This message was deleted
Ghost
@ghost~561e7019d33f749381a9572c
Best I got for a stack trace for the ArgumentException. Looks to be from shutting it down while it was accepting the connection, but how do I make it shutdown gracefully anyway?
System.ArgumentException: The IAsyncResult object was not returned from the corresponding asynchronous method on this class.
Parameter name: asyncResult
   at System.Net.Sockets.Socket.EndAccept(Byte[]& buffer, Int32& bytesTransferred, IAsyncResult asyncResult)
   at System.Net.Sockets.Socket.EndAccept(IAsyncResult asyncResult)
   at Modbus.Device.ModbusTcpSlave.AcceptCompleted(IAsyncResult ar)
   at Modbus.Device.ModbusTcpSlave.<>c.<AcceptCompleted>b__17_0(IAsyncResult state)
   at System.Net.LazyAsyncResult.Complete(IntPtr userToken)
   at System.Net.ContextAwareResult.CompleteCallback(Object state)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Net.ContextAwareResult.Complete(IntPtr userToken)
   at System.Net.LazyAsyncResult.ProtectedInvokeCallback(Object result, IntPtr userToken)
   at System.Net.Sockets.BaseOverlappedAsyncResult.CompletionPortCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* nativeOverlapped)
   at System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* pOVERLAP)
Ghost
@ghost~561e7019d33f749381a9572c
Lastly, I had removed slave = null; and slaveTcpListener=null; from the Dispose routine shown above, and I no longer have the NullReference exception showing up. Before the change it was happening about 1/3 of tests run.
Also, after talking with a coworker here, we think the exception handler setting on a slave that I referred to earlier was probably added to the old nmodbus library by an ex-coworker of ours.
Richard Lawley
@richardlawley
Got a bit mixed up before, I only use the master functionality. However, looking at your code I would try calling slave.Dispose() and not calling .Stop() on your listener. Looking at the code it looks like the Dispose handler takes care of cleaning up the listener.
Ghost
@ghost~561e7019d33f749381a9572c
Ah, you've nailed it! No more exceptions. Thank you very much. Previous version of library didn't properly disconnect without more stuff in the dispose (but then would exception quite a bit too). This version doesn't need it and properly disconnects on its own with no exceptions. Excellent.
David Barda
@davebarda
Hmm, if I disconnect the serial port, there is a reason why the slaves doesn't disconnect? should it be like that?
Kevin Luty
@kevlut
So, I sometimes get a IOException when communicating with a Modbus TCP device regarding to transaction id expected X. Transaction id received X-Y, using the original NModbus from the google repo... does NModbus4 fix that issue?
this doesn't seem too active, hoping you'll see this @Maxwe11
Kevin Luty
@kevlut
@davebarda if you disconnect the serialport, the physical communication line doesn't disappear, so the slaves don't techincally "disconnect" they simply just don't communicate.
Richard Lawley
@richardlawley
@kevlut, this behaviour occurs if your receive timeout is shorter than the timeout on the sender - your first request appears to timeout, but the reply is still waiting in the queue. On the second request, you receive the response to the first. I ran a private fork because of this situation for years, I put this enhancement into NModbus4 when it started up. See NModbus4/NModbus4#41 for details.
Kevin Luty
@kevlut
beautiful
do you recommend using SlaveBusyUsesRetryCount?
Richard Lawley
@richardlawley
Yes - that's another one I added because it caused me problems in the original fork.
Kevin Luty
@kevlut
@richardlawley so i get a bunch of, odd behavior, with the connected modbus tcp/ip device, are you familiar with wireshark and want to lend a helping hand? :D
Kevin Luty
@kevlut
blob
looks like a timeout occurs, then i bombard it, then it returns exception code, then it starts replying, then gets out of order again... then the connection just... closes/disconnects
Kevin Luty
@kevlut
.6: 11320000001b01031805dc0000000000030000000002b100000000000000000022
.182: 1133000000060103003f000c
.6: 11330000001b01031805dc0000000000030000000002b100000000000000000022
.182: 1134000000060103003f000c
.182: 1135000000060103003f000c
.182: 1136000000060103003f000c
.182: 1137000000060103003f000c1138000000060103003f000c
.6: 113600000003018306
.182: 1139000000060103003f000c
.6: 11370000000301830611380000000301830611340000001b01031805dc0000000000030000000002b10000000000000000002211350000001b01031805dc0000000000030000000002b100000000000000000022
.6: 11390000001b01031805dc0000000000030000000002b100000000000000000022
this is over wifi
Ghost
@ghost~561e7019d33f749381a9572c
@kevlut We see things like that wireshark sometimes too.. did you figure out what's going on?
Ghost
@ghost~561e7019d33f749381a9572c
General question - is there a way (with example?) to get a slave to respond to additional function codes without modifying the library? In one configuration, a function code 20 gets sent to it as a request and it exceptions and terminates the tread pool - documented in the code that this is what it should do, so we've configured the other device to not send function code 20, but sometimes it gets an old config and sends the function code, which will cause a nuisance. I'd prefer to make the slave not terminate in this case if that's possible - without hacking at the library :)
oh lol.. didn't notice the activity stream with function code 20 added! nvm on my question then as I'll try that out when it is ready.
Gritsenko Sergey
@GritsenkoSD
Hello!
Снимок.PNG
The parameter is incorrect.
I can not understand what the problem is
Gritsenko Sergey
@GritsenkoSD
Problem was solved.
Craig
@cragdor
Hi All, Do any of you know of some guides to compiling NModbus4 on Mono on Linux? I can see from the build output of Travis that the mono version is compiling on Ubuntu. But I keep getting errors when I try to compile the solution.
aneek231
@aneek231
@aneek231
Hey guys, Can you please tell me which ModbusMaster library supports ESP8266.
I have used https://github.com/4-20ma/ModbusMaster and during compilation it says "This library only supports boards with an AVR or SAM processor. Please open an issue at https://github.com/4-20ma/ModbusMaster/issues and indicate which processor/platform you're using.""
Alexander Winter
@WinterGuardian
Hi ?
SamuelZXP
@SamuelZXP
I download "NModbus4-portable-3.0.zip", unzip and open by VS2015.; then I use "Package Manager Console" install "NModbus4", it is sucessfully installed. But the compiler still fails. Question: where is the "NModbus4" installed?
SamuelZXP
@SamuelZXP
When I open the solution, the output have errors as below: An error occurred while sending the request.
GET https://api.nuget.org/v3/index.jsonFindPackagesById()?id='dotnet-test-xunit'
GET https://api.nuget.org/v3/index.jsonFindPackagesById()?id='OpenCover'
Warning: FindPackagesById: Moq
An error occurred while sending the request.
GET https://api.nuget.org/v3/index.jsonFindPackagesById()?id='Moq'
GET https://api.nuget.org/v3/index.jsonFindPackagesById()?id='System.Diagnostics.TraceSource'
Warning: FindPackagesById: dotnet-test-xunit
An error occurred while sending the request.
GET https://api.nuget.org/v3/index.jsonFindPackagesById()?id='dotnet-test-xunit'

GET https://api.nuget.org/v3/index.jsonFindPackagesById()?id='xunit'

MikeOnTheWork
@MikeOnTheWork
Hi Guys, I'm trying to understand if the NModbus4-portable-3.0 release can run on windos 10 iot core. I saw some references to not .core framework parts. Moreover i would like understand if all the projects are need to be used in a production enviroment or I can delete Nmodbus4-UnitTests. Thanks for any support.
Sujeeth
@sujeethk

Hi, I have setup a slave using the NModbus4 library. A master is able to read/write to the slave. I am looking for some direction on how to intercept requests, so i can control access to specific register addresses?

Example:

  1. When a master is trying to read a specific register I want to return 0 instead of its actual value
  2. When a master is trying to write to a specific register, I want to return -1 indicating he cannot write to it
AlexeyTipunin
@AlexeyTipunin
Hi guys! When exchanging data, I get the following error: Hi Guys! Response was not of expected transaction ID. Expected 49719, received 49718. Has anyone encountered a similar problem? Is there a way to synchronize transactions in the library?
Richard Lawley
@richardlawley
I added support for this a long time ago (NModbus4/NModbus4#41). You need to enable the feature though - it's off by default. This happens if your device replies later than the nmodbus timeout for watching for the reply - the next receive gets the missed reply.
AlexeyTipunin
@AlexeyTipunin
@richardlawley Thank you very much for the quick response. I tried it, it works fine.
iamwho
@iamyongan_twitter
Hi all,I noticed that nmobus4 master doesn't support broadcasting,is that ture?
master.WriteSingleRegister(0, 0, 0x0043); still cause a receiving timeout exception
duhtmep
@duhtmep
hi all, does anyone have experiences to run the library at the dotnet core framework?? Many thanks
zengxiding
@zengxiding
hello
jaygeet
@jaygeet
can you explain me how you set up modbus ?
Brian Gallaway
@greatawesome
Does anyone know whether it is possible to share a DataStore between a ModbusTCPSlave and ModbusSerialSlave? It looks like it should be feasible, but wanted to see if anyone has experience doing that.
Brian Gallaway
@greatawesome
I just tried it. Works fine.