[Equest-users] A method for reading result from DOE2/eQUEST by calling function in D2Result.dll

Nicholas Caton via Equest-users equest-users at lists.onebuilding.org
Mon Dec 5 08:16:55 PST 2016


In the event it isn’t apparent, I felt it may be worthwhile to flag there’s a concurrent discussion with unique answers containing additional approaches here:

https://unmethours.com/question/21135/how-to-load-d2resultdll-from-equestdoe-2/

I myself aspire to join the ranks of those leveraging d2result.dll via Python for some of the tools/processes I’ve been tinkering with.  Jeremy Lerond has shared some extremely helpful-looking scripts along these lines to help other Python’ers getting started here: https://github.com/lymereJ/DOE-2-eQUEST-Sim-Output-Retrieval-w-Python


~Nick

[cid:image001.png at 01D24EDC.517A8000]
Nick Caton, P.E., BEMP
  Senior Energy Engineer
  Energy and Sustainability Services
  Schneider Electric

D  913.564.6361
M  785.410.3317
E  nicholas.caton at schneider-electric.com<mailto:nicholas.caton at schneider-electric.com>
F  913.564.6380

15200 Santa Fe Trail Drive
Suite 204
Lenexa, KS 66219
United States

[cid:image001.png at 01D189AB.58634A10]



From: Equest-users [mailto:equest-users-bounces at lists.onebuilding.org] On Behalf Of Chris Jones via Equest-users
Sent: Wednesday, November 30, 2016 7:15 AM
To: zhaoyongqing1987 <zhaoyongqing1987 at 126.com>; Daric Adair via Equest-users <equest-users at lists.onebuilding.org>
Subject: Re: [Equest-users] A method for reading result from DOE2/eQUEST by calling function in D2Result.dll

Thank you!


Christopher Jones, P. Eng.
Rowan Williams Davies & Irwin Inc.
Consulting Engineers & Scientists
901 King Street West, Suite 400, Toronto, Ontario, M5V 3H5
T: (519) 823-1311 ext 2052
M: (416) 697-0056

From: zhaoyongqing1987 [mailto:zhaoyongqing1987 at 126.com]
Sent: Tuesday, November 29, 2016 11:44 PM
To: Chris Jones; Daric Adair via Equest-users
Subject: Re: RE: [Equest-users] A method for reading result from DOE2/eQUEST by calling function in D2Result.dll


Below is VBA version:

Public Declare PtrSafe Function D2R_VBGetSingleResultsing Lib "doe22\dll32.ref\D2Result.dll" Alias "D2R_VBGetSingleResult" (ByVal a As String, _
    ByVal b As String, _
    ByVal c As LongPtr, _
    ByRef d As Single, _
    ByVal e As LongPtr, _
    ByVal f As String, _
    ByVal g As String _
) As LongPtr

Dim fReslt As Single
pszDoe = "doe22\exent.ref\"
pszFileName = "Project 10\Project 10 - Baseline Design"
iEntryID = 2001001
D2R_VBGetSingleResultsing pszDoe, pszFileName, iEntryID, fReslt, 1, "", ""
Sheet1.Cells(1, 1).Value = fReslt


On 11/25/2016 20:58, Chris Jones <Christopher.Jones at RWDI.com<mailto:Christopher.Jones at RWDI.com>> wrote:
Thanks for this example.

I have wondered if anyone has used the VB version within an Excel application?


Christopher Jones, P. Eng.
Rowan Williams Davies & Irwin Inc.
Consulting Engineers & Scientists
901 King Street West, Suite 400, Toronto, Ontario, M5V 3H5
T: (519) 823-1311 ext 2052
M: (416) 697-0056

From: Equest-users [mailto:equest-users-bounces at lists.onebuilding.org<mailto:equest-users-bounces at lists.onebuilding.org>] On Behalf Of zhaoyongqing1987 via Equest-users
Sent: Friday, November 25, 2016 4:36 AM
To: equest-users
Subject: [Equest-users] A method for reading result from DOE2/eQUEST by calling function in D2Result.dll

I share a method for reading result from DOE2/eQUEST by calling function in D2Result.dll.
Before run the program,you must the D2Result.dll to your project folder.Below is the source code for c#.
-------------------------------------------------------------------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;

namespace ConsoleApplication1
{

    [StructLayout(LayoutKind.Sequential,Pack=4)]
    public struct MultResultsType
    {
        public int  iEntryID;      // from NHRList.txt
        public int  iReturnValue;  // success/failure
        [MarshalAs(UnmanagedType.ByValTStr,SizeConst =40)]
        public string pszReportKey;
        [MarshalAs(UnmanagedType.ByValTStr,SizeConst = 40)]
        public string pszRowKey;
    }
    class Program
    {
        [DllImport("kernel32.dll")]
        public extern static IntPtr LoadLibrary(string dllToLoad);
        [DllImport("kernel32.dll", EntryPoint = "GetProcAddress")]
        public extern static IntPtr GetProcAddress(IntPtr hModule, string procedureName);
        [DllImport("kernel32.dll", EntryPoint = "FreeLibrary")]
        public extern static bool FreeLibrary(IntPtr hModule);
        [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
        private delegate long D2R_GetSingleResult([MarshalAs(UnmanagedType.LPStr)]string pszDOE2Dir,
            [MarshalAs(UnmanagedType.LPStr)]string pszFileName,
            int iEntryID,
            float[] pfData,
            int iMaxValues,
            [MarshalAs(UnmanagedType.LPStr)]string pszReportKey,
            [MarshalAs(UnmanagedType.LPStr)]string pszRowKey);

        private delegate long D2R_GetMultipleResult([MarshalAs(UnmanagedType.LPStr)]string pszDOE2Dir,
            [MarshalAs(UnmanagedType.LPStr)]string pszFileName,
            int iFileType,
            //[MarshalAs(UnmanagedType.LPArray)]
            float[] pfData,
            int iMaxValues,
            int iNumMRTs,
            [In,Out]IntPtr pMRTs);

        unsafe public static  IntPtr MarshalArray(ref MultResultsType[] bodies)
        {
            int iSizeOfOneBodyPos = Marshal.SizeOf(typeof(MultResultsType));
            int iTotalSize = iSizeOfOneBodyPos * bodies.Length;
            IntPtr pUnmanagedBodies = Marshal.AllocHGlobal(iTotalSize);
            byte* pbyUnmanagedBodies = (byte*)(pUnmanagedBodies.ToPointer());

            for (int i = 0; i < bodies.Length; i++, pbyUnmanagedBodies += (iSizeOfOneBodyPos))
            {
                IntPtr pOneBodyPos = new IntPtr(pbyUnmanagedBodies);
                Marshal.StructureToPtr(bodies[i], pOneBodyPos, false);
            }

            return pUnmanagedBodies;
        }

        static void Main(string[] args)
        {
            // Dynamically Load Library
            var pDll = LoadLibrary("D2Result.dll"); // Path to D2Result.dll
            // Get Address of Function
            var pFunctionAddress = GetProcAddress(pDll, "D2R_GetMultipleResult");
            // Instantiate Delegate
            D2R_GetMultipleResult D2R_GetMultipleResult = (D2R_GetMultipleResult)Marshal.GetDelegateForFunctionPointer(pFunctionAddress, typeof(D2R_GetMultipleResult));

            string pszDOE2Dir = "doe22\\exent.ref\\"; // Insert path to DOE-2 Dir i.e "C:\\DOE-2\\
            string pszFileName = "Project 10\\Project 10 - Baseline Design"; // Insert file path of where the input and run files are kept

            float[] pfData = new float[1] ;
            //string pszReportKey = null;
            //string pszRowKey = null;
            MultResultsType[] MRTs=new MultResultsType[4];
            MRTs[0].iEntryID = 2309007;    // EM1 array from PS-F
            MRTs[0].pszReportKey = "EM1";
            MRTs[0].pszRowKey = "";

            MRTs[1].iEntryID = 2309007;    // EM2 array from PS-F
            MRTs[1].pszReportKey = "EM1";
            MRTs[1].pszRowKey = "";

            MRTs[2].iEntryID = 2305005;    // Elec Mtr Totals from PS-E
            MRTs[2].pszReportKey = "";
            MRTs[2].pszRowKey = "";
            IntPtr pt = MarshalArray(ref MRTs);
            float[] fResults=new float[39];
            long lRetVal = D2R_GetMultipleResult(
                                 pszDOE2Dir,
                                 pszFileName,
                                 1, fResults, 39, 3, pt);


           // long result = getSingleResult(pszDOE2Dir, pszFileName, iEntryID, pfData, iMaxValues, pszReportKey, pszRowKey);
            for (int i = 0; i < 39;i++ )
                Console.WriteLine("pfData is {0}", fResults[i]);

            bool freedom = FreeLibrary(pDll);

            Console.ReadKey();
        }
    }
}






________________________________
RWDI - One of Canada's 50 Best Managed Companies - This communication is intended for the sole use of the party to whom it was addressed and may contain information that is privileged and/or confidential. Any other distribution, copying or disclosure is strictly prohibited. If you received this email in error, please notify us immediately by replying to this email and delete the message without retaining any hard or electronic copies of same. Outgoing emails are scanned for viruses, but no warranty is made to their absence in this email or attachments. If you require any information supplied by RWDI in a different format to facilitate accessibility, contact the sender of the email, email solutions at rwdi.com<mailto:solutions at rwdi.com> or call +1.519.823.1311.
________________________________

________________________________
RWDI - One of Canada's 50 Best Managed Companies - This communication is intended for the sole use of the party to whom it was addressed and may contain information that is privileged and/or confidential. Any other distribution, copying or disclosure is strictly prohibited. If you received this email in error, please notify us immediately by replying to this email and delete the message without retaining any hard or electronic copies of same. Outgoing emails are scanned for viruses, but no warranty is made to their absence in this email or attachments. If you require any information supplied by RWDI in a different format to facilitate accessibility, contact the sender of the email, email solutions at rwdi.com<mailto:solutions at rwdi.com> or call +1.519.823.1311.
________________________________

______________________________________________________________________
This email has been scanned by the Symantec Email Security.cloud service.
______________________________________________________________________
________________________________
This message was scanned by Exchange Online Protection Services.
________________________________
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.onebuilding.org/pipermail/equest-users-onebuilding.org/attachments/20161205/f5039ea7/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image001.png
Type: image/png
Size: 255 bytes
Desc: image001.png
URL: <http://lists.onebuilding.org/pipermail/equest-users-onebuilding.org/attachments/20161205/f5039ea7/attachment.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image002.png
Type: image/png
Size: 7893 bytes
Desc: image002.png
URL: <http://lists.onebuilding.org/pipermail/equest-users-onebuilding.org/attachments/20161205/f5039ea7/attachment-0001.png>


More information about the Equest-users mailing list