Hello,
I am currently working on a project using the Ixxat USB to CAN hardware and I have a problem using the Ixxat VCI4 API in C#. Indeed, the acceptance filter does not work as I would like.
I would like to see if I am using the right method to initialize the acceptance filter.
Here is my method to open the CAN connection.
Thanks for your help,
Have a good day
/// <summary>
/// Global bal object
/// </summary>
IBalObject bal;
IVciDeviceManager deviceManager;
/// <summary>
/// Global canControl socket, used to open the communciation
/// </summary>
ICanControl2 canControl;
/// <summary>
/// Global canChannel socket, used to send/receive messages
/// </summary>
ICanChannel canChannel;
/// <summary>
/// Global CAN channel writer
/// </summary>
ICanMessageWriter messageWriter;
/// <summary>
/// Global CAN channel reader
/// </summary>
ICanMessageReader messageReader;
public override bool openConnection()
{
byte port = 0;
try
{
foreach (IVciDevice d in deviceManager.GetDeviceList())
{
if ((bal = d.OpenBusAccessLayer()) != null)
{
Device = d;
break;
}
}
if (bal != null)
{
canControl = bal.OpenSocket(port, typeof(ICanControl2)) as ICanControl2;
CanOperatingModes mode = CanOperatingModes.Standard | CanOperatingModes.Extended;
canControl.InitLine(mode, CanExtendedOperatingModes.Undefined, CanFilterModes.Inclusive,0,CanFilterModes.Inclusive ,0, bitRates[bitRateValue], bitRates[bitRateValue]);
if (HasFilter) //Filter.Id and Filter.Mask are uint
{
canControl.SetAccFilter(CanFilter.Ext, Filter.Id, Filter.Mask);
}
canControl.StartLine();
canChannel = bal.OpenSocket(port, typeof(ICanChannel)) as ICanChannel;
Console.WriteLine("Device's firmwareVersion: " + bal.FirmwareVersion);
Console.WriteLine(canChannel.BusType + " On port: " + canChannel.BusPort + " On: " + canChannel.BusName);
canChannel.Initialize(100, 100, false); //can be recalled when the max number of messages is reached
canChannel.Activate();
messageWriter = canChannel.GetMessageWriter();
messageReader = canChannel.GetMessageReader();
}
else
{
ErrorMessage = "Cannot detect transceiver";
return false;
}
}
catch (VciException e)
{
Console.WriteLine("Error:" + e.Message);
ErrorMessage = e.Message;
return false;
}
ActualState = status.opened;
return true;
}