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

Modbus TCP Slave / How to detect process image change #64

Closed
dannaughton opened this issue Nov 7, 2017 · 4 comments
Closed

Modbus TCP Slave / How to detect process image change #64

dannaughton opened this issue Nov 7, 2017 · 4 comments

Comments

@dannaughton
Copy link

(I posted this on the sourceforge site, but I saw you moved here - sorry for duplicate post)

I have question about modbus TCP slave. I have the simple tutorial working (the one from the Wiki) and masters can connect to it and read/write the process image

Question:
On my slave device, what's the best way to detect if the process image has been changed (by the master of course).

@steveohara
Copy link
Owner

The best way is to implement you own ProcessImage and handle the updates. You could do that explicitly or extend SimpleProcessImage.
You then need to add the process image to the slave you have started.

@dannaughton
Copy link
Author

Thanks Steve,

That was helpful. Implementing my own ProcessImage is beyond my skill level. I looked into extending SimpleProcessImage and using Observable to handle changes, but that creates this Multiple Inheritance requirement that is also beyond my skill level to work through.

Everything seems to be working well, and stable. I'll keep looking to find someway to detect and handle when the ProcessImage is changed. There is an Observer interface that's included in j2mod. Not sure what the differences are between that and the normal Observer - but in either case, I'm not sure where to plug it in.

I'll report back - Thanks for your help

@dannaughton
Copy link
Author

I think I have a handle on it. It looks like using the ObservableDigitalOut and ObservableRegister is the way to go, rather than trying to extend SimpleProcessImage.

The following seems to work well (so I'm good - thanks for your help):

   spi = new SimpleProcessImage();
   ObservableDigitalOut odo = new ObservableDigitalOut();
   odo.set(true);
   odo.addObserver(this);
   spi.addDigitalOut(odo);


@Override
public void update(Observable o, Object arg) {
	System.out.println("Got notification from odo");
	
}

@steveohara
Copy link
Owner

I learn something new every day! I've never used the Observable features of j2mod before.
Thanks

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