Skip to content

Instantly share code, notes, and snippets.

@zhukovgreen
Created May 24, 2017 08:18
Show Gist options
  • Save zhukovgreen/57fc430614f1a3bf701dffe8aafcba02 to your computer and use it in GitHub Desktop.
Save zhukovgreen/57fc430614f1a3bf701dffe8aafcba02 to your computer and use it in GitHub Desktop.
import os
from ctypes import *
from msl.loadlib import Server32
#from comtypes import BSTR
class Heatex32(Server32):
"""
class created by the 32bit process to wrap 32bit DLL which is called from 64bit Python
"""
PLATE_NAMES_BUF_SIZE = 60_000_000
def __init__(self, host, port, quiet):
super(Heatex32, self).__init__(
os.path.join(os.path.dirname(__file__), '_resources', 'heatex32'),
'windll',
host, port, quiet)
def GET_CALCULATION(self, s1, s2, IN, KEY):
_IN = ARRAY(c_double, 20)(*IN)
OUT = ARRAY(c_double, 50)()
z1 = ARRAY(c_ubyte, 1)()
z2 = ARRAY(c_ubyte, 1)()
_KEY = c_char_p(KEY.encode())
self.lib.GET_CALCULATION(c_ubyte(s1), c_ubyte(s2), _IN, _KEY, z1, z2,
OUT)
return z1[0], z2[0], [x for x in OUT]
def GET_WHEELCALC(self, s1, s2, IN, KEY):
_IN = ARRAY(c_double, 20)(*IN)
OUT = ARRAY(c_double, 52)() # [Ver 5.12] increase in size to 52
_s1 = ARRAY(c_ubyte, 1)(s1)
_s2 = ARRAY(c_ubyte, 1)(s2)
z1 = ARRAY(c_ubyte, 1)()
z2 = ARRAY(c_ubyte, 1)()
_KEY = c_char_p(KEY.encode())
self.lib.GET_WHEELCALC(_s1, _s2, _IN, _KEY, z1, z2, OUT)
return z1[0], z2[0], [x for x in OUT]
def GET_PRICE(self, s1, s2, IN, KEY):
_IN = ARRAY(c_double, 20)(*IN)
OUT = ARRAY(c_double, 50)()
z1 = ARRAY(c_ubyte, 1)()
z2 = ARRAY(c_ubyte, 1)()
_KEY = c_char_p(KEY.encode())
CODE = create_string_buffer(2048)
self.lib.GET_PRICE(c_ubyte(s1), c_ubyte(s2), _IN, _KEY, z1, z2, OUT,
CODE)
return z1[0], z2[0], [x for x in OUT], CODE.value.decode()
def GET_WHEELPRICE(self, s1, s2, IN, KEY):
_IN = ARRAY(c_double, 20)(*IN)
OUT = ARRAY(c_double, 50)()
z1 = ARRAY(c_ubyte, 1)()
z2 = ARRAY(c_ubyte, 1)()
_KEY = c_char_p(KEY.encode())
CODE = create_string_buffer(2048)
self.lib.GET_WHEELPRICE(c_ubyte(s1), c_ubyte(s2), _IN, _KEY, z1, z2,
OUT, CODE)
return z1[0], z2[0], [x for x in OUT], CODE.value.decode()
def GET_CALCULATIONALLVB6(self, IN, WarmOrCold, TypePlate, ParametersIn,
SelectionIn):
_IN = ARRAY(c_double, 20)(*IN)
_WarmOrCold = c_ubyte(WarmOrCold)
PlateNames = create_string_buffer(__class__.PLATE_NAMES_BUF_SIZE)
_ParametersIn = ARRAY(c_double, 6)(*ParametersIn)
_TypePlate = c_char_p(TypePlate.encode())
_SelectionIn = ARRAY(c_double, 4)(*SelectionIn)
self.lib.GET_CALCULATIONALLVB6.restype = c_int
retval = self.lib.GET_CALCULATIONALLVB6(_IN, PlateNames, _WarmOrCold,
_TypePlate, _ParametersIn,
_SelectionIn)
# make the splitting and data conversion before 32bit->64bit HTTP transport
plates = []
for plate_section in PlateNames.value.decode().split('_'):
if len(plate_section):
P = plate_section.split(';')
plates.append([P[0]]+[float(x) for x in P[1:]])
return retval, plates
def GET_WHEELCALCALLVB6(self, IN, Materials, WarmOrCold, ParametersIn, SelectionIn):
_IN = ARRAY(c_double, 13)(*IN)
_WarmOrCold = c_ubyte(WarmOrCold)
_Materials = c_char_p(Materials.encode())
Rotors = create_string_buffer(__class__.PLATE_NAMES_BUF_SIZE)
_ParametersIn = ARRAY(c_double, 7)(*ParametersIn)
_SelectionIn = ARRAY(c_double, 12)(*SelectionIn)
self.lib.GET_CALCULATIONALLVB6.restype = c_int
# Declare Sub Get_WheelCalcAll Lib "HEATEX32.DLL" Alias "GET_WHEELCALCALLVB6" _
# (heatexin As Double, ByVal Materiale$, ByVal Rotors$, WarmOrCold As Byte,
# ParametersIn As Double, Selection As Double)
retval = self.lib.GET_WHEELCALCALLVB6(_IN, _Materials, Rotors, _WarmOrCold,
_ParametersIn, _SelectionIn)
# make the splitting and data conversion before 32bit->64bit HTTP transport
rotors = []
for rotor_section in Rotors.value.decode().split('_'):
if len(rotor_section):
R = rotor_section.split(';')
rotors.append([R[0]]+[float(x) for x in R[1:]])
return retval, rotors
# def GET_CALCULATIONALL(self, IN, WarmOrCold, TypePlate, ParametersIn,
# SelectionIn):
# _IN = ARRAY(c_double, 20)(*IN)
# _WarmOrCold = c_ubyte(WarmOrCold)
# PlateNames = pointer(BSTR(' '*60000000))
# _ParametersIn = ARRAY(c_double, 6)(*ParametersIn)
# _TypePlate = pointer(BSTR(TypePlate))
# _SelectionIn = ARRAY(c_double, 4)(*SelectionIn)
# self.lib.GET_CALCULATIONALL.restype = c_int
#
# # print('___ _TypePlate:', _TypePlate, _TypePlate.contents,
# # _TypePlate.contents.value)
# # print('___ PlateNames:', PlateNames, PlateNames.contents,
# # PlateNames.contents.value)
#
# retval = self.lib.GET_CALCULATIONALL(_IN, PlateNames, _WarmOrCold,
# _TypePlate, _ParametersIn,
# _SelectionIn)
#
# print('___ _TypePlate:', _TypePlate, _TypePlate.contents,
# _TypePlate.contents.value)
# print('___ PlateNames:', PlateNames, PlateNames.contents,
# PlateNames.contents.value)
#
# return retval, PlateNames.contents.value
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment