Exemplo n.º 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);
        }
Exemplo n.º 2
0
        static int Main(string[] args)
        {
            try
            {
                KApiLib.Construct();
                GoSdkLib.Construct();
                GoSystem      system      = new GoSystem();
                GoAccelerator accelerator = new GoAccelerator();
                GoSensor      sensor;
                KIpAddress    ipAddress = KIpAddress.Parse(Constants.SENSOR_IP);
                GoDataSet     dataSet   = new GoDataSet();
                accelerator.Start();
                sensor = system.FindSensorByIpAddress(ipAddress);
                accelerator.Attach(sensor);
                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();
                accelerator.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);
        }