From 3d94da983a87cf95e2a393ffd2b51ac4c4bad5ea Mon Sep 17 00:00:00 2001 From: Markus Zolliker Date: Mon, 21 Oct 2019 16:59:23 +0200 Subject: [PATCH] windows interface for the PPMS driver this runs on window systems only Change-Id: I75ea9572981a4d6da2e5b371b709d613578a1e80 Reviewed-on: https://forge.frm2.tum.de/review/c/sine2020/secop/playground/+/21447 Tested-by: JenkinsCodeReview Reviewed-by: Markus Zolliker --- secop_psi/ppmswindows.py | 62 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100755 secop_psi/ppmswindows.py diff --git a/secop_psi/ppmswindows.py b/secop_psi/ppmswindows.py new file mode 100755 index 0000000..25b75f4 --- /dev/null +++ b/secop_psi/ppmswindows.py @@ -0,0 +1,62 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# ***************************************************************************** +# 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 +# ***************************************************************************** +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 '