ctypes calling delphi dll
Brian Elmegaard
brian at rk-speed.rugby.dk
Wed Dec 18 10:16:58 EST 2002
Brian Elmegaard <brian at rk-speed.rugby.dk> writes:
> Thomas Heller <theller at python.net> writes:
>
> > and it seems to work. It prints 'R11'. Is this what you expected?
>
> Yep. Thanks a lot for the help.
And now I got it all working, but have written the code below in the
best possible way? I don't think it is much easier to read than the
C-code example, I am copying.
#import the library
import ctypes
c_double=ctypes.c_double
c_float=ctypes.c_float
byref=ctypes.byref
#load the dll
RefrigC=ctypes.cdll.RefrigC
#instantiate a refrigerant name
AName=ctypes.c_string("\0"*200)
RefrigC.SetRNumber("R134a")
RefrigC.GetRNumber(AName)
print "Refrigerant : %7s" %AName.value
print "-------------------------"
#Declare the return type of the functions
RefrigC.PDewT.restype='f'
RefrigC.TDewP.restype='f'
ps = RefrigC.PDewT(c_double(273.15))
ts = RefrigC.TDewP(c_double(ps))
print "PDew [bar] : %.3f"%(ps/1e5)
print "TDew [C] : %.3f"%(ts-273.15)
print "-------------------------"
RefrigC.SDewT.restype='f'
ss = RefrigC.SDewT(c_double(ts))
tsnew=c_double()
vs=c_double()
RefrigC.TVSP(c_double(ss),
c_double(ps),
byref(tsnew),
byref(vs))
print "SS [kJ/kgK] : %.3f"%(ss/1000)
print "TSNew [C] : %.3f"%(tsnew.value-273.15)
print "PSNew [bar] : %.3f"%(ps/1e5)
print "VSNew [m^3/kg] : %.6f"%vs.value
Brian
More information about the Python-list
mailing list