private unsafe HRESULT CodeSpec(byte *memStream, uint size) { switch (mDecoderStatus) { case kStatus.Finished: return(HRESULT.S_OK); case kStatus.Error: return(HRESULT.S_FALSE); case kStatus.NeedInit: //_inStream.Init(); if (!PPMD.Ppmd7z_RangeDec_Init(mRangeDecoder)) { mDecoderStatus = kStatus.Error; return(HRESULT.S_FALSE); } mDecoderStatus = kStatus.Normal; PPMD.Ppmd7_Init(mState, mSettingOrder); break; } /* if (mLength.HasValue) */ { var rem = mLength - mPosition; if (size > rem) { size = (uint)rem; } } uint i; int sym = 0; for (i = 0; i != size; i++) { sym = PPMD.Ppmd7_DecodeSymbol(mState, mRangeDecoder); if (mExceededInput || sym < 0) { break; } memStream[i] = (byte)sym; } mPosition += i; if (mExceededInput) { mDecoderStatus = kStatus.Error; return(HRESULT.E_FAIL); } if (sym < 0) { mDecoderStatus = (sym < -1) ? kStatus.Error : kStatus.Finished; } return(HRESULT.S_OK); }
public bool DisConnect(ref string errMsg) { try { state = GoSdkWrapper.GoSystem_Disconnect(go_system); if (state != kStatus.kOK) { errMsg = string.Format("GoSystem_DisConnect Error:{0}", state); return(false); } return(true); } catch (Exception ex) { errMsg = string.Format("GoSystem_DisConnect Error:{0}", ex.Message); return(false); } }
public bool CutJob(string jobName, ref string errMsg) { try { state = GoSdkWrapper.GoSensor_CopyFile(go_sensor, jobName + ".job", "_live.job"); if (state != kStatus.kOK) { errMsg = string.Format("GoSensor_CopyFile Error:{0}", state); return(false); } return(true); } catch (Exception ex) { errMsg = string.Format("GoSensor_CopyFile Error:{0}", ex.Message); return(false); } }
public bool Stop(ref string errMsg) { try { state = GoSdkWrapper.GoSystem_Stop(go_system); if (state != kStatus.kOK) { errMsg = string.Format("GoSystem_Stop Error:{0}", state); return(false); } ProfileRecFinish?.Invoke(); MeasurementRecFinish?.Invoke(); return(true); } catch (Exception ex) { errMsg = string.Format("GoSystem_Stop Error:{0}", ex.Message); return(false); } }
public bool Download3dFile(string destpath, ref string errMsg) { try { state = GoSdkWrapper.GoSensor_DownloadFile(go_sensor, "_live.job", destpath + ".job"); if (state != kStatus.kOK) { errMsg = string.Format("GoSensor_DownloadJob Error:{0}", state); return(false); } state = GoSdkWrapper.GoSensor_DownloadFile(go_sensor, "_live.rec", destpath + ".rec"); if (state != kStatus.kOK) { errMsg = string.Format("GoSensor_DownloadRec Error:{0}", state); return(false); } return(true); } catch (Exception ex) { errMsg = string.Format("GoSensor_DownloadFile Error:{0}", ex.Message); return(false); } }
public bool connect(ref string errMsg) { if (gocatorIp != null) { state = GoSdkWrapper.GoSdk_Construct(ref go_api); if (state != kStatus.kOK) { errMsg = string.Format("GoSystem_Construct Error:{0}", state); return(false); } state = GoSdkWrapper.GoSystem_Construct(ref go_system, IntPtr.Zero); if (state != kStatus.kOK) { errMsg = string.Format("GoSystem_Construct Error:{0}", state); return(false); } addrPtr = Marshal.AllocHGlobal(Marshal.SizeOf(addr)); Marshal.StructureToPtr(addr, addrPtr, false); state = GoSdkWrapper.kIpAddress_Parse(addrPtr, gocatorIp); if (state != kStatus.kOK) { errMsg = string.Format("kIpAddress_Parse Error:{0}", state); return(false); } state = GoSdkWrapper.GoSystem_FindSensorByIpAddress(go_system, addrPtr, ref go_sensor); if (state != kStatus.kOK) { errMsg = string.Format("GoSystem_FindSensorByIpAddress Error:{0}", state); return(false); } state = GoSdkWrapper.GoSystem_Connect(go_system); if (state != kStatus.kOK) { errMsg = string.Format("GoSystem_Connect Error:{0}", state); return(false); } state = GoSdkWrapper.GoSystem_EnableData(go_system, true); if (state != kStatus.kOK) { errMsg = string.Format("GoSystem_EnableData Error:{0}", state); return(false); } Setup = GoSdkWrapper.GoSensor_Setup(go_sensor); zRange = GoSdkWrapper.GoSetup_ActiveAreaHeight(Setup, GoRole.GO_ROLE_MAIN); z_byte_resolution = 255 / zRange; zStart = GoSdkWrapper.GoSetup_ActiveAreaZ(Setup, GoRole.GO_ROLE_MAIN); ondatatype = new onDataType(OnData); state = GoSdkWrapper.GoSystem_SetDataHandler(go_system, ondatatype, context); GC.KeepAlive(ondatatype); if (state != kStatus.kOK) { errMsg = string.Format("GoSystem_SetDataHandler Error:{0}", state); return(false); } profileDataZ = new List <Profile>(); measurementDataList = new List <MeasurementData>(); #region 加密模块 SecretKey.License l = new SecretKey.License("license.dat", expirationTime, isStartCheck, tel); l.GocatorId = GoSdkWrapper.GoSensor_Id(go_sensor).ToString(); l.Warn(warnStartDay, warnTime); #endregion context.serialNumber = GoSdkWrapper.GoSensor_Id(go_sensor); GoRole role = GoRole.GO_ROLE_MAIN; //context.yResolution =(double) GoSdkWrapper.GoSetup_YSpacingCount(Setup, role); context.yResolution = GoSdkWrapper.GoSetup_EncoderSpacing(Setup); context.xResolution = Math.Round(GoSdkWrapper.GoSetup_SpacingIntervalSystemValue(Setup, role), 3); return(true); } else { errMsg = "Gocator ip is Empty"; return(false); } }
private unsafe HRESULT CodeSpec(byte* memStream, uint size) { switch (mDecoderStatus) { case kStatus.Finished: return HRESULT.S_OK; case kStatus.Error: return HRESULT.S_FALSE; case kStatus.NeedInit: //_inStream.Init(); if (!PPMD.Ppmd7z_RangeDec_Init(mRangeDecoder)) { mDecoderStatus = kStatus.Error; return HRESULT.S_FALSE; } mDecoderStatus = kStatus.Normal; PPMD.Ppmd7_Init(mState, mSettingOrder); break; } /* if (mLength.HasValue) */ { var rem = mLength - mPosition; if (size > rem) size = (uint)rem; } uint i; int sym = 0; for (i = 0; i != size; i++) { sym = PPMD.Ppmd7_DecodeSymbol(mState, mRangeDecoder); if (mExceededInput || sym < 0) break; memStream[i] = (byte)sym; } mPosition += i; if (mExceededInput) { mDecoderStatus = kStatus.Error; return HRESULT.E_FAIL; } if (sym < 0) mDecoderStatus = (sym < -1) ? kStatus.Error : kStatus.Finished; return HRESULT.S_OK; }
public void Stop() { Stopwatch sw = new Stopwatch(); sw.Start(); if ((status = (kStatus)GoDestroy(dataset)) != kStatus.kOK) throw new Exception(("GoDestroy Error: " + (int)status)); if ((status = (kStatus)GoSystem_Stop(system)) != kStatus.kOK) throw new Exception(("GoSystem_Stop Error: " + (int)status)); sw.Stop(); Console.WriteLine("Time to stop Gocator: {0}", sw.Elapsed); }
/// <summary> /// Starts the scanner and returns the surface /// </summary> /// <returns> /// 0 = success, errors codes can be found in gocator manual /// -1 general error /// </returns> public SurfaceData GetSurfaceData() { Stopwatch sw1 = new Stopwatch(); sw1.Start(); SurfaceData surfaceData = new SurfaceData(); if ((status = (kStatus)GoSystem_Start(system)) != kStatus.kOK) throw new Exception("GoSystem_Start Error: " +(int)status); while ((status = (kStatus)GoSystem_ReceiveData(system, ref dataset, 2000000)) != kStatus.kOK) ; if (GoDataSet_Count(dataset) == 0) throw new Exception("GoSystem_ReceiveData Error: Data received, but it was empty. Check ethernet output settings."); // each result can have multiple data items // loop through all items in result message for (UInt32 i = 0; i < GoDataSet_Count(dataset); i++) { dataObj = GoDataSet_At(dataset, i); // retrieve GoStamp message if (GoDataMsg_Type(dataObj) == GoDataMessageTypes.GO_DATA_MESSAGE_TYPE_STAMP) { stampMsg = dataObj; for (UInt32 j = 0; j < GoStampMsg_Count(stampMsg); j++) { stampPtr = GoStampMsg_At(stampMsg, j); stamp = (GoStamp)Marshal.PtrToStructure(stampPtr, typeof(GoStamp)); surfaceData.Stamp = stamp; } } // retrieve surface data if (GoDataMsg_Type(dataObj) == GoDataMessageTypes.GO_DATA_MESSAGE_TYPE_SURFACE) { surfaceMsg = dataObj; surfaceData.SurfaceInfo.Width = GoSurfaceMsg_Width(surfaceMsg); surfaceData.SurfaceInfo.Height = GoSurfaceMsg_Length(surfaceMsg); surfaceData.SurfaceInfo.XResolution = GoSurfaceMsg_XResolution(surfaceMsg); surfaceData.SurfaceInfo.YResolution = GoSurfaceMsg_YResolution(surfaceMsg); surfaceData.SurfaceInfo.XOffset = GoSurfaceMsg_XOffset(surfaceMsg); surfaceData.SurfaceInfo.YOffset = GoSurfaceMsg_YOffset(surfaceMsg); surfaceData.SurfaceInfo.ZOffset = GoSurfaceMsg_ZOffset(surfaceMsg); surfaceData.SurfaceInfo.ZResolution = GoSurfaceMsg_ZResolution(surfaceMsg); UInt32 bufferSize = surfaceData.SurfaceInfo.Width * surfaceData.SurfaceInfo.Height; IntPtr bufferPointer = GoSurfaceMsg_RowAt(surfaceMsg, 0); surfaceData.ranges = new short[bufferSize]; Marshal.Copy(bufferPointer, surfaceData.ranges, 0, surfaceData.ranges.Length); Stopwatch sw = new Stopwatch(); sw.Start(); for (int j = 0; j < bufferSize; j++) { // surfaceData.ranges[j] = (short)(surfaceData.SurfaceInfo.ZOffset + surfaceData.ranges[j] * surfaceData.SurfaceInfo.ZResolution); surfaceData.ranges[j] = (short)(Math.Pow(2, 15) - Math.Abs((int)surfaceData.ranges[j])); } sw.Stop(); Console.WriteLine("Time to transform data: {0}", sw.Elapsed); sw.Stop(); Console.WriteLine("Time to transform data: {0}", sw.ElapsedMilliseconds); } // retrieve surface data if (GoDataMsg_Type(dataObj) == GoDataMessageTypes.GO_DATA_MESSAGE_TYPE_SURFACE_INTENSITY) { surfaceMsg = dataObj; surfaceData.SurfaceIntensityInfo.Width = GoSurfaceIntensityMsg_Width(surfaceMsg); surfaceData.SurfaceIntensityInfo.Height = GoSurfaceIntensityMsg_Length(surfaceMsg); surfaceData.SurfaceIntensityInfo.XResolution = GoSurfaceIntensityMsg_XResolution(surfaceMsg); surfaceData.SurfaceIntensityInfo.YResolution = GoSurfaceIntensityMsg_YResolution(surfaceMsg); surfaceData.SurfaceIntensityInfo.XOffset = GoSurfaceIntensityMsg_XOffset(surfaceMsg); surfaceData.SurfaceIntensityInfo.YOffset = GoSurfaceIntensityMsg_YOffset(surfaceMsg); UInt32 bufferSize = surfaceData.SurfaceIntensityInfo.Width * surfaceData.SurfaceIntensityInfo.Height; IntPtr bufferPointer = GoSurfaceIntensityMsg_RowAt(surfaceMsg, 0); //short[] ranges = new short[bufferSize]; surfaceData.intensities = new byte[bufferSize]; Marshal.Copy(bufferPointer, surfaceData.intensities, 0, surfaceData.intensities.Length); } } sw1.Stop(); Console.WriteLine("Time to get all data: {0}", sw1.Elapsed); return surfaceData; }
/// <summary> /// Constructs GoSdk and GoSystem. Sets up pointers to unmanaged memory, finds and connects to sensor /// </summary> /// <param name="sensorIP">IP of Gocator Sensor</param> /// <returns>1 = success /// >1 = fail code /// -1 = Error: GoSensor_Setup: Invalid Handle /// </returns> public void ConfigureGocator(string sensorIP) { if ((status = (kStatus)GoSdk_Construct(ref api)) != kStatus.kOK) { throw new Exception("GoSdk_Construct Error: " + (int)status); } if ((status = (kStatus)GoSystem_Construct(ref system, IntPtr.Zero)) != kStatus.kOK) { throw new Exception("GoSystem_Construct Error: " + (int)status); } addrPtr = Marshal.AllocHGlobal(Marshal.SizeOf(addr)); Marshal.StructureToPtr(addr, addrPtr, false); if ((status = (kStatus)kIpAddress_Parse(addrPtr, SENSOR_IP)) != kStatus.kOK) { throw new Exception("kIpAddress_Parse Error: " + (int)status); } if ((status = (kStatus)GoSystem_FindSensorByIpAddress(system, addrPtr, ref sensor)) != kStatus.kOK) { throw new Exception("GoSystem_FindSensorByIpAddress Error: " + (int)status); } if ((status = (kStatus)GoSensor_Connect(sensor)) != kStatus.kOK) { throw new Exception("GoSensor_Connect Error: " + (int)status); } if ((status = (kStatus)GoSystem_EnableData(system, true)) != kStatus.kOK) { throw new Exception("GoSystem_EnableData Error: " + (int)status); } if ((setup = GoSensor_Setup(sensor)) == null) { throw new Exception("GoSensor_Setup Error: Invalid Handle"); } this.Stop(); if ((status = (kStatus)GoSetup_SetScanMode(setup, GoMode.GO_MODE_SURFACE)) != kStatus.kOK) { throw new Exception("GoSetup_SetScanMode Error: " + (int)status); } }