GallowayLabMIT / labbot

MIT License
0 stars 0 forks source link

Keyence status integration #7

Open meson800 opened 3 years ago

meson800 commented 3 years ago

Summary

The basic idea here is to create a client Python script that is responsible for reading the state of the Keyence (is the microscope on? Is the microscope software open?). It sends the labbot server this information, which then decides how to notify people via Slack, in case the Keyence gets left on.

Non-standard libraries (e.g. extra documentation to look at):

To see if the Microscope is on and if the microscope is open, we need some non-standard library packages:

Getting running processes: psutil. Getting connected devices: either pywin32 or pyusb with libusb binaries for windows.

Quickly skimming the relevant tutorials, pyusb looks like the one we want: https://github.com/pyusb/pyusb/blob/master/docs/tutorial.rst but probably requires a little bit of fiddling to properly load the libusb DLL.

Solution outline

  1. Decide how you want to notify the user. Unlike the Attune, we don't know which user logged in, so its hard to notify specific users. You should think through and figure out what you want to do (e.g. after N hours of being "left on" (e.g. software closed but microscope left on, send a message to #admin if we are within "normal hours". If it isn't normal hours, maybe use an @channel to alert people).
  2. Start a new branch off master and start writing a client script (with its own virtual environment), testing it on the Keyence computer. This will involve finding the name of the keyence software process and finding the keyence device ID (through device manager on Windows). At this point, the script can just output the current state in a loop ("running, left on, off, etc") to the screen, we'll tie it in later.
  3. Write the slack backend side (very similar to Adam's attune backend; we'll discuss both of the server backends together)
  4. Tie the client and server together

Open questions

What's a good way to figure out the difference between both the microscope and the software being left open and the keyence doing a very long microscopy operation? It might be possible to modify the microscope software briefly to output this information (e.g. started a run, finished a run) into a log file.