frappy/frappy_psi/ppmswindows.py
Alexander Zaft 15d38d7cc1 all: remove coding cookies
Change-Id: I53a4d79c3ebc50b8aed43a5ef1fa6538f8059a47
Reviewed-on: https://forge.frm2.tum.de/review/c/secop/frappy/+/32251
Tested-by: Jenkins Automated Tests <pedersen+jenkins@frm2.tum.de>
Reviewed-by: Enrico Faulhaber <enrico.faulhaber@frm2.tum.de>
Reviewed-by: Alexander Zaft <a.zaft@fz-juelich.de>
2024-01-29 14:06:06 +01:00

66 lines
2.5 KiB
Python

#!/usr/bin/env python
# *****************************************************************************
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation; either version 2 of the License, or (at your option) any later
# version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# Module authors:
# Markus Zolliker <markus.zolliker@psi.ch>
# *****************************************************************************
import threading
try:
import pythoncom
import win32com.client
except ImportError:
print("This Module only works with a pythoncom module on a MS Windows OS")
raise
class Error(Exception):
pass
class QDevice:
def __init__(self, classid):
self.threadlocal = threading.local()
self.classid = classid
def send(self, command):
try:
mvu = self.threadlocal.mvu
except AttributeError:
pythoncom.CoInitialize()
mvu = win32com.client.Dispatch(self.classid)
self.threadlocal.mvu = mvu
args = [
win32com.client.VARIANT(pythoncom.VT_BYREF | pythoncom.VT_BSTR, command),
win32com.client.VARIANT(pythoncom.VT_BYREF | pythoncom.VT_BSTR, ""), # reply
win32com.client.VARIANT(pythoncom.VT_BYREF | pythoncom.VT_BSTR, ""), # error
win32com.client.VARIANT(pythoncom.VT_BYREF | pythoncom.VT_I4, 0), # ?
win32com.client.VARIANT(pythoncom.VT_BYREF | pythoncom.VT_I4, 0)] # ?
err = mvu.SendPpmsCommand(*args)
# win32com does invert the order of results!
if err == 0:
# print '<', args[3].value
return args[3].value
if err == 1:
# print '<done'
return "OK"
raise Error('%s on cmd "%s" %s' % (args[2].value.replace('\n', ' '), command,
getattr(args[2], 'value', 'noreply')))
if __name__ == "__main__": # test only
print(QDevice('QD.MULTIVU.PPMS.1').send('LEVEL?'))