private static AddressVqtString128[] toAddressVqtString128s(IntPtr pData, int iDataLength, int iParamCount) { //int sbyte[128] int long == 144 if (iDataLength < iParamCount * 144) { return(null); } //byte[] bs = new byte[iDataLength]; //Marshal.Copy(pData, bs, 0, iDataLength); AddressVqtString128[] values = new AddressVqtString128[iParamCount]; int iOffset = 0; for (int i = 0; i < iParamCount; i++) { values[i].address = Marshal.ReadInt32(pData, iOffset); iOffset += 4; values[i].value = assignToString(pData, iOffset, 127); iOffset += 128; 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 inOutYw :输入与输出结构体,输入时存放有Mid字段值,即 address;输出时带有查询结果数据信息 //* @return : 0:什么都没发生,函数空白; >0 :表示成功读了多少个;; <0 :表示错误; public static int GetAddressVqtString128(ref AddressVqtString128 inOutYw) { //byte[] datas = new byte[vqt.Length * 144]; int r = 0; int iMidCount = 1; int iDataLength = iMidCount * 144; IntPtr pnt = IntPtr.Zero; pnt = Marshal.AllocHGlobal(iDataLength); int iOffset = 0; try { Marshal.WriteInt32(pnt, iOffset, inOutYw.address); iOffset += 4; byte[] value = System.Text.Encoding.UTF8.GetBytes(inOutYw.value); for (int j = 0; j < 128; j++) { if (j < value.Length) { Marshal.WriteByte(pnt, iOffset, value[j]); iOffset += 1; } else { Marshal.WriteByte(pnt, iOffset, 0); iOffset += 1; } } Marshal.WriteInt32(pnt, iOffset, inOutYw.quality); iOffset += 4; Marshal.WriteInt64(pnt, iOffset, getMsepoch(inOutYw.datetime)); iOffset += 8; r = gci_realtime_data_get_list(0x0101022F, pnt, iDataLength, iMidCount, IntPtr.Zero); if (r > 0) { AddressVqtString128[] yws = toAddressVqtString128s(pnt, iDataLength, iMidCount); if (yws != null && yws.Length > 0) { inOutYw = yws[0]; } } } finally { Marshal.FreeHGlobal(pnt); } return(r); }