I want to use the EPlusWth.dll
provided by EnergyPlus, a building energy simulation engine, within Python (EnergyPlus download here, file is located in the preprocess
folder). The goal is to convert a multitude of weather files to the EnergyPlus Weather File format. The functions of the DLL are described here.
For the setup of the code, I followed paxdiablo's answer to this question.
My code looks like this:
import ctypes
from ctypes import byref, c_bool, c_char_p, c_long
conversionDLL = ctypes.WinDLL('C:/[...]/EPlusWth.dll')
conversionPrototype = ctypes.WINFUNCTYPE(
c_bool, # Output type.
c_char_p, c_long, # Input file type and string length.
c_char_p, c_long, # Output file type and string length.
c_char_p, c_long, # Input file name and string length.
c_char_p, c_long, # Output file name and string length.
c_bool, # Output variable ErrorFlag to use. Positive, if an error occurred.
)
conversionApiParams = (
(1, 'strInType ', 'CUSTOM'), (1, 'InTypeLen', 0),
(1, 'strOutType', 'EPW'), (1, 'OutTypeLen', 3),
(1, 'strInFileName', ''), (1, 'InFileNameLen', 0),
(1, 'strOutFileName', ''), (1, 'OutFileNameLen', 0),
(1, 'ErrorFlag ', False),
)
conversionApi = conversionPrototype(('ProcessWeather', conversionDLL), conversionApiParams)
# value = 'yes'
# EPlusWth.SetFixOutOfRangeData(value, len(value))
inputFileType = b'CUSTOM'
outputFileType = b'EPW'
inputFileName = b'C:/[...]/BAS_2035_RCP85_DRY.csv'
outputFileName = b'C:/[...]/BAS_2035_RCP85_DRY.epw'
errorFlag = c_bool(False)
strInType = c_char_p(inputFileType)
strOutType = c_char_p(outputFileType)
strInFileName = c_char_p(inputFileName)
strOutFileName = c_char_p(outputFileName)
InTypeLen = c_long(len(inputFileType))
OutTypeLen = c_long(len(outputFileType))
InFileNameLen = c_long(len(inputFileName))
OutFileNameLen = c_long(len(outputFileName))
conversionApi(
byref(strInType), byref(InTypeLen),
byref(strOutType), byref(OutTypeLen),
byref(strInFileName), byref(InFileNameLen),
byref(strOutFileName), byref(OutFileNameLen),
# byref(errorFlag),
errorFlag,
)
It works (within Python 3.10 32 bit) up to the actual function call. I get this error:
Traceback (most recent call last):
File "C:\[...]\WeatherFilesToEPW.py", line 42, in <module>
conversionApi(
ctypes.ArgumentError: argument 1: <class 'TypeError'>: wrong type
Without byref()
, the error is:
OSError: exception: access violation writing 0x00000000
Without knowing the difference, I've used c_wchar_p
before instead of c_char_p
. Didn't work, either.
Thanks for your help.
I tried using a DLL to convert custom weather files to the EnergyPlus EPW format. I was expecting a converted output file and an error flag.