Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Modbus RTU/ASCII OVER TCP/UDP #149

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

MLing592
Copy link

No description provided.

Copy link
Contributor

@rquackenbush rquackenbush left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your PR! I've asked a few questions and it looks like there is at least one item that needs fixing before we can merge.

Note that I'm travelling at the moment, but will pull down your full PR into my local environment so I can better understand your changes and intent and may have more questions and comments at that point.

<ItemGroup>
<ProjectReference Include="..\NModbus\NModbus.csproj" />
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the thought for removing this reference?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was a bad mistake, so I should have done it

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be added

Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NModbus.IntegrationTests", "NModbus.IntegrationTests\NModbus.IntegrationTests.csproj", "{1AA055F2-68E1-409F-A744-6081D7A27A57}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NModbus.IntegrationTests", "NModbus.IntegrationTests\NModbus.IntegrationTests.csproj", "{1AA055F2-68E1-409F-A744-6081D7A27A57}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ConsoleApp1", "H:\Users\Administrator\Desktop\MLToolkit\ConsoleApp1\ConsoleApp1.csproj", "{5F0BB26E-AB88-4D59-834D-5082653BF24B}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like a temporary change that probably shouldn't be here as it points to a project in your local environment.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you are right, in fact I used “ConsoleApp1” for testing but I forgot to delete it

public ModbusMasterRtuOverTcpConnection(TcpClient client, IModbusSlaveNetwork slaveNetwork, IModbusFactory modbusFactory, IModbusLogger logger)
: base(client,slaveNetwork,modbusFactory,logger, new ModbusRtuTransport(new TcpClientAdapter(client), modbusFactory, logger))
{
//TODO
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is there left to do here?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, this is some habit of mine, in fact nothing needs to be done here

private readonly IModbusSlaveNetwork _slaveNetwork;
private readonly IModbusFactory _modbusFactory;
private readonly Task _requestHandlerTask;
protected internal TcpClient _client;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll need to pull this PR down to my local environment to follow exactly what's happening here, but what is your thought in making all of these protected? Also, did something change where we can't keep the readonly modifier?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, at first I was hoping to change it to "protected readonly" so that subclasses could inherit, but apparently I forgot to add "readonly",

@@ -38,6 +38,8 @@ public int WriteTimeout
set { _serialPort.WriteTimeout = value; }
}

public string Name => _serialPort?.PortName;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What problem does exposing the port name solve?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NModbusPic
As you can see, in fact this is for use in Logger.Information, but they are not important

@MLing592
Copy link
Author

  1. Thank you for your reply. In fact, I have some other questions that I would like to discuss with you. For example,
  • [1 ] In ModbusMasterRtuOverTcpConnection.cs, should CRC or LRC verification be performed on modbusRTU/ASCII OVER TCP/UDP? In my code I commented them out because I think TCP and UDP have their own verification and no verification is needed anymore.

  • [ 2] Should asynchronous mode be added to TcpClientAdapter and UdpClientAdapter?

  • [ 3.] As you can see, In UdpClientAdapter.cs,I added the Endpoint parameter to Udp,

NModbusPic6
NModbusPic2
NModbusPic3

which will lead to some changes. For example, this will affect all UdpMasters in ModbusFactory.cs
NModbusPic7

They must specify this Endpoint during initialization, but the slave does not need to. This may Not very good. The reason I added it is because when Udp serves as the master station, it needs to actively send requests, so it needs to set the Endpoint of the master station. When Udp serves as the slave station, it listens for requests. Receive automatically obtains the client Endpoint when sending. What are your thoughts on using this Endpoint?

  • [ finally ]Thanks and wish you a pleasant journey 😊😊😊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants