This example illustrates communicating with a VectorNav sensor over a serial port.
Visual Studio (Windows)
- Open the solution file for your specific Visual Studio version located at
<root>/net/examples/ez_async_data/projects/vs20XX/ez_async_data.sln.
- Open the project file
Program.cs and edit the SensorPort and SensorBaudrate constants at the top of the Main() method to the settings used by your attached VectorNav sensor.
- Build the entire solution by going to the menu
BUILD -> Build Solution.
- Right-click the project
ez_async_data and select Debug -> Start new instance.
Make (Linux)
- You will first need to open the file
<root>/net/examples/ez_async_data/Program.cs and edit the SensorPort and SensorBaudrate constants at the top of the Main() method to the settings used by your attached VectorNav sensor.
- Open a terminal and change to the directory
<root>/net/examples/ez_async_data .
- To build the example, run the command
make .
- Run the example by executing the command
sudo ./ez_async_data . Note that running the command using sudo is required since administrator privileges are required to access the serial ports on Linux.
class Program
{
static void Main(string[] args)
{
const string SensorPort = "COM1";
const UInt32 SensorBaudrate = 115200;
var ez = EzAsyncData.Connect(SensorPort, SensorBaudrate);
for (var i = 0; i < 25; i++)
{
Thread.Sleep(200);
var cd = ez.CurrentData;
if (!cd.HasYawPitchRoll)
Console.WriteLine("YPR Unavailable.");
else
Console.WriteLine("Current YPR: {0}", cd.YawPitchRoll);
}
ez.Sensor.WriteAsyncDataOutputType(
AsciiAsync.VNYPR);
for (var i = 0; i < 25; i++)
{
Thread.Sleep(200);
var cd = ez.CurrentData;
if (!cd.HasYawPitchRoll)
Console.WriteLine("YPR Unavailable.");
else
Console.WriteLine("Current YPR: {0}", cd.YawPitchRoll);
}
Console.WriteLine("HasQuaternion: {0}", ez.CurrentData.HasQuaternion);
for (var i = 0; i < 25; i++)
{
Thread.Sleep(200);
var cd = ez.CurrentData;
if (!cd.HasAnyAttitude)
Console.WriteLine("Attitude Unavailable.");
else
Console.WriteLine("Current Quaternion: {0}", cd.AnyAttitude.Quat);
}
ez.Disconnect();
}
}