Home

Awesome

Candle.NET

.NET wrapper for the Candle API for controlling CAN bus gateways/analysers using the Candlelight firmware (e.g. candleLight, CANable, CANtact, etc)

Instructions

Notes for general use

Notes if you work directly with NativeFunctions

I strongly recommend that you work with Device and Channel classes rather than with the NativeFunctions. So these notes are mostly for me:

Example

Example apps can be found in the TestApp folder.

using System;
using System.Threading;
using Candle;

namespace TestApp
{
	class Program
	{
		static void Main(string[] args)
		{
			var devices = Device.ListDevices();

			foreach (var device in devices)
			{
				device.Open();
				foreach(var keyValue in device.Channels) {
					var channel = keyValue.Value;
					channel.Start(500000);

					// Send frame
					{
						var frame = new Frame();
						frame.Identifier = 1 << 19;
						frame.Extended = true;
						frame.Data = new byte[3] { 0, 0, 0};
						channel.Send(frame);
					}

					Thread.Sleep(100);

					// Receive frames
					var receivedFrames = channel.Receive();
					foreach (var frame in receivedFrames)
					{
						Console.WriteLine(frame);
					}

					channel.Stop();
				}

				var errors = device.ReceiveErrors();
				foreach (var error in errors)
				{
					Console.WriteLine(error);
				}

				device.Close();
			}
		}
	}
}

Credits

Candle.NET wraps a modified version of the CandleAPIDriver found in the Cangaroo repo. The modifications are mostly to make things cleaner to wrap using the DLLImport mechanism of C#/.NET.