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

Is there a method to gracefully end communication? #6

Open
elliotburch opened this issue Jun 23, 2016 · 8 comments
Open

Is there a method to gracefully end communication? #6

elliotburch opened this issue Jun 23, 2016 · 8 comments

Comments

@elliotburch
Copy link

I've been looking through the core.py file for a method that will end comms, but I can't find anything... The official Thor manual lists a StopCtrl method, but it doesn't seem like that method is included in the package.

I've written a small program that allows for user communication with a while loop controlling the whole process, but if the program crashes or is willingly exited it can't relaunch without resetting the motors. I'm guessing its cause the communication channel never closes. It won't even load the packages.

Other than that, it works great on BSC 201 and KDC 101 model stepper motor controllers.

@tobiasgehring
Copy link
Contributor

Hi,

I'm not aware of any method closing the communication other than calling
APTCleanUp. It is not really well documented how the whole process
works. APTCleanUp should be the counterpart to APTInit, but I think
communication is only established in InitHWDevice. However, already in
APTInit some internal lists are initialized with existing hardware.
My guess is that StopCtrl is a method of the ActiveX control which has
much more useful functions than APT.DLL. You could have a look at thorpy
instead which uses the underlying communication protocol. I haven't
tried it myself though.

On 06/23/2016 11:09 PM, thisismynamenow wrote:

I've been looking through the core.py file for a method that will end
comms, but I can't find anything... The official Thor manual lists a
StopCtrl method, but it doesn't seem like that method is included in the
package.

I've written a small program that allows for user communication with a
while loop controlling the whole process, but if the program crashes or
is willingly exited it can't relaunch without resetting the motors. I'm
guessing its cause the communication channel never closes. It won't even
load the packages.

Other than that, it works great on BSC 201 and KDC 101 model stepper
motor controllers.


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
#6, or mute the thread
https://github.com/notifications/unsubscribe/ABV7UgVPXYQ71v6LX_DHqQW2E3OLGd1fks5qOvYhgaJpZM4I9Pf1.

@elliotburch
Copy link
Author

The _cleanup() method does the trick! I was just having trouble finding it in core.py, nothing came up for ctrl+f end/stop/quit/exit or any other synonyms. In order to get it to work I had to add an 'import thorlabs_apt.core as core', as the function didn't import from a standard 'from thorlabs_atp import *', but once that was included everything runs like a charm. Thanks a bunch!

@tobiasgehring
Copy link
Contributor

you're welcome. I would like to understand this a little better. Could
you tell me in which context you call this method?

On 06/24/2016 10:53 PM, thisismynamenow wrote:

The _cleanup() method does the trick! I was just having trouble finding
it in core.py, nothing came up for ctrl+f end/stop/quit/exit or any
other synonyms. In order to get it to work I had to add an 'import
thorlabs_apt.core as core', as the function didn't import from a
standard 'from thorlabs_atp import *', but once that was included
everything runs like a charm. Thanks a bunch!


You are receiving this because you commented.
Reply to this email directly, view it on GitHub
#6 (comment),
or mute the thread
https://github.com/notifications/unsubscribe/ABV7UuyCR6d6v39LkSNwd3_nCZZ29lnMks5qPEPXgaJpZM4I9Pf1.

@elliotburch
Copy link
Author

The program I wrote is for user control for those not familiar with the more complex python commands, since my setup has 2 motors, I set it up so that users can move it between three configurations. The program as a whole just ran in a while loop, with user input via input(). But when exiting the program and reentering it, it will always crash without a power cycle on the controllers, as the communication channel remains open after exiting the program. The cleanup() method ends communication so that it can be reestablished next time the program is launched.

@fonty422
Copy link

Hi guys,
I think this is connected to the above, but I recently upgraded my PC to a new OS (from 32-bit to 64-bit) and I now have a problem when I exit.
In short, I'm using this and flask to control a few stages via a web browser, and when I use crtl+c to quit, it somehow clobbers the controllers and I can't run either the server app OR the APT software until I flash the firmware. This never happened previously.

Thanks heaps!

NOTE: using python 2.7

@fonty422
Copy link

Hi guys,
I'm still having trouble here, but I believe this will solve the problem as it's the same as you described. I'm just not sure how to call APTCleanUp() - I keep getting an error that the module doesn't exist.

I was planning on calling it via a SIGINT capture so when i ctrl+C to quit, it first runs this, but just can't seem to get it to call.

Any chance you could offer a quick example that opens, runs, and gracefully exits using the APTCleanup method?

Thanks

@LeftyAce
Copy link

LeftyAce commented Nov 30, 2016

Here's how I am running it. Note that I put ALL of my code (requesting input from the user, everything after "import_thorlabs_apt") inside the try block. This is so that if ANY of my code causes an exception, or the user quits with the keyboard, or anything else happens after I've imported thorlabs_apt, I still get to call _cleanup() before the program exits. Otherwise it'll refuse to run next time.

import thorlabs_apt.core as apt_core
import thorlabs_apt as apt

try:
# put everything you want to do here
finally:
apt_core._cleanup()

ps, I can't figure out getting a multi-line code block, or how to get the code style to respect indents. Everything inside the "try" needs to be indented, as well as everything inside the "finally:" Take a look at some python exception handling examples if you're new to exceptions :-)

@fonty422
Copy link

Thanks LeftyAce. That should all work just fine now.
Cheers!

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

4 participants