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

Network Stream #77

Open
harjitsinghhpk opened this issue Jan 25, 2022 · 10 comments
Open

Network Stream #77

harjitsinghhpk opened this issue Jan 25, 2022 · 10 comments

Comments

@harjitsinghhpk
Copy link

harjitsinghhpk commented Jan 25, 2022

If connected with TCP/IP, the connection aborted if there is no poll for sometime with server. It end up with below exception:

At this line:
stream.Write(data, 0, data.Length-2);

System.Net.Sockets.SocketException : Unable to read data from the transport connection: An established connection was aborted by the software in your host machine.

Is there anyway to keep the connection live even there is no poll until disconnected from slave.

@Padanian
Copy link

You can poll any register every n seconds, where n < disconnection timeout
Or you can check if connected before attempting reading or writing.

@harjitsinghhpk
Copy link
Author

Polling register is a hack & i do check the connection before trying write. The connection status is true.
To tackle it more efficiently, can it be done by re-connecting to same tcpclient incase the exception occur?

@Padanian
Copy link

Polling a register is not a hack.
Anyway, the right thing to do is to set the tcp timeout on your server to a sensible value, and/or prevent the timeout to expire.

@harjitsinghhpk
Copy link
Author

Or
Can we add a system.timer in the master library, which will keep the connection live by writing and reading on stream after 10 seconds.
The write and read can be blocked if there is any request on the function codes. If there is not request received to the library for 10 seconds it will use the above steam read/write to keep the connection alive.

@harjitsinghhpk
Copy link
Author

Polling a register is not a hack. Anyway, the right thing to do is to set the tcp timeout on your server to a sensible value, and/or prevent the timeout to expire.

: Issue with polling register is, user have to define the register which is available in the slave to poll always.

@Padanian
Copy link

Well, if you plan to connect via modbus to a slave, you should at least be aware of one or more register addresses actually available on that slave. Don't you think?

@Padanian
Copy link

Or
Can we add a system.timer in the master library, which will keep the connection live by writing and reading on stream after 10 seconds.
The write and read can be blocked if there is any request on the function codes. If there is not request received to the library for 10 seconds it will use the above steam read/write to keep the connection alive.

Terrible idea in the class definition. You can do it though in your implementation.

@harjitsinghhpk
Copy link
Author

Well, if you plan to connect via modbus to a slave, you should at least be aware of one or more register addresses actually available on that slave. Don't you think?

Hi,
Definitely there will be some registers in the slave, but it will be uncertain extra work on the master interface who so ever is implementing the library in their project. In case where a user just want to get the data when a request is sent.

To elaborate further, say i have prepared a modbus master tool using the library. I can connect it to multiple slave for testing/data collection. Each slave may not have the same address as other, in this case a additional lookup for defining the keep alive registers need to be taken care. I was just looking a way out to avoid this.

@Padanian
Copy link

The issue here, IMHO, is that you have a timing-out slave problem, that you'd like to solve on the master.
If so, why don't you just close the connection after polling and reopen the connection before polling, so that the slave will never time out.

@harjitsinghhpk
Copy link
Author

The issue here, IMHO, is that you have a timing-out slave problem, that you'd like to solve on the master.

If so, why don't you just close the connection after polling and reopen the connection before polling, so that the slave will never time out.

Probably the best to do i guess. 👌🏻

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

No branches or pull requests

2 participants