|
你好,请按照如下代码替换winformdemo工程下对应文件中的接口,然后再测试一下接收 GPS 数据的显示。- GPS 数据接收:
- 1、EventHandler.cs 文件:
- void GpsDialog_OnData(IntPtr dialog, IntPtr pGpsData, Int32 len)
- {
- if (IntPtr.Zero == pGpsData) return;
- BVCU_PUCFG_GPSData gpsData = (BVCU_PUCFG_GPSData)Marshal.PtrToStructure(pGpsData, typeof(BVCU_PUCFG_GPSData));
- m_dialog.onGpsData(dialog, gpsData, len);
- }
- 2、Dialog.cs 文件:
- delegate void OnGetGpsData(IntPtr dialog, BVCU_PUCFG_GPSData gpsData, Int32 len);
- OnGetGpsData deleGetGpsData;
- public void onGpsData(IntPtr dialog, BVCU_PUCFG_GPSData gpsData, Int32 len)
- {
- if(null != m_mainForm && m_mainForm.IsHandleCreated)
- {
- if (null == deleGetGpsData)
- {
- deleGetGpsData = new OnGetGpsData(procGetGpsData);
- }
- m_mainForm.BeginInvoke(deleGetGpsData, new object[] { dialog, gpsData, len });
- }
- }
- void procGetGpsData(IntPtr dialog, BVCU_PUCFG_GPSData gpsData, int len)
- {
- foreach (OneDialog dlg in m_gpsDialogs)
- {
- if (dlg.dialogHandle == dialog)
- {
- if(null != m_mainForm)
- {
- m_mainForm.onGetGpsData(dlg.pu.id, gpsData, len);
- }
- return;
- }
- }
- }
- 3、MainWinForm.cs文件:
- /// <summary>
- /// 获得Gps数据
- /// </summary>
- public void onGetGpsData(string puId, BVCU_PUCFG_GPSData gpsData, Int32 len)
- {
- foreach (ListViewItem item in listViewGPSData.Items)
- {
- if (item.Text.Equals(puId, StringComparison.CurrentCultureIgnoreCase))
- {
- float lat = 0;
- float lng = 0;
- ListViewItem.ListViewSubItem latItem = new ListViewItem.ListViewSubItem();
- lat = (float)gpsData.iLatitude / BVCU.BVCU_LAT_LNG_UNIT;
- lng = (float)gpsData.iLongitude / BVCU.BVCU_LAT_LNG_UNIT;
- latItem.Text = lat.ToString("0.00000");
- item.SubItems[1] = latItem;
- ListViewItem.ListViewSubItem lngItem = new ListViewItem.ListViewSubItem();
- lngItem.Text = lng.ToString("0.00000");
- item.SubItems[2] = lngItem;
- LogHelper.LogHelper.RecordLog(8, string.Format("({0}, {1})", lat.ToString("0.00000"), lng.ToString("0.00000")));
- return;
- }
- }
- }
copycode
|
|