public void AsyncReceiveData(KObject data) { GoDataSet dataset = (GoDataSet)data; 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); getStamp.FrameIndex = stamp.FrameIndex; getStamp.Timestamp = stamp.Timestamp; getStamp.Encoder = stamp.Encoder; get_stamp_FrameIndex.Add(stamp.FrameIndex); get_stamp_TimeStamp.Add(stamp.Timestamp); get_stamp_EncoderValue.Add(stamp.Encoder); } dataReceivedFlag.Stamp = 1; } break; case GoDataMessageType.Measurement: { GoMeasurementMsg measurementMsg = (GoMeasurementMsg)dataObj; for (UInt32 k = 0; k < measurementMsg.Count; k++) { GoMeasurementData measurementData = measurementMsg.Get(k); getMeasurement.Id = measurementMsg.Id; getMeasurement.value = measurementData.Value; getMeasurement.decison = measurementData.Decision; get_measurementMsg_Id.Add(measurementMsg.Id); get_measurementMsg_Value.Add(measurementData.Value); get_measurementMsg_Decison.Add(measurementData.Decision); } dataReceivedFlag.Measurement = 1; } break; case GoDataMessageType.Alignment: { GoAlignMsg dataItem = (GoAlignMsg)dataSet.Get(i); if (dataItem.Status == KStatus.Ok) { calibrationSuccessfulBl = true; } else { calibrationSuccessfulBl = false; } } break; } } }
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); }
int CalibrationSensor(int goalignmentType, int alignmentmovingTarget, double diskDiameter, double diskHeight) { try { GoSetup setup = sensor_main.Setup; setup.AlignmentType = GoAlignmentType.Moving; setup.AlignmentMovingTarget = GoAlignmentTarget.Disk; setup.DiskDiameter = diskDiameter; setup.DiskHeight = diskHeight; setup.AlignmentEncoderCalibrateEnabled = true; sensor_main.Align(); //wait for calibration disk to be scanned dataSet = system_main.ReceiveData(300000000); for (UInt32 i = 0; i < dataSet.Count; i++) { GoAlignMsg dataItem = (GoAlignMsg)dataSet.Get(i); if (dataItem.MessageType == GoDataMessageType.Alignment) { if (dataItem.Status == KStatus.Ok) { calibrationSuccessfulBl = true; } else { calibrationSuccessfulBl = false; } } } } catch (KException ex) { if (ex.Status == KStatus.ErrorTimeout) { errorInformation.Add(DateTime.Now.ToString("yyyy:MM:dd HHmmss") + "calibration disk time out"); } else if (ex.Status != KStatus.Ok) { errorInformation.Add(DateTime.Now.ToString("yyyy:MM:dd HHmmss") + "calibration error code" + ex.Status); } } return(0); }