/*
* AcceleratorReceiveMeasurement.cs
*
* Gocator 2000 Sample
* Copyright (C) 2011-2019 by LMI Technologies Inc.
*
* Licensed under The MIT License.
* Redistributions of files must retain the above copyright notice.
*
* Purpose: Demonstrates the simple use of the Accelerator by connecting to a sensor and receiving a measurement.
* This allows processing to be performed on the PC rather than on the sensor.
*/
using System;
using Lmi3d.GoSdk;
using Lmi3d.Zen;
using Lmi3d.Zen.Io;
using Lmi3d.GoSdk.Messages;
using Lmi3d.GoSdk.AcceleratorMgr;
using System.Threading;
static class Constants
{
public const string SENSOR_IP1 = "192.168.1.10"; // IP of the sensor used for sensor connection GoSystem_FindSensorByIpAddress() call.
public const string SENSOR_IP2 = "192.168.1.11"; // IP of sensor 2
}
namespace AcceleratorReceiveMeasurement
{
class AcceleratorReceiveMeasurement
{
static int Main(string[] args)
{
try
{
KApiLib.Construct();
GoSdkLib.Construct();
GoSystem system = new GoSystem();
GoSensor sensor1,sensor2;
KIpAddress ipAddress1 = KIpAddress.Parse(Constants.SENSOR_IP1);
KIpAddress ipAddress2 = KIpAddress.Parse(Constants.SENSOR_IP2);
GoDataSet dataSet = new GoDataSet();
sensor1 = system.FindSensorByIpAddress(ipAddress1);
sensor2 = system.FindSensorByIpAddress(ipAddress2);
GoAcceleratorMgr goAcceleratorMgr = new GoAcceleratorMgr();
// create connection to system
goAcceleratorMgr.SetSystem(system);
// start Accelerator manager
goAcceleratorMgr.Start();
//Set Parameters for Acceleration
GoAcceleratorMgrSensorParam goAcceleratorMgrSensorParam1 = new GoAcceleratorMgrSensorParam();
GoAccelSensorPortAllocPorts ports1 = new GoAccelSensorPortAllocPorts();
GoAcceleratorMgrSensorParam goAcceleratorMgrSensorParam2 = new GoAcceleratorMgrSensorParam();
GoAccelSensorPortAllocPorts ports2 = new GoAccelSensorPortAllocPorts();
goAcceleratorMgrSensorParam1.PlatformIpAddress = KIpAddress.AnyV4;
goAcceleratorMgrSensorParam1.Ports = ports1;
goAcceleratorMgrSensorParam2.PlatformIpAddress = KIpAddress.AnyV4;
goAcceleratorMgrSensorParam2.Ports = ports2;
//Accelerate two sensors
goAcceleratorMgr.Accelerate(sensor1.Id, goAcceleratorMgrSensorParam1);
goAcceleratorMgr.Accelerate(sensor2.Id, goAcceleratorMgrSensorParam2);
//Check accelerated status of sensor1
for (UInt32 i = 0; i < 30; i++)
{
GoSensorAccelState kStatus1 = sensor1.AccelerationState;
if (kStatus1 == 2)
{
Console.WriteLine("Sensor1 Accelerated");
break;
}
else
{
Console.WriteLine("Waiting for Sensor1 Accelerated...");
}
Thread.Sleep(1000);
}
//Check accelerated status of sensor2
for (UInt32 i = 0; i < 30; i++)
{
GoSensorAccelState kStatus2 = sensor2.AccelerationState;
if (kStatus2 == 2)
{
Console.WriteLine("Sensor2 Accelerated");
break;
}
else
{
Console.WriteLine("Waiting for Sensor2 Accelerated...");
}
Thread.Sleep(1000);
}
system.Refresh();
sensor1.Connect();
sensor2.Connect();
system.EnableData(true);
system.Start();
// refer to SetupMeasurement.cs for setting up of the measurement tools
dataSet = system.ReceiveData(300000);
for (uint i = 0; i < dataSet.Count; i++)
{
GoDataMsg dataObj = (GoDataMsg)dataSet.Get(i);
switch (dataObj.MessageType)
{
case GoDataMessageType.Stamp:
{
GoStampMsg stampMsg = (GoStampMsg)dataObj;
for (uint 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 (uint 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();
//stop acceleration
goAcceleratorMgr.Decelerate(sensor1.Id);
goAcceleratorMgr.Decelerate(sensor2.Id);
}
catch (KException ex)
{
Console.WriteLine("Error: {0}", ex.ToString());
}
// wait for ENTER key
Console.WriteLine("\nPress ENTER to continue");
while (Console.ReadKey().Key != ConsoleKey.Enter) { }
return 1;
}
}
}
LMI2500系列相机SDK开发包C#版
最新推荐文章于 2024-05-21 13:39:45 发布