private static AddressDoubleVqt[] toAddressAddressDoubleVqts(IntPtr pData, int iDataLength, int iParamCount) { //int double int long == 24 if (iDataLength < iParamCount * 24) { return(null); } //byte[] bs = new byte[iDataLength]; //Marshal.Copy(pData, bs, 0, iDataLength); AddressDoubleVqt[] values = new AddressDoubleVqt[iParamCount]; long lTemp; int iOffset = 0; for (int i = 0; i < iParamCount; i++) { values[i].address = Marshal.ReadInt32(pData, iOffset); iOffset += 4; lTemp = Marshal.ReadInt64(pData, iOffset); iOffset += 8; values[i].value = BitConverter.Int64BitsToDouble(lTemp); values[i].quality = Marshal.ReadInt32(pData, iOffset); iOffset += 4; long dt = Marshal.ReadInt64(pData, iOffset); iOffset += 8; if (dt > MinMsepoch && dt < MaxMsepoch) { values[i].datetime = msepochToDateTime(dt); } } //ptr = (IntPtr)(((long)ptr) + perf_object_type.TotalByteLength); return(values); }
//new at 20160510 by oudream //读实时数据以散列方式:遥测、模拟量 //* @param inOutYc :输入与输出结构体,输入时存放有Mid字段值,即 address;输出时带有查询结果数据信息 //* @return : 0:什么都没发生,函数空白; >0 :表示成功读了多少个;; <0 :表示错误; public static int GetAddressDoubleVqt(ref AddressDoubleVqt inOutYc) { //byte[] datas = new byte[vqt.Length * 24]; int r = 0; int iMidCount = 1; int iDataLength = iMidCount * 24; IntPtr pnt = IntPtr.Zero; pnt = Marshal.AllocHGlobal(iDataLength); int iOffset = 0; try { long lTemp; Marshal.WriteInt32(pnt, iOffset, inOutYc.address); iOffset += 4; lTemp = BitConverter.DoubleToInt64Bits(inOutYc.value); Marshal.WriteInt64(pnt, iOffset, lTemp); iOffset += 8; Marshal.WriteInt32(pnt, iOffset, inOutYc.quality); iOffset += 4; Marshal.WriteInt64(pnt, iOffset, getMsepoch(inOutYc.datetime)); iOffset += 8; r = gci_realtime_data_get_list(0x0101021C, pnt, iDataLength, iMidCount, IntPtr.Zero); if (r > 0) { AddressDoubleVqt[] ycs = toAddressAddressDoubleVqts(pnt, iDataLength, iMidCount); if (ycs != null && ycs.Length > 0) { inOutYc = ycs[0]; } } } finally { Marshal.FreeHGlobal(pnt); } return(r); }