Exemplo n.º 1
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);
            }
        }