0
down vote
favorite
i need to write some data to a HDF5 file, i have a list of objects of the class “OPC_UA” inside a “BV” class, i want to create a dataset with the name of the BV and inside the dataset i want to have the list of the “OPC_UA” objects, tha OPC_UA Class have 3 attributes, a Long int ,one float value and a Datetime that i will convert to a timestamp, i can’t seem to make it work, the Marshal.SizeOf() doesn’t work with classes but i cant do it as a struct… Here is my code:
public void CriaHDF5Customizado(PackingConfigFile pf)
{
H5FileId fileId = H5F.create(“pmdfq.h5”, H5F.CreateMode.ACC_TRUNC);
H5GroupId infoGroupId = H5G.create(fileId, "informations");
H5G.close(infoGroupId);
H5GroupId datasetGroupId = H5G.create(fileId, "datasets");
long[] dims = new long[1];
foreach(BasicVariable bv in pf.basicVariableList.bvList)
{
OPC_UA aux = new OPC_UA();
var xx = bv.bvData;
int tamanho = Marshal.SizeOf(typeof(OPC_UA));
dims[0] = (long)bv.bvData.Count;
// dims[1] = (long)4;
H5DataSpaceId spaceId = H5S.create(H5S.H5SClass.SCALAR);
H5DataTypeId dataTypeId = H5T.create(H5T.CreateClass.COMPOUND, Marshal.SizeOf(typeof(OPC_UA)));
H5T.insert(dataTypeId, "TimeStamp", 0, new H5DataTypeId(H5T.H5Type.NATIVE_UINT));
H5T.insert(dataTypeId, "Quality", Marshal.SizeOf(H5T.H5Type.NATIVE_UINT), new H5DataTypeId(H5T.H5Type.NATIVE_UINT));
H5T.insert(dataTypeId, "Value", 2* Marshal.SizeOf(H5T.H5Type.NATIVE_UINT), new H5DataTypeId(H5T.H5Type.NATIVE_INT));
H5DataSetId dataSetId = H5D.create(datasetGroupId, bv.bvTag, dataTypeId, spaceId);
//H5D.write(dataSetId, new H5DataTypeId(H5T.H5Type.STD_REF_OBJ), new H5Array<OPC_UA>(bv.bvData.ToArray()));
H5D.writeScalar(dataSetId, dataTypeId, ref xx);
H5D.close(dataSetId);
}
H5G.close(datasetGroupId);
H5F.close(fileId);
}
And this is the OPC UA Class
public class OPC_UA
{
public DateTime timeStamp { get; set; }
public string data { get; set; }
public Int64 quality { get; set; }
public OPC_UA(DateTime? ts = null ,string dt = "",Int64 qlt = -99)
{
if (!ts.HasValue)
{
timeStamp = DateTime.Now;
}
data = dt;
quality = qlt;
}