Beispiel #1
0
        public long GetSensorEncode()
        {
            long encode = 0;

            GoSdkWrapper.GoSensor_Encoder(go_sensor, ref encode);
            return(encode);
        }
Beispiel #2
0
 public bool IsConnected(ref string errMsg)
 {
     //设置掉线报警
     if (go_sensor == IntPtr.Zero)
     {
         return(false);
     }
     return(GoSdkWrapper.GoSensor_IsConnected(go_sensor));
 }
Beispiel #3
0
 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);
     }
 }
Beispiel #4
0
 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);
     }
 }
Beispiel #5
0
 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);
     }
 }
Beispiel #6
0
 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);
     }
 }
Beispiel #7
0
        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);
            }
        }
Beispiel #8
0
        private int OnData(DataContext ctx, IntPtr sys, IntPtr data)
        {
            if (!SecretKey.License.SnOk)
            {
                string errMsg  = "";
                string warnMsg = "传感器试用权限已到期,传感器将停止接收数据,如有疑问请联系:" + tel;
                if (DisConnect(ref errMsg))
                {
                    warnMsg += " !";
                }
                MessageBox.Show(warnMsg);
                return(0);
            }

            if (!IsOnline)
            {
                GoSdkWrapper.GoDestroy(data);
                //GC.Collect();
                return(1);
            }

            IntPtr dataObj = IntPtr.Zero;

            IntPtr  StampMsg = IntPtr.Zero;
            IntPtr  StampPtr = IntPtr.Zero;
            GoStamp stamp    = new GoStamp();

            IntPtr  ProfileMsgZ = IntPtr.Zero;
            Profile mProfile    = new Profile();

            IntPtr ProfileMsgIntensity = IntPtr.Zero;

            IntPtr SurfaceMsgZ         = IntPtr.Zero;
            IntPtr SurfaceMsgIntensity = IntPtr.Zero;

            IntPtr          MeasurementMsg  = IntPtr.Zero;
            MeasurementData measurementData = new MeasurementData();
            bool            isRecSurfaceZOK = false;

            for (uint i = 0; i < GoSdkWrapper.GoDataSet_Count(data); i++)
            {
                dataObj = GoSdkWrapper.GoDataSet_At(data, i);
                switch (GoSdkWrapper.GoDataMsg_Type(dataObj))
                {
                case GoDataMessageTypes.GO_DATA_MESSAGE_TYPE_STAMP:
                    StampMsg = dataObj;
                    StampPtr = GoSdkWrapper.GoStampMsg_At(StampMsg, 0);

                    stamp = (GoStamp)Marshal.PtrToStructure(StampPtr, typeof(GoStamp));
                    //if (stamp.encoder == 0)
                    //{
                    //    stamp.encoder = 0;
                    //}
                    Stamp            = stamp;
                    mProfile.encoder = stamp.encoder;

                    break;

                case GoDataMessageTypes.GO_DATA_MESSAGE_TYPE_SURFACE:

                    SurfaceMsgZ     = dataObj;
                    ctx.xResolution = (double)GoSdkWrapper.GoSurfaceMsg_XResolution(SurfaceMsgZ) / 1000000;
                    ctx.zResolution = (double)GoSdkWrapper.GoSurfaceMsg_ZResolution(SurfaceMsgZ) / 1000000;
                    ctx.yResolution = (double)GoSdkWrapper.GoSurfaceMsg_YResolution(SurfaceMsgZ) / 1000000;
                    ctx.xOffset     = (double)GoSdkWrapper.GoSurfaceMsg_XOffset(SurfaceMsgZ) / 1000;
                    ctx.yOffset     = (double)GoSdkWrapper.GoSurfaceMsg_YOffset(SurfaceMsgZ) / 1000;
                    ctx.zOffset     = (double)GoSdkWrapper.GoSurfaceMsg_ZOffset(SurfaceMsgZ) / 1000;

                    uint    surfaceWidth     = GoSdkWrapper.GoSurfaceMsg_Width(SurfaceMsgZ);
                    uint    surfaceHeight    = GoSdkWrapper.GoSurfaceMsg_Length(SurfaceMsgZ);
                    IntPtr  surfacePtr       = GoSdkWrapper.GoSurfaceMsg_RowAt(SurfaceMsgZ, 0);
                    short[] surfacePoints    = new short[surfaceWidth * surfaceHeight];
                    float[] surfaceData      = new float[surfaceWidth * surfaceHeight];
                    float[] surfaceDataX     = new float[surfaceWidth * surfaceHeight];
                    float[] surfaceDataY     = new float[surfaceWidth * surfaceHeight];
                    byte[]  surfaceDataZByte = new byte[surfaceWidth * surfaceHeight];

                    //保存Kdat
                    Stopwatch sp = new Stopwatch();
                    sp.Start();

                    //if (surfacePoints.Length==0)
                    //{
                    //    break;
                    //}
                    try
                    {
                        Marshal.Copy(surfacePtr, surfacePoints, 0, surfacePoints.Length);
                    }
                    catch (Exception)
                    {
                        return(1);
                    }


                    //保存dat
                    //if (SaveDatFileDirectory != null && !string.IsNullOrEmpty(SaveDatFileDirectory))
                    //{
                    //    PointMsg pmoffset = new PointMsg() { x = ctx.xOffset, y = ctx.yOffset, z = ctx.zOffset };
                    //    PointMsg pmscale = new PointMsg() { x = ctx.xResolution, y = ctx.yResolution, z = ctx.zResolution };
                    //    SurfaceZSaveDat ssd = new SurfaceZSaveDat() { points = surfacePoints, resolution = pmscale, offset = pmoffset,width = (int)surfaceWidth,height = (int)surfaceHeight };
                    //    StaticTool.WriteSerializable($"{SaveDatFileDirectory}Side{RunSide}_H.dat", ssd);
                    //}

                    PointMsg pmoffset = new PointMsg()
                    {
                        x = ctx.xOffset, y = ctx.yOffset, z = ctx.zOffset
                    };
                    PointMsg pmscale = new PointMsg()
                    {
                        x = ctx.xResolution, y = ctx.yResolution, z = ctx.zResolution
                    };
                    SurfaceZSaveDat ssd = new SurfaceZSaveDat()
                    {
                        points = surfacePoints, resolution = pmscale, offset = pmoffset, width = (int)surfaceWidth, height = (int)surfaceHeight
                    };
                    if (!isRecSurfaceZOK)
                    {
                        if (SaveDatFileDirectory != null && !string.IsNullOrEmpty(SaveDatFileDirectory))
                        {
                            StaticTool.WriteSerializable($"{SaveDatFileDirectory}Side{RunSide}_L_H.dat", ssd);
                        }
                        sddList_L.Add(ssd);
                        if (SaveKdatDirectoy != null && !string.IsNullOrEmpty(SaveKdatDirectoy) && RunSide != null)
                        {
                            Point3d64f poffset = new Point3d64f()
                            {
                                x = ctx.xOffset, y = ctx.yOffset, z = ctx.zOffset
                            };
                            Point3d64f pscale = new Point3d64f()
                            {
                                x = ctx.xResolution, y = ctx.yResolution, z = ctx.zResolution
                            };
                            GoSurface insurface = new GoSurface()
                            {
                                data = surfacePtr, width = (int)surfaceWidth, height = (int)surfaceHeight, offset = poffset, scale = pscale
                            };
                            GoSaveSurfaceGraphic.SaveSufaceToFile($"{SaveKdatDirectoy}{DateTime.Now.ToString("yyyyMMdd_HHmmss")}_Side{RunSide}_L.kdat", ref insurface, false);
                        }
                    }
                    else
                    {
                        //保存dat
                        if (SaveDatFileDirectory != null && !string.IsNullOrEmpty(SaveDatFileDirectory))
                        {
                            //PointMsg pmoffset = new PointMsg() { x = ctx.xOffset, y = ctx.yOffset, z = ctx.zOffset };
                            //PointMsg pmscale = new PointMsg() { x = ctx.xResolution, y = ctx.yResolution, z = ctx.zResolution };
                            //SurfaceZSaveDat ssd = new SurfaceZSaveDat() { points = surfacePoints, resolution = pmscale, offset = pmoffset, width = (int)surfaceWidth, height = (int)surfaceHeight };
                            StaticTool.WriteSerializable($"{SaveDatFileDirectory}Side{RunSide}_S_H.dat", ssd);
                        }
                        sddList_S.Add(ssd);
                        if (SaveKdatDirectoy != null && !string.IsNullOrEmpty(SaveKdatDirectoy) && RunSide != null)
                        {
                            Point3d64f poffset = new Point3d64f()
                            {
                                x = ctx.xOffset, y = ctx.yOffset, z = ctx.zOffset
                            };
                            Point3d64f pscale = new Point3d64f()
                            {
                                x = ctx.xResolution, y = ctx.yResolution, z = ctx.zResolution
                            };
                            GoSurface insurface = new GoSurface()
                            {
                                data = surfacePtr, width = (int)surfaceWidth, height = (int)surfaceHeight, offset = poffset, scale = pscale
                            };
                            GoSaveSurfaceGraphic.SaveSufaceToFile($"{SaveKdatDirectoy}{DateTime.Now.ToString("yyyyMMdd_HHmmss")}_Side{RunSide}_S.kdat", ref insurface, false);
                        }
                    }
                    sp.Stop();
                    long b = sp.ElapsedMilliseconds;
                    sp.Start();

                    for (int j = 0; j < surfaceHeight; j++)
                    {
                        for (int k = 0; k < surfaceWidth; k++)
                        {
                            surfaceData[j * surfaceWidth + k]  = surfacePoints[j * surfaceWidth + k] == -32768 ? -12 : (float)(ctx.zOffset + ctx.zResolution * surfacePoints[j * surfaceWidth + k]);
                            surfaceDataX[j * surfaceWidth + k] = (float)(ctx.xOffset + ctx.xResolution * k);
                            surfaceDataY[j * surfaceWidth + k] = (float)(ctx.yOffset + ctx.yResolution * j);
                            if (IsRecSurfaceDataZByte && (!isRecSurfaceZOK))
                            {
                                if (surfacePoints[j * surfaceWidth + k] != -32768)
                                {
                                    surfaceDataZByte[j * surfaceWidth + k] = (byte)Math.Ceiling(((ctx.zOffset + ctx.zResolution * surfacePoints[j * surfaceWidth + k]) - zStart) * z_byte_resolution);
                                }
                                else
                                {
                                    surfaceDataZByte[j * surfaceWidth + k] = 0;
                                }
                            }
                        }
                    }
                    sp.Stop();
                    long a = sp.ElapsedMilliseconds;
                    if (!isRecSurfaceZOK)
                    {
                        this.SurfaceWidth     = surfaceWidth;
                        this.SurfaceHeight    = surfaceHeight;
                        this.SurfaceDataZ     = surfaceData;
                        this.SurfaceDataZByte = surfaceDataZByte;
                        this.surfaceDataX     = surfaceDataX;
                        this.surfaceDataY     = surfaceDataY;
                        isRecSurfaceZOK       = true;
                    }
                    else
                    {
                        this.SurfaceAlignData   = surfaceData;
                        this.SurfaceAlignWidth  = surfaceWidth;
                        this.SurfaceAlignHeight = surfaceHeight;
                    }


                    break;

                case GoDataMessageTypes.GO_DATA_MESSAGE_TYPE_SURFACE_INTENSITY:
                    SurfaceMsgIntensity = dataObj;
                    IntPtr intensityPtr = GoSdkWrapper.GoSurfaceIntensityMsg_RowAt(SurfaceMsgIntensity, 0);
                    surfaceWidth  = GoSdkWrapper.GoSurfaceIntensityMsg_Width(SurfaceMsgIntensity);
                    surfaceHeight = GoSdkWrapper.GoSurfaceIntensityMsg_Length(SurfaceMsgIntensity);
                    byte[] intensityArr = new byte[surfaceWidth * surfaceHeight];
                    Marshal.Copy(intensityPtr, intensityArr, 0, intensityArr.Length);
                    SurfaceDataIntensity = intensityArr;
                    SurfaceIntensitySaveDat sid = new SurfaceIntensitySaveDat()
                    {
                        points = intensityArr, width = (int)surfaceWidth, height = (int)surfaceHeight
                    };
                    if (SaveDatFileDirectory != null && !string.IsNullOrEmpty(SaveDatFileDirectory))
                    {
                        StaticTool.WriteSerializable($"{SaveDatFileDirectory}Side{RunSide}_I.dat", sid);
                    }
                    sddList_I.Add(sid);
                    break;

                case GoDataMessageTypes.GO_DATA_MESSAGE_TYPE_RESAMPLED_PROFILE:
                    if (!EnableProfle)
                    {
                        break;
                    }
                    ProfileMsgZ     = dataObj;
                    ctx.xResolution = ((double)GoSdkWrapper.GoProfileMsg_XResolution(ProfileMsgZ)) / 1000000;
                    ctx.zResolution = ((double)GoSdkWrapper.GoProfileMsg_ZResolution(ProfileMsgZ)) / 1000000;
                    ctx.xOffset     = ((double)GoSdkWrapper.GoProfileMsg_XOffset(ProfileMsgZ)) / 1000;
                    ctx.zOffset     = ((double)GoSdkWrapper.GoProfileMsg_ZOffset(ProfileMsgZ)) / 1000;
                    profileWidth    = GoSdkWrapper.GoProfileMsg_Width(ProfileMsgZ);

                    IntPtr  pointPtr = GoSdkWrapper.GoResampledProfileMsg_At(ProfileMsgZ, 0);
                    short[] points   = new short[profileWidth];
                    Marshal.Copy(pointPtr, points, 0, points.Length);
                    ProfilePoint[] profile = new ProfilePoint[profileWidth];
                    for (int j = 0; j < points.Length; j++)
                    {
                        profile[j].x = (float)(ctx.xOffset + ctx.xResolution * j);
                        profile[j].z = points[j] == -32768 ? -12 : (float)(ctx.zOffset + ctx.zResolution * points[j]);
                    }
                    mProfile.points = profile;
                    isRecProfileZ   = true;
                    break;

                case GoDataMessageTypes.GO_DATA_MESSAGE_TYPE_PROFILE_INTENSITY:
                    if (isRecProfileZ)
                    {
                        ProfileMsgIntensity = dataObj;
                        profileWidth        = GoSdkWrapper.GoProfileIntensityMsg_Width(ProfileMsgIntensity);
                        IntPtr profileIntensityPtr = GoSdkWrapper.GoProfileIntensityMsg_At(ProfileMsgIntensity, 0);
                        byte[] profileIntensityArr = new byte[profileWidth];
                        Marshal.Copy(profileIntensityPtr, profileIntensityArr, 0, profileIntensityArr.Length);
                        for (int j = 0; j < profileIntensityArr.Length; j++)
                        {
                            mProfile.points[j].Intensity = profileIntensityArr[j];
                        }
                    }
                    break;

                case GoDataMessageTypes.GO_DATA_MESSAGE_TYPE_MEASUREMENT:
                    MeasurementMsg = dataObj;
                    IntPtr            measurementPtr = GoSdkWrapper.GoMeasurementMsg_At(MeasurementMsg, 0);
                    GoMeasurementData mData          = (GoMeasurementData)Marshal.PtrToStructure(measurementPtr, typeof(GoMeasurementData));
                    measurementData.id    = GoSdkWrapper.GoMeasurementMsg_Id(MeasurementMsg);
                    measurementData.value = mData.Value;
                    measurementDataList.Add(measurementData);
                    break;

                default:
                    break;
                }
            }
            if (isRecProfileZ)
            {
                profileDataZ.Add(mProfile);
                this.SigleProfile = mProfile;
                isRecProfileZ     = false;
            }
            GoSdkWrapper.GoDestroy(data);
            //GC.Collect();
            return(1);
        }