Utgard - Trying to implement OPC HDA

56 views
Skip to first unread message

Anderson Vasconcelos Pires

unread,
Jul 4, 2016, 10:54:08 PM7/4/16
to openSCADA
Hi Guys,

I am trying to implement the OPC HDA communication. I am connecting, reading the historian status, adding items, reading at Time (readAtTime) but I cannot readRaw and readProcessed. Maybe you guys can help me. If it works will be a pleasure to supply the source code to this great project and availability to the community.

Follow some part of the code. If it is necessary more information, let me know.



    HRESULT ReadRaw (
    [in, out] OPCHDA_TIME *htStartTime,
    [in, out] OPCHDA_TIME *htEndTime,
    [in] DWORD dwNumValues,
    [in] BOOL bBounds,
    [in] DWORD dwNumItems,
    [in, size_is(dwNumItems)] OPCHANDLE * phServer,
    [out, size_is(,dwNumItems)] OPCHDA_ITEM ** ppItemValues,
    [out, size_is(,dwNumItems)] HRESULT ** ppErrors
    );

public void readRaw(int numValues, boolean bounds, OPCHDATIME startDate, OPCHDATIME endDate, Integer[] serverHandles) throws JIException
    {
    JICallBuilder builder = new JICallBuilder(true);
    builder.reInit();
        builder.setOpnum(0);

        builder.addInParamAsPointer(new JIPointer(startDate.getStruct(), true), JIFlags.FLAG_NULL);
        builder.addOutParamAsObject(new JIPointer(OPCHDATIME.GetStruct()), JIFlags.FLAG_NULL);
        builder.addInParamAsPointer(new JIPointer(endDate.getStruct(), true), JIFlags.FLAG_NULL);
        builder.addOutParamAsObject(new JIPointer(OPCHDATIME.GetStruct()), JIFlags.FLAG_NULL);

        builder.addInParamAsInt(numValues, JIFlags.FLAG_NULL);
        builder.addInParamAsInt(bounds?1:0, JIFlags.FLAG_NULL);
        builder.addInParamAsInt(serverHandles.length, JIFlags.FLAG_NULL);
        builder.addInParamAsArray(new JIArray(serverHandles, true), JIFlags.FLAG_NULL);

        builder.addOutParamAsObject(new JIPointer(new JIArray(OPCHDAITEM.GetStruct(), null, 1,true)),JIFlags.FLAG_NULL);
        builder.addOutParamAsObject(new JIPointer(new JIArray(Integer.class, null, 1, true)), JIFlags.FLAG_NULL);

        Object[] result = Helper.callRespectSFALSE(getCOMObject(), builder);
}


    /*
     *      HRESULT ReadAtTime (
    [in] DWORD dwNumTimeStamps,
    [in, size_is(dwNumTimeStamps)] FILETIME *ftTimeStamps,
    [in] DWORD dwNumItems,
    [in, size_is(dwNumItems)] OPCHANDLE * phServer,
    [out, size_is(,dwNumItems)] OPCHDA_ITEM ** ppItemValues,
    [out, size_is(,dwNumItems)] HRESULT ** ppErrors
    );
     */

//This code works.    
public ResultSet<OPCHDAITEM> readAtTime(FILETIME[] timeStamp, Integer[] serverHandles) throws JIException
    {
        if (timeStamp.length != serverHandles.length)
            throw new JIException (0, "Array sizes don't match");

    JICallBuilder builder = new JICallBuilder(true);
    builder.reInit();
        builder.setOpnum(2);

        JIStruct[] v_Time = new JIStruct[timeStamp.length];

        for (int i = 0; i < timeStamp.length; i++)
        {
        v_Time[i] = timeStamp[i].getValue();
        }

        builder.addInParamAsInt(timeStamp.length, JIFlags.FLAG_NULL);
        builder.addInParamAsArray(new JIArray(v_Time, true), JIFlags.FLAG_NULL);
        builder.addInParamAsInt(serverHandles.length, JIFlags.FLAG_NULL);
        builder.addInParamAsArray(new JIArray(serverHandles, true), JIFlags.FLAG_NULL);
        builder.addOutParamAsObject(new JIPointer(new JIArray(OPCHDAITEM.GetStruct(), null, 1,true)),JIFlags.FLAG_NULL);
        builder.addOutParamAsObject(new JIPointer(new JIArray(Integer.class, null, 1, true)), JIFlags.FLAG_NULL);

        Object[] result = Helper.callRespectSFALSE(getCOMObject(), builder);
}

////
public class OPCHDATIME
{
Boolean m_IsString;
String m_TimeString;
FILETIME m_Time;

public OPCHDATIME (String p_Date)
{
this (true, p_Date, null);

m_Time = new FILETIME();
m_Time.setLow(0);
m_Time.setHigh(0);
}

public OPCHDATIME (FILETIME p_Date)
{
this (false, "", p_Date);
}

private OPCHDATIME (Boolean p_IsString, String p_TimeString, FILETIME p_Time)
{
m_IsString = p_IsString;
m_TimeString = p_TimeString;
m_Time = p_Time;
}

/*
typedef struct {
BOOL bString;
[string] LPWSTR szTime;
FILETIME ftTime;
} OPCHDA_TIME;

*/
public JIStruct getStruct () throws JIException
    {
        JIStruct v_Struct = new JIStruct ();

        v_Struct.addMember(m_IsString ? 1 : 0);
        v_Struct.addMember(new JIString(m_TimeString, JIFlags.FLAG_REPRESENTATION_STRING_LPWSTR));
        v_Struct.addMember(m_Time.getValue());

        return v_Struct;
    }

    public static JIStruct GetStruct () throws JIException
    {
        JIStruct v_Struct = new JIStruct ();

        v_Struct.addMember(Integer.class);
        v_Struct.addMember(new JIString(JIFlags.FLAG_REPRESENTATION_STRING_LPWSTR));
        v_Struct.addMember(FILETIME.getStruct());

        return v_Struct;
    }
}


fabrizio gerina

unread,
Jan 31, 2018, 6:36:21 AM1/31/18
to openSCADA
Hi Anderson,

do you have some news about this amazing project?

Best Regards

Fabrizio

Anderson Vasconcelos Pires

unread,
Feb 2, 2018, 6:41:22 PM2/2/18
to open...@googlegroups.com
Hi Fabrizio, 

I dont have any news about this. Actually, I gave up and implement an gateway. 

Best regards,
Anderson. 

--
You received this message because you are subscribed to a topic in the Google Groups "openSCADA" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/openscada/PnOiGcqgiyw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to openscada+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages