private static AddressInt32Vqt[] toAddressInt32Vqts(IntPtr pData, int iDataLength, int iParamCount) { //int int int long == 20 if (iDataLength < iParamCount * 20) { return(null); } //byte[] bs = new byte[iDataLength]; //Marshal.Copy(pData, bs, 0, iDataLength); AddressInt32Vqt[] values = new AddressInt32Vqt[iParamCount]; int iOffset = 0; for (int i = 0; i < iParamCount; i++) { values[i].address = Marshal.ReadInt32(pData, iOffset); iOffset += 4; values[i].value = Marshal.ReadInt32(pData, iOffset); iOffset += 4; 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 20160511 by oudream //读实时数据以散列方式:遥信、开关量、状态 //* @param inOutYx :输入与输出结构体,输入时存放有Mid字段值,即 address;输出时带有查询结果数据信息 //* @return : 0:什么都没发生,函数空白; >0 :表示成功读了多少个;; <0 :表示错误; public static int GetAddressInt32Vqt(ref AddressInt32Vqt inOutYx) { //byte[] datas = new byte[vqt.Length * 20]; int r = 0; int iMidCount = 1; int iDataLength = iMidCount * 20; IntPtr pnt = IntPtr.Zero; pnt = Marshal.AllocHGlobal(iDataLength); int iOffset = 0; try { Marshal.WriteInt32(pnt, iOffset, inOutYx.address); iOffset += 4; Marshal.WriteInt32(pnt, iOffset, inOutYx.value); iOffset += 4; Marshal.WriteInt32(pnt, iOffset, inOutYx.quality); iOffset += 4; Marshal.WriteInt64(pnt, iOffset, getMsepoch(inOutYx.datetime)); iOffset += 8; r = gci_realtime_data_get_list(0x01010203, pnt, iDataLength, iMidCount, IntPtr.Zero); if (r > 0) { AddressInt32Vqt[] yxs = toAddressInt32Vqts(pnt, iDataLength, iMidCount); if (yxs != null && yxs.Length > 0) { inOutYx = yxs[0]; } } } finally { Marshal.FreeHGlobal(pnt); } return(r); }