コード例 #1
0
        /// <summary>
        /// initialize /Connect sensor
        /// </summary>
        /// <returns></returns>
        public bool  Go_Init_Sensor()
        {
            bool rtn = false;

            try
            {
                KApiLib.Construct();
                GoSdkLib.Construct();
                system_main = new GoSystem();
                accelerator = new GoAccelerator();
                accelerator.Start();
                KIpAddress ipAddress = KIpAddress.Parse(SENSOR_MAIN_IP);
                sensor_main = system_main.FindSensorByIpAddress(ipAddress);
                accelerator.Attach(sensor_main);
                sensor_main.Connect();
                system_main.EnableData(true);
                system_main.SetDataHandler(AsyncReceiveData);
                system_main.Start();
            }
            catch (Exception ex)
            {
                rtn = true;
            }

            return(rtn);
        }
コード例 #2
0
ファイル: Generator.cs プロジェクト: ilikeyml/AVLTest
        void initialApi()
        {
            KApiLib.Construct();
            GoSdkLib.Construct();
            KIpAddress addr = KIpAddress.Parse(IPAddr);

            _system = new GoSystem();

            _sensor = _system.FindSensorByIpAddress(addr);
            _system.Connect();

            if (_sensor.State == GoState.Ready)
            {
                _context.Post(delegate
                {
                    richTextBox1.AppendText("Connected" + Environment.NewLine);
                }, null);
            }
            else
            {
                _context.Post(delegate
                {
                    richTextBox1.AppendText(@"Connect failed" + Environment.NewLine);
                }, null);
            }



            _system.EnableData(true);
            _system.SetDataHandler(OnDataReceived);
        }
コード例 #3
0
        static int Main(string[] args)
        {
            try
            {
                KApiLib.Construct();
                GoSdkLib.Construct();
                GoSystem  system = new GoSystem();
                GoSensor  sensor;
                GoDataSet dataSet = new GoDataSet();

                KIpAddress ipAddress = KIpAddress.Parse(Constants.SENSOR_IP);
                sensor = system.FindSensorByIpAddress(ipAddress);
                sensor.Connect();
                system.EnableData(true);
                GoSetup setup = sensor.Setup;
                setup.AlignmentType             = GoAlignmentType.Stationary;
                setup.AlignmentStationaryTarget = GoAlignmentTarget.None;
                sensor.Align();
                Console.WriteLine("Waiting for alignment calibration data to be collected...");
                dataSet = system.ReceiveData(30000000);
                for (UInt32 i = 0; i < dataSet.Count; i++)
                {
                    GoAlignMsg dataItem = (GoAlignMsg)dataSet.Get(i);
                    if (dataItem.MessageType == GoDataMessageType.Alignment)
                    {
                        if (dataItem.Status == KStatus.Ok)
                        {
                            Console.WriteLine("Alignment calibration successful!");
                        }
                        else
                        {
                            Console.WriteLine("Alignment calibration failed.");
                        }
                    }
                }
                system.Stop();
            }

            catch (KException ex)
            {
                if (ex.Status == KStatus.ErrorTimeout)
                {
                    Console.WriteLine("Failed to collect data for calibration within timeout limit...");
                }
                else if (ex.Status != KStatus.Ok)
                {
                    Console.WriteLine("Error:{0}", ex.Status);
                }
            }

            // wait for Enter key
            Console.WriteLine("\nPress ENTER to continue");
            do
            {
                System.Threading.Thread.Sleep(100);
            } while (Console.Read() != (int)ConsoleKey.Enter);
            return(1);
        }
コード例 #4
0
ファイル: LmiScanner.cs プロジェクト: wangweiqq/C_Dot_Demo
 /// <summary>
 /// 开始监听拍照数据
 /// </summary>
 public void StartListen()
 {
     if (sensor.IsConnected())
     {
         system.EnableData(true);
         system.SetDataHandler(onData);
         system.Start();
     }
 }
コード例 #5
0
 public bool InitialAcq()
 {
     mSystem = new GoSystem();
     mSensor = mSystem.FindSensorByIpAddress(KIpAddress.Parse(IPAddr));
     DeviceStatusEvent?.Invoke(this, $"Find device @ IP address {IPAddr}");
     mSystem.Connect();
     DeviceStatusEvent?.Invoke(this, $"Connect to {IPAddr}");
     mSystem.EnableData(true);
     mSystem.SetDataHandler(OnData);
     return(true);
 }
コード例 #6
0
ファイル: SetupMeasurement.cs プロジェクト: yikakabu/GO_SDK
        static int Main(string[] args)
        {
            try
            {
                KApiLib.Construct();
                GoSdkLib.Construct();
                GoSystem   system = new GoSystem();
                GoSensor   sensor;
                KIpAddress ipAddress = KIpAddress.Parse(Constants.SENSOR_IP);
                sensor = system.FindSensorByIpAddress(ipAddress);
                sensor.Connect();
                system.EnableData(true);
                //retrieve setup handle
                GoSetup setup = sensor.Setup;
                //retrieve tools handle
                GoTools tools = sensor.Tools;
                // add ProfilePosition tool, retreive tool handle
                GoProfilePosition profilePositionTool = (GoProfilePosition)tools.AddTool(GoToolType.ProfilePosition);
                // set name for tool
                profilePositionTool.Name = "Profile position Test";
                // add Z measurement for ProfilePosition tool
                GoProfilePositionZ zProfileMeasurementTop = profilePositionTool.ZMeasurement;
                zProfileMeasurementTop.Enabled = true;
                zProfileMeasurementTop.Id      = 0;
                //set ProfilePosition feature to top
                GoProfileFeature profileFeature = profilePositionTool.Feature;
                profileFeature.FeatureType = GoProfileFeatureType.MaxZ;
                // set the ROI to fill the entire active area
                GoProfileRegion regionTop = profileFeature.Region;
                regionTop.X      = setup.GetTransformedDataRegionX(GoRole.Main);
                regionTop.Z      = setup.GetTransformedDataRegionZ(GoRole.Main);
                regionTop.Height = setup.GetTransformedDataRegionHeight(GoRole.Main);
                regionTop.Width  = setup.GetTransformedDataRegionWidth(GoRole.Main);
                // enable Ethernet output for measurement tool
                GoOutput   output         = sensor.Output;
                GoEthernet ethernetOutput = output.GetEthernet();
                ethernetOutput.ClearAllSources();
                ethernetOutput.AddSource(GoOutputSource.Measurement, 0);
            }
            catch (KException ex)
            {
                Console.WriteLine("Error: {0}", ex.Status);
            }
            // wait for ESC key
            Console.WriteLine("\nPress ENTER to continue");
            do
            {
                System.Threading.Thread.Sleep(100);
            } while (Console.Read() != (int)ConsoleKey.Enter);

            return(1);
        }
コード例 #7
0
ファイル: LmiLaser.cs プロジェクト: xusongfei/LeadChina
        public bool Disconnect()
        {
            if (FrameworkExtenion.IsSimulate)
            {
                return(true);
            }

            if (sensor == null)
            {
                return(false);
            }

            if (EnableAccelerator)
            {
                //accelerator.Detach(sensor);
                //accelerator.Stop();
                //accelerator.Dispose();
            }

            try
            {
                //sensor.Disconnect();
                //sensor.Dispose();
                //sensor = null;

                system.Stop();
                system.EnableData(false);
                system.Dispose();
                system = null;
            }
            catch (Exception)
            {
                return(false);
            }

            return(true);
        }
コード例 #8
0
        static int Main(string[] args)
        {
            try
            {
                KApiLib.Construct();
                GoSdkLib.Construct();
                GoSystem   system = new GoSystem();
                GoSensor   sensor;
                GoDataSet  healthData = new GoDataSet();
                KIpAddress ipAddress  = KIpAddress.Parse(Constants.SENSOR_IP);
                sensor = system.FindSensorByIpAddress(ipAddress);
                sensor.Connect();
                system.EnableData(true);

                UInt32 i = 1;
                while (i < 10)
                {
                    healthData = system.ReceiveHealth(30000000);
                    for (UInt32 j = 0; j < healthData.Count; j++)
                    {
                        GoHealthMsg healthMsg = (GoHealthMsg)healthData.Get(j);
                        Console.WriteLine("Health message received:");
                        Console.WriteLine(" Number of indicators: {0}", healthMsg.Count);
                        for (UInt32 k = 0; k < healthMsg.Count; k++)
                        {
                            GoIndicator healthIndicator = healthMsg.Get(k);
                            Console.WriteLine(" Indicator[{0}]: Id:{1} Instance:{2} Value{3}", k, healthIndicator.id, healthIndicator.instance, healthIndicator.value);
                        }
                        // Dispose required to prevent memory leak.
                        healthMsg.Dispose();
                    }
                    i++;
                }
            }
            catch (KException ex)
            {
                Console.WriteLine("Error: {0}", ex.Status);
            }

            // wait for Enter key
            Console.WriteLine("\nPress ENTER to continue");
            do
            {
                System.Threading.Thread.Sleep(100);
            } while (Console.Read() != (int)ConsoleKey.Enter);
            return(1);
        }
コード例 #9
0
        /// <summary>
        /// initial api constructor and open data channel
        /// </summary>
        /// <returns></returns>
        public bool InitialDevice()
        {
            try
            {
                KApiLib.Construct();
                GoSdkLib.Construct();
            }
            catch (KException kEx)
            {
                Trace.WriteLine(kEx.ToString());
            }

            _system = new GoSystem();
            KIpAddress kIpAddress = KIpAddress.Parse(IPAddress);

            Trace.WriteLine($"Sonsor IP {IPAddress}");
            _sensor = _system.FindSensorByIpAddress(kIpAddress);
            if (_sensor.State == GoState.Ready)
            {
                _sensor.Connect();
                Trace.WriteLine("Sonsor Connected");
            }
            else
            {
                return(false);
            }
            _system.EnableData(true);
            Trace.WriteLine("Data channel open");

            _system.SetDataHandler(onData);
            if (_sensor.State == GoState.Running)
            {
                _system.Stop();
                _system.Start();
            }
            else
            {
                _system.Start();
                Trace.WriteLine("Sysem Start");
            }


            return(true);
        }
コード例 #10
0
        //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        //생성 :
        //수정 :
        //목적 : 3D 센서( Gocator )
        //설명 :
        //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        public override bool HL3DStart()
        {
            bool bReturn = false;

            do
            {
                try {
                    m_objCameraSystem.EnableData(true);
                    m_objCameraSystem.SetDataHandler(ReceiveData);
                    m_objCameraSystem.Start();
                } catch (Exception ex) {
                    Trace.WriteLine("HL3DStart : " + ex.ToString());
                    break;
                }

                bReturn = true;
            } while(false);
            return(bReturn);
        }
コード例 #11
0
        public void GoSystemConstruct(string IPAddress, long profileCount)
        {
            initialApi();
            _system       = new GoSystem();
            _profileCount = profileCount;
            KIpAddress addr = KIpAddress.Parse(IPAddress);

            _sensor = _system.FindSensorByIpAddress(addr);
            _syncContext.Post(delegate { yRes.Content = profileCount.ToString(); }, null);
            _system.Connect();
            if (_sensor.IsConnected())
            {
                _system.EnableData(true);
                _system.SetDataHandler(OnDataReceived);
                _syncContext.Post(delegate { UpdateMsg("Systeme Construct successfully"); }, null);
            }
            else
            {
                _syncContext.Post(delegate { UpdateMsg("System Construct Failed"); }, null);
            }
        }
コード例 #12
0
        bool initialApi()
        {
            updateMsg("default ip address:" + ipAddr);
            updateMsg("Initial API construct");
            KApiLib.Construct();
            GoSdkLib.Construct();
            _system = new GoSystem();
            KIpAddress addr = KIpAddress.Parse(ipAddr);

            _sensor     = _system.FindSensorByIpAddress(addr);
            _sensorInfo = new GoSensorInfo();
            if (_sensor != null)
            {
                updateMsg("Find Device");
            }
            else
            {
                updateMsg("Device not found");
                return(false);
            }
            _sensor.Connect();
            if (_sensor.IsConnected())
            {
                updateMsg("Sensor Connected");
                string IDStr = _sensor.Id.ToString();

                updateMsg("Sensor ID:" + IDStr);
                _system.EnableData(true);
                updateMsg("Enable Data");
                _sensor.SetDataHandler(OnDataReceived);
                updateMsg("regist data handller");
                updateMsg("Waiting data....");
                string sts = _sensor.State.ToString();
                updateMsg("sensor current state:" + sts);
                return(true);
            }

            return(false);
        }
コード例 #13
0
        public void StartGetPoint()
        {
            if (File.Exists(strFileSave) == true)
            {
                File.Delete(strFileSave);
            }
            length = 0;

            system.EnableData(true);
            system.SetDataHandler(onData);

            try
            {
                sensor.CopyFile("test.job", "_live.job");
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show("请检查相机连接状态");
                return;
            }
            system.Start();
        }
コード例 #14
0
        void goRun()
        {
            try
            {
                KApiLib.Construct();
                GoSdkLib.Construct();
                system = new GoSystem();
                GoSensor   sensor;
                KIpAddress ipAddress = KIpAddress.Parse(IPAddress);
                GoDataSet  dataSet   = new GoDataSet();
                sensor = system.FindSensorByIpAddress(ipAddress);
                sensor.Connect();
                infoTxt.Text = "Conn" + Environment.NewLine;
                GoSetup setup = sensor.Setup;
                setup.ScanMode = GoMode.Surface;

                system.EnableData(true);
                system.SetDataHandler(OnDataReceived);
                infoTxt.Text += "Binding data handler" + Environment.NewLine;

                system.Start();

                infoTxt.Text += "System Started" + Environment.NewLine;
                infoTxt.Text += "Waiting Data" + Environment.NewLine;

                GoActiveAreaConfig goActiveAreaConfig = new GoActiveAreaConfig();



                sensor.Setup.GetActiveAreaLength(GoRole.Main);
                GoSetup set = sensor.Setup;
                setup.

                // wait for Enter key
            }
            catch (KException ex)
            {
            }
        }
コード例 #15
0
        public void Connect()
        {
            try {
                // Gocator 초기화 및 접속 (GoSDK 예제를 참고)
                KApiLib.Construct();
                GoSdkLib.Construct();
                KIpAddress ipAddress;

                // GoSystem 필수
                m_objCameraSystem = new GoSystem();

                ipAddress = KIpAddress.Parse(m_objInitializeParameter.str3DCameraIP);

                m_objCamera = m_objCameraSystem.FindSensorByIpAddress(ipAddress);
                m_objCamera.Connect();

                m_objCameraSystem.EnableData(true);
                m_bConnect = true;
            } catch (Exception ex) {
                Trace.WriteLine("Exception Gocator : " + ex.ToString());
            }
        }
コード例 #16
0
        static int Main(string[] args)
        {
            try
            {
                KApiLib.Construct();
                GoSdkLib.Construct();
                GoSystem   system = new GoSystem();
                GoSensor   sensor;
                KIpAddress ipAddress = KIpAddress.Parse(Constants.SENSOR_IP);
                sensor = system.FindSensorByIpAddress(ipAddress);
                sensor.Connect();
                system.EnableData(true);
                system.SetDataHandler(onData);
                system.Start();

                // wait for Enter key
                Console.WriteLine("\nPress ENTER to stop");
                do
                {
                    //System.Threading.Thread.Sleep(100);
                } while (Console.Read() != (int)ConsoleKey.Enter);
                system.Stop();
            }

            catch (KException ex)
            {
                Console.WriteLine("Error: {0}", ex.Status);
            }

            // wait for Enter key
            Console.WriteLine("\nPress ENTER to continue");
            do
            {
                System.Threading.Thread.Sleep(100);
            } while (Console.Read() != (int)ConsoleKey.Enter);
            return(1);
        }
コード例 #17
0
ファイル: ReceiveProfile.cs プロジェクト: yikakabu/GO_SDK
        static int Main(string[] args)
        {
            try
            {
                KApiLib.Construct();
                GoSdkLib.Construct();
                GoSystem   system = new GoSystem();
                GoSensor   sensor;
                KIpAddress ipAddress = KIpAddress.Parse(Constants.SENSOR_IP);
                GoDataSet  dataSet   = new GoDataSet();
                sensor = system.FindSensorByIpAddress(ipAddress);
                sensor.Connect();
                system.EnableData(true);
                system.Start();
                dataSet = system.ReceiveData(30000000);
                DataContext context = new DataContext();
                for (UInt32 i = 0; i < dataSet.Count; i++)
                {
                    GoDataMsg dataObj = (GoDataMsg)dataSet.Get(i);
                    switch (dataObj.MessageType)
                    {
                    case GoDataMessageType.Stamp:
                    {
                        GoStampMsg stampMsg = (GoStampMsg)dataObj;
                        for (UInt32 j = 0; j < stampMsg.Count; j++)
                        {
                            GoStamp stamp = stampMsg.Get(j);
                            Console.WriteLine("Frame Index = {0}", stamp.FrameIndex);
                            Console.WriteLine("Time Stamp = {0}", stamp.Timestamp);
                            Console.WriteLine("Encoder Value = {0}", stamp.Encoder);
                        }
                    }
                    break;

                    case GoDataMessageType.UniformProfile:
                    {
                        GoResampledProfileMsg profileMsg = (GoResampledProfileMsg)dataObj;
                        Console.WriteLine("  Resampled Profile Message batch count: {0}", profileMsg.Count);
                        for (UInt32 k = 0; k < profileMsg.Count; ++k)
                        {
                            int validPointCount   = 0;
                            int profilePointCount = profileMsg.Width;
                            Console.WriteLine("    Item[{0}]: Profile data ({1} points)", k, profileMsg.Width);
                            context.xResolution = (double)profileMsg.XResolution / 1000000;
                            context.zResolution = (double)profileMsg.ZResolution / 1000000;
                            context.xOffset     = (double)profileMsg.XOffset / 1000;
                            context.zOffset     = (double)profileMsg.ZOffset / 1000;

                            short[]        points        = new short[profilePointCount];
                            ProfilePoint[] profileBuffer = new ProfilePoint[profilePointCount];
                            IntPtr         pointsPtr     = profileMsg.Data;
                            Marshal.Copy(pointsPtr, points, 0, points.Length);

                            for (UInt32 arrayIndex = 0; arrayIndex < profilePointCount; ++arrayIndex)
                            {
                                if (points[arrayIndex] != -32768)
                                {
                                    profileBuffer[arrayIndex].x = context.xOffset + context.xResolution * arrayIndex;
                                    profileBuffer[arrayIndex].z = context.zOffset + context.zResolution * points[arrayIndex];
                                    validPointCount++;
                                }
                                else
                                {
                                    profileBuffer[arrayIndex].x = context.xOffset + context.xResolution * arrayIndex;
                                    profileBuffer[arrayIndex].z = -32768;
                                }
                            }
                            Console.WriteLine("Received {0} Range Points", profilePointCount);
                            Console.WriteLine("Valid Points {0}", validPointCount);
                        }
                    }
                    break;

                    case GoDataMessageType.ProfilePointCloud:
                    {
                        GoProfileMsg profileMsg = (GoProfileMsg)dataObj;
                        Console.WriteLine("  Profile Message batch count: {0}", profileMsg.Count);
                        for (UInt32 k = 0; k < profileMsg.Count; ++k)
                        {
                            int  validPointCount   = 0;
                            long profilePointCount = profileMsg.Width;
                            Console.WriteLine("    Item[{0}]: Profile data ({1} points)", i, profileMsg.Width);
                            context.xResolution = profileMsg.XResolution / 1000000;
                            context.zResolution = profileMsg.ZResolution / 1000000;
                            context.xOffset     = profileMsg.XOffset / 1000;
                            context.zOffset     = profileMsg.ZOffset / 1000;
                            GoPoints[]     points        = new GoPoints[profilePointCount];
                            ProfilePoint[] profileBuffer = new ProfilePoint[profilePointCount];
                            int            structSize    = Marshal.SizeOf(typeof(GoPoints));
                            IntPtr         pointsPtr     = profileMsg.Data;
                            for (UInt32 array = 0; array < profilePointCount; ++array)
                            {
                                IntPtr incPtr = new IntPtr(pointsPtr.ToInt64() + array * structSize);
                                points[array] = (GoPoints)Marshal.PtrToStructure(incPtr, typeof(GoPoints));
                            }

                            for (UInt32 arrayIndex = 0; arrayIndex < profilePointCount; ++arrayIndex)
                            {
                                if (points[arrayIndex].x != -32768)
                                {
                                    profileBuffer[arrayIndex].x = context.xOffset + context.xResolution * points[arrayIndex].x;
                                    profileBuffer[arrayIndex].z = context.xOffset + context.xResolution * points[arrayIndex].y;
                                    validPointCount++;
                                }
                                else
                                {
                                    profileBuffer[arrayIndex].x = -32768;
                                    profileBuffer[arrayIndex].z = -32768;
                                }
                            }
                            Console.WriteLine("Received {0} Range Points", profilePointCount);
                            Console.WriteLine("Valid Points {0}", validPointCount);
                        }
                    }
                    break;

                    case GoDataMessageType.ProfileIntensity:
                    {
                        GoProfileIntensityMsg profileMsg = (GoProfileIntensityMsg)dataObj;
                        Console.WriteLine("  Profile Intensity Message batch count: {0}", profileMsg.Count);
                        for (UInt32 k = 0; k < profileMsg.Count; ++k)
                        {
                            byte[] intensity    = new byte[profileMsg.Width];
                            IntPtr intensityPtr = profileMsg.Data;
                            Marshal.Copy(intensityPtr, intensity, 0, intensity.Length);
                        }
                    }
                    break;
                    }
                }
                system.Stop();
            }
            catch (KException ex)
            {
                Console.WriteLine("Error: {0}", ex.Status);
            }
            // wait for ESC key
            Console.WriteLine("\nPress ENTER to continue");
            do
            {
                System.Threading.Thread.Sleep(100);
            } while (Console.Read() != (int)ConsoleKey.Enter);

            return(1);
        }
コード例 #18
0
        static int Main(string[] args)
        {
            try
            {
                KApiLib.Construct();
                GoSdkLib.Construct();
                GoSystem   system = new GoSystem();
                GoSensor   sensor;
                KIpAddress ipAddress = KIpAddress.Parse(Constants.SENSOR_IP);
                GoDataSet  dataSet   = new GoDataSet();
                sensor = system.FindSensorByIpAddress(ipAddress);
                sensor.Connect();
                system.EnableData(true);
                system.Start();
                // refer to SetupMeasurement.cs for setting up of the measurement tools
                dataSet = system.ReceiveData(30000000);
                for (UInt32 i = 0; i < dataSet.Count; i++)
                {
                    GoDataMsg dataObj = (GoDataMsg)dataSet.Get(i);
                    switch (dataObj.MessageType)
                    {
                    case GoDataMessageType.Stamp:
                    {
                        GoStampMsg stampMsg = (GoStampMsg)dataObj;
                        for (UInt32 j = 0; j < stampMsg.Count; j++)
                        {
                            GoStamp stamp = stampMsg.Get(j);
                            Console.WriteLine("Frame Index = {0}", stamp.FrameIndex);
                            Console.WriteLine("Time Stamp = {0}", stamp.Timestamp);
                            Console.WriteLine("Encoder Value = {0}", stamp.Encoder);
                        }
                    }
                    break;

                    case GoDataMessageType.Measurement:
                    {
                        GoMeasurementMsg measurementMsg = (GoMeasurementMsg)dataObj;
                        for (UInt32 k = 0; k < measurementMsg.Count; ++k)
                        {
                            GoMeasurementData measurementData = measurementMsg.Get(k);
                            Console.WriteLine("ID: {0}", measurementMsg.Id);
                            Console.WriteLine("Value: {0}", measurementData.Value);
                            Console.WriteLine("Decision: {0}", measurementData.Decision);
                        }
                    }
                    break;
                    }
                }
                system.Stop();
            }
            catch (KException ex)
            {
                Console.WriteLine("Error: {0}", ex.Status);
            }

            // wait for ESC key
            Console.WriteLine("\nPress ENTER to continue");
            do
            {
                System.Threading.Thread.Sleep(100);
            } while (Console.Read() != (int)ConsoleKey.Enter);

            return(1);
        }
コード例 #19
0
        private void Form1_Load(object sender, EventArgs e)
        {
            // 主窗口大小、位置
            int Desk_width  = Screen.PrimaryScreen.WorkingArea.Width;
            int Desk_height = Screen.PrimaryScreen.WorkingArea.Height;

            Width    = Desk_width;
            Height   = Desk_height;
            Location = new Point(0, 0);

            // 尝试连接ABB
            NetworkScanner networkScanner = new NetworkScanner();

            networkScanner.Scan();
            controllers = networkScanner.Controllers;
            foreach (ControllerInfo info in controllers)
            {
                ListViewItem item = new ListViewItem("PC");
                item.SubItems.Add("ABB");
                item.SubItems.Add("Detected");
                item.Tag = info;
                listView_Log.Items.Add(item);
                ABB_Connect_OK = true;
                if_ABB_init    = true;
            }



            // 初始化内存映射
            if (If_Init_mmf == false)
            {
                try
                {
                    mmf = MemoryMappedFile.CreateNew(memo_file_name, memo_capacity);
                }
                catch (Exception Memo_e)
                {
                    Console.WriteLine("Memo File: {0} Exception caught.", Memo_e);
                    return;
                }

                try
                {
                    accessor = mmf.CreateViewAccessor();
                }
                catch (Exception Memo_e)
                {
                    Console.WriteLine("Memo File: {0} Exception caught.", Memo_e);
                    return;
                }
                If_Init_mmf = true;
            }
            // Endof-初始化内存映射

            // Gocator启动
            // 进行Gocator初始化的相关工作
            KApiLib.Construct();
            GoSdkLib.Construct();
            GC_system = new GoSystem();
            KIpAddress ipAddress = KIpAddress.Parse(SENSOR_IP);

            try
            {
                sensor = GC_system.FindSensorByIpAddress(ipAddress);
            }
            catch (Exception GC_e)
            {
                Console.WriteLine("XX Gocator Error XX : {0} Exception caught.", GC_e);
                return;
            }

            sensor.Connect();
            sensor_setup = sensor.Setup;
            GC_system.EnableData(true);
            GC_system.SetDataHandler(onData);
            if_Gocator_init = true;
            // Endof-Gocator启动
        }// - Endof - Form1Load
コード例 #20
0
        public static void takephoto(string name2)
        {
            try
            {
                KApiLib.Construct();
                GoSdkLib.Construct();
                GoSystem   system = new GoSystem();
                GoSensor   sensor;
                KIpAddress ipAddress = KIpAddress.Parse(Constants.SENSOR_IP);
                GoDataSet  dataSet   = new GoDataSet();
                sensor = system.FindSensorByIpAddress(ipAddress);
                sensor.Connect();
                GoSetup setup = sensor.Setup;
                setup.ScanMode = GoMode.Surface;
                system.EnableData(true);
                system.Start();
                Console.WriteLine("Waiting for Whole Part Data...");
                dataSet = system.ReceiveData(30000000);
                //DataContext context = new DataContext();
                for (UInt32 i = 0; i < dataSet.Count; i++)
                {
                    GoDataMsg dataObj = (GoDataMsg)dataSet.Get(i);
                    switch (dataObj.MessageType)
                    {
                    case GoDataMessageType.Stamp:
                    {
                        GoStampMsg stampMsg = (GoStampMsg)dataObj;
                        for (UInt32 j = 0; j < stampMsg.Count; j++)
                        {
                            GoStamp stamp = stampMsg.Get(j);
                            Console.WriteLine("Frame Index = {0}", stamp.FrameIndex);
                            Console.WriteLine("Time Stamp = {0}", stamp.Timestamp);
                            Console.WriteLine("Encoder Value = {0}", stamp.Encoder);
                        }
                    }
                    break;

                    case GoDataMessageType.UniformSurface:
                    {
                        GoUniformSurfaceMsg goSurfaceMsg = (GoUniformSurfaceMsg)dataObj;    // 定义变量gosurfacemsg,类型gosurfacemsg
                        long            length = goSurfaceMsg.Length;                       //surface长度
                        long            width = goSurfaceMsg.Width;                         //surface宽度
                        long            bufferSize = width * length;
                        double          XResolution = goSurfaceMsg.XResolution / 1000000.0; //surface 数据X方向分辨率为nm,转为mm
                        double          YResolution = goSurfaceMsg.YResolution / 1000000.0; //surface 数据Y方向分辨率为nm,转为mm
                        double          ZResolution = goSurfaceMsg.ZResolution / 1000000.0; //surface 数据Z方向分辨率为nm,转为mm
                        double          XOffset = goSurfaceMsg.XOffset / 1000.0;            //接收到surface数据X方向补偿单位um,转mm
                        double          YOffset = goSurfaceMsg.YOffset / 1000.0;            //接收到surface数据Y方向补偿单位um,转mm
                        double          ZOffset = goSurfaceMsg.ZOffset / 1000.0;            //接收到surface数据Z方向补偿单位um,转mm
                        IntPtr          bufferPointer = goSurfaceMsg.Data;
                        int             rowIdx, colIdx;
                        SurfacePoints[] surfacePointCloud = new SurfacePoints[bufferSize];
                        short[]         ranges            = new short[bufferSize];
                        Marshal.Copy(bufferPointer, ranges, 0, ranges.Length);
                        FileStream fs;
                        string     path = string.Format("D:\\Grasp\\Grasp\\EyeToHandData\\{0}.txt", name2);
                        //if (!File.Exists(path))
                        //{
                        fs = new FileStream(path, FileMode.Create, FileAccess.Write);

                        //else
                        //{
                        //    fs = new FileStream(path, FileMode.Append, FileAccess.Write);
                        //}
                        StreamWriter sr = new StreamWriter(fs);
                        for (rowIdx = 0; rowIdx < length; rowIdx++)                                                                                                                                   //row is in Y direction
                        {
                            for (colIdx = 0; colIdx < width; colIdx++)                                                                                                                                //col is in X direction
                            {
                                surfacePointCloud[rowIdx * width + colIdx].x = colIdx * XResolution + XOffset;                                                                                        //客户需要的点云数据X值
                                surfacePointCloud[rowIdx * width + colIdx].y = rowIdx * YResolution + YOffset;                                                                                        //客户需要的点云数据Y值
                                surfacePointCloud[rowIdx * width + colIdx].z = ranges[rowIdx * width + colIdx] * ZResolution + ZOffset;                                                               //客户需要的点云数据Z值
                                sr.WriteLine(surfacePointCloud[rowIdx * width + colIdx].x + "," + surfacePointCloud[rowIdx * width + colIdx].y + "," + surfacePointCloud[rowIdx * width + colIdx].z); //开始写入值
                            }
                        }
                        sr.Write("end");
                        //ushort[] ZValues = new ushort[ranges.Length];
                        //for (int k = 0; k < ranges.Length; k++)
                        //{
                        //    ZValues[k] = (ushort)(ranges[k] - short.MinValue);
                        //}

                        //for (UInt32 k = 0; k < bufferSize; k++)
                        //{
                        //    sr.WriteLine(surfacePointCloud[k].x.ToString() + "," + surfacePointCloud[k].y.ToString() + "," + surfacePointCloud[k].z.ToString());//开始写入值
                        //}
                        sr.Close();
                        fs.Close();
                    }
                    break;

                    case GoDataMessageType.SurfaceIntensity:
                    {
                        GoSurfaceIntensityMsg surfaceMsg = (GoSurfaceIntensityMsg)dataObj;
                        long   width          = surfaceMsg.Width;
                        long   height         = surfaceMsg.Length;
                        long   bufferSize     = width * height;
                        IntPtr bufferPointeri = surfaceMsg.Data;

                        Console.WriteLine("Whole Part Intensity Image received:");
                        Console.WriteLine(" Buffer width: {0}", width);
                        Console.WriteLine(" Buffer height: {0}", height);
                        byte[] ranges = new byte[bufferSize];
                        Marshal.Copy(bufferPointeri, ranges, 0, ranges.Length);
                    }
                    break;
                    }
                }
                system.Stop();
            }
            catch (KException ex)
            {
                Console.WriteLine("Error: {0}", ex.Status);
            }
            // wait for ESC key
            //Console.WriteLine("\nPress ENTER to continue");
            //do
            //{
            //    System.Threading.Thread.Sleep(100);
            //} while (Console.Read() != (int)ConsoleKey.Enter);
        }