UPDATE: this has been resolved. See following post.
ORIGINAL POST
Hi we're evaluating j2mod as a modbus library for to use in our product. I'm still trying to figure this out so please excuese any silly questions. What I've tried to do is implement the Register interface with this:
publicclassSPTRegisterimplementsRegister{Randomgenerator=newRandom();intvalue=generator.nextInt();...@OverridepublicintgetValue(){value=generator.nextInt(10);System.out.println("Value:"+value); return value; } @Override public byte[] toBytes() { //value = generator.nextInt(10); value = (int) System.currentTimeMillis(); System.out.println("toBytes...valueis:"+value);returnByteBuffer.allocate(4).putInt(value).array();}}
and then i added my new register class to the TCPSlaveTest.java like this:
spi.addRegister(50, new SPTRegister());
But when I use my client to retrieve the value it does not seem to update and is always reporting the cached value while scanning. I'm testing with qModMaster and Radzio Modbus Simulator. I have to shutdown and reconnect to get an updated value which appears to be the next value instead of a recently updated value. So i'm confused shouldn't my implementation just return the latest value that was taken from toBytes()? When i run my client it continually scans and the server/slave appears to be calling toBytes repeaditly but of course as mentioned the value retrieved is unchanging unless i stop and reconnect.
toBytes... value is: -1531314939
toBytes... value is: -1531313921
toBytes... value is: -1531312907
toBytes... value is: -1531311892
toBytes... value is: -1531310876
toBytes... value is: -1531309860
toBytes... value is: -1531308844
...
With it as it is I'm not sure how to update any registers dynamically besides adding a new register to the SimpleProcessImage everytime the registers changes which seems very waistful . Any advice is would be very appreciated.
A second question is with qmodmaster putting the app in scan mode gives me a
Readdatafailed.SystemException.[Brokenpipe]
Error in red. Wondering if there is some special configuration i need to do to have the continuous scan work on qmodmaster. I have the default settings in the TCPSlaveTest.java
UPDATE I got my issue resolved! My issues was that in my int variable that i was publishing over the protocol i was sending the MSBytes which was not changing frequently. When i adjusted the test code so the LSBytes were used the behavior was much more ideal in that I was seeing my data update by two as expected. On top of that I also extended the class SynchronizedAbstractRegister which is probably intended by the library developors.
@Overridepublicbyte[]toBytes(){value++;value++;System.out.print("toBytes... value is: "+value+" ");byte[]my_buf=ByteBuffer.allocate(4).putInt(value).array();m_Register[0]=my_buf[2];m_Register[1]=my_buf[3];System.out.println("m_Register is: "+bytesToHex(m_Register));returnm_Register;}
Last edit: James M Chan 2016-02-10
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
UPDATE: this has been resolved. See following post.
ORIGINAL POST
Hi we're evaluating j2mod as a modbus library for to use in our product. I'm still trying to figure this out so please excuese any silly questions. What I've tried to do is implement the Register interface with this:
and then i added my new register class to the TCPSlaveTest.java like this:
But when I use my client to retrieve the value it does not seem to update and is always reporting the cached value while scanning. I'm testing with qModMaster and Radzio Modbus Simulator. I have to shutdown and reconnect to get an updated value which appears to be the next value instead of a recently updated value. So i'm confused shouldn't my implementation just return the latest value that was taken from toBytes()? When i run my client it continually scans and the server/slave appears to be calling toBytes repeaditly but of course as mentioned the value retrieved is unchanging unless i stop and reconnect.
With it as it is I'm not sure how to update any registers dynamically besides adding a new register to the SimpleProcessImage everytime the registers changes which seems very waistful . Any advice is would be very appreciated.
A second question is with qmodmaster putting the app in scan mode gives me a
Error in red. Wondering if there is some special configuration i need to do to have the continuous scan work on qmodmaster. I have the default settings in the TCPSlaveTest.java
--James
Last edit: James M Chan 2016-02-10
UPDATE I got my issue resolved! My issues was that in my int variable that i was publishing over the protocol i was sending the MSBytes which was not changing frequently. When i adjusted the test code so the LSBytes were used the behavior was much more ideal in that I was seeing my data update by two as expected. On top of that I also extended the class SynchronizedAbstractRegister which is probably intended by the library developors.
Last edit: James M Chan 2016-02-10