Re: [micro-manager-general] Steps to get a functional plugin, lesson n+1
Status: Beta
Brought to you by:
nicost
|
From: Nico S. <nic...@uc...> - 2020-04-08 20:28:20
|
Hi Carlos,
On 4/7/2020 3:00 PM, Carlos G Mendioroz wrote:
> Here, I was hoping to be informed using DataProviderHasNewImageEvent.
> But my first try did not work.
>
> I'm doing:
>
> // Run an acquisition using the current MDA parameters.
> acquireButton_ = new JButton("Run Acquisition");
> acquireButton_.addActionListener(new ActionListener() {
> @Override
> public void actionPerformed(ActionEvent e) {
> // All GUI event handlers are invoked on the EDT (Event Dispatch
> // Thread). Acquisitions are not allowed to be started from the
> // EDT. Therefore we must make a new thread to run this.
> Thread acqThread = new Thread(new Runnable() {
> @Override
> public void run() {
> ds_ = studio_.acquisitions().runAcquisition();
> ds_.registerForEvents(me);
> }
> });
> acqThread.start();
> }
> });
>
> where "me" is a reference to the Frame instance, and there:
>
> @Subscribe
> public void onNewImage(DataProviderHasNewImageEvent event) {
> imagesReceived_++;
> title.setText("We have an image to work with!");
> }
>
> I'm not getting along this bus thing.
> Help ?
Change:
ds_ = studio_.acquisitions().runAcquisition();
to:
ds_ = studio_.acquisitions().runAcquisitionNonBlocking();
Your current code registers the datastore to the Eventbus only after the
acquisition finished, hence your code never received a
DataProvierHasNewImageEvent.
Thanks for exercising the API!
Best,
Nico
|