steveohara / j2mod

Enhanced Modbus library implemented in the Java programming language
Apache License 2.0
276 stars 110 forks source link

Problem with raspbian RS-485 communication #112

Closed pan-henryk closed 3 years ago

pan-henryk commented 4 years ago

I am using j2mod with jSerialComm on raspberry pi/raspbian derived industrial embedded device. With jSerialComm-2.5.1 and j2mod-2.6.4 (last pair of libraries that work for me, j2mod 2.7.0 is binary incompatible with older jSerialComm versions) everything works fine, but any higher version of jSerialComm it does not, so it seems that the problem I experience was introduced in jSerialComm 2.5.2 Note: I am also posting this in jSerialComm issues, but it may be related to how j2mod uses jSerialComm.

I noticed that any newer version reverts internal com port mode from RS-485 back to rs-232. Looking at COM port name (/dev/ttySC0) I guess the underlying chip is SC16IS***

Expected Behavior

Modbus communication should work

Actual Behavior

Modbus communication does not work

Steps to Reproduce the Problem

  1. Try to establish modbus communication on SC16IS*** chip (device?) running in RS-485 mode, using jserialcom version > 2.5.1

Specifications

steveohara commented 4 years ago

There isn't anything chip specific in j2mod, so I suspect that if the behaviour has changed, then it will be in jserialcomm or perhaps in the linux serial driver that is being used on Raspbian. I would reach out to Will over there https://fazecast.github.io/jSerialComm/ and see what he says.

steveohara commented 4 years ago

I've re-opened this because I think we can mitigate your problem by exposing the RTS control from jserialcomm through j2mod so that you can control it from your application. If you're in a hurry, you could do this yourself by providing your own AbstractSerialConnection implementation that extends the included version SerialConnection and then setting the RS485 values on Open

pan-henryk commented 4 years ago

Thank you, I will check it asap.

icedaq commented 3 years ago

@pan-henryk We are experiencing the exact same problem. Did you ever find a solution for this?

pan-henryk commented 3 years ago

@pan-henryk We are experiencing the exact same problem. Did you ever find a solution for this? I stopped at using last working version (jSerialComm-2.5.1 and j2mod-2.6.4) and got distracted by another project. I plan to revisit it early January and try solution suggested by Steve.

icedaq commented 3 years ago

@pan-henryk We are experiencing the exact same problem. Did you ever find a solution for this? I stopped at using last working version (jSerialComm-2.5.1 and j2mod-2.6.4) and got distracted by another project. I plan to revisit it early January and try solution suggested by Steve.

Thanks for the update. We tested with the version you mentioned and it works perfectly in our case too. So we will stick with this version for the moment.

steveohara commented 3 years ago

Closing this on the basis that https://github.com/steveohara/j2mod/pull/117 has now introduced RS485 mode which should fix the issue