Hi,
Is it possible to receive both extended and default CAN messages with the same program?
how can i set both modes?
thanks
Hi,
Is it possible to receive both extended and default CAN messages with the same program?
how can i set both modes?
thanks
Hello,
try to evaluete fmt-flag while receive/send use extended frames(?).
now i'm using this code:
res = _CP.GetBaudrate(out baudrate);
if (baudrate != 250000) throw new Exception("Baudrate was set to " + baudrate + " instead of 250000");
//pCan.SetCommand(CanPort.CanCommand.ENTER_STANDBY)
res = _CP.SetDefaultFrameFormat(FS.NetDCU.CanPort.CanTransmitFormat.EXTENDED);
if (res != 0) throw new Exception("Error setting default frame format");
res = _CP.SetCanMode(FS.NetDCU.CanPort.CanMode.CAN_2_0_A);
if (res != 0) throw new Exception("Error setting can mode");
_canFilter.code = 0; // no filter for this moment
_canFilter.mask = 0xFFFFFFFF;
res = _CP.WriteAcceptanceFilter(ref _canFilter);
if (res != 0) throw new Exception("Error setting acceptance filter");
res = _CP.Init();
if (res != 0) throw new Exception("Error initializing can bus");
CanPort.CanAcceptanceFilter _canFilterRet;
res = _CP.ReadAcceptanceFilter(out _canFilterRet);
if (res != 0) throw new Exception("Error reading acceptance filter");
_canMask = CanPort.CanEventFlags.RECEIVED;
res = _CP.SetCommMask(_canMask);
if (res != 0) throw new Exception("Error setting can RXmask");
CanPort.CommTimeouts timeouts = new CanPort.CommTimeouts();
timeouts.ReadIntervalTimeout = 10;
_CP.SetCommTimeouts(ref timeouts);
but how can i say i want to listen to both standard AND extended messages?
The correct way is to open two file handles to the CAN port. And define two different acceptance filters for them, one file handle with a standard format acceptance filter and one file handle with an extended format acceptance filter. Then each acceptance filter will receive the frames of its own kind.
Your F&S Support Team
i'm still having problem with defining the mask.
I want to recieve everything.
for can mode 2.0.A it is 0xFFFFFFFF
but what is it for extended frames?
if i make 2 handles to the same can port and configure it with defferent filter and format, i can't recieve anything...
so this doesn't seem to work...
private void Initialize()
{
int res = 0;
_CP = new CanPort("CID2:", FS.NetDCU.CanPort.CanAccess.READ_WRITE);
_CP2 = new CanPort("CID2:", FS.NetDCU.CanPort.CanAccess.READ_WRITE);
_CP.HandleErrorsViaReturn(true);
res = _CP.SetBaudrate(250000);
if (res != 0) throw new Exception("Error setting canbus baudrate to 250000!");
uint baudrate;
res = _CP.GetBaudrate(out baudrate);
if (baudrate != 250000) throw new Exception("Baudrate was set to " + baudrate + " instead of 250000");
//pCan.SetCommand(CanPort.CanCommand.ENTER_STANDBY)
res = _CP.SetDefaultFrameFormat(FS.NetDCU.CanPort.CanTransmitFormat.STANDARD); // verschillend bij extended
if (res != 0) throw new Exception("Error setting default frame format");
res = _CP.SetCanMode(FS.NetDCU.CanPort.CanMode.CAN_2_0_A); // verschillend bij extended
if (res != 0) throw new Exception("Error setting can mode");
_canFilter.code = 0; // no filter for this moment
_canFilter.mask = 0xFFFFFFFF;
res = _CP.WriteAcceptanceFilter(ref _canFilter);
if (res != 0) throw new Exception("Error setting acceptance filter");
res = _CP.Init();
if (res != 0) throw new Exception("Error initializing can bus");
CanPort.CanAcceptanceFilter _canFilterRet;
res = _CP.ReadAcceptanceFilter(out _canFilterRet);
if (res != 0) throw new Exception("Error reading acceptance filter");
_canMask = CanPort.CanEventFlags.RECEIVED;
res = _CP.SetCommMask(_canMask);
if (res != 0) throw new Exception("Error setting can RXmask");
CanPort.CommTimeouts timeouts = new CanPort.CommTimeouts();
timeouts.ReadIntervalTimeout = 10;
_CP.SetCommTimeouts(ref timeouts);
//////_CP2
_CP2.HandleErrorsViaReturn(true);
res = _CP.SetBaudrate(250000);
if (res != 0) throw new Exception("Error setting canbus baudrate to 250000!");
uint baudrate2;
res = _CP2.GetBaudrate(out baudrate2);
if (baudrate2 != 250000) throw new Exception("Baudrate was set to " + baudrate2 + " instead of 250000");
//pCan.SetCommand(CanPort.CanCommand.ENTER_STANDBY)
res = _CP2.SetDefaultFrameFormat(FS.NetDCU.CanPort.CanTransmitFormat.EXTENDED);
if (res != 0) throw new Exception("Error setting default frame format");
res = _CP2.SetCanMode(FS.NetDCU.CanPort.CanMode.CAN_2_0_B);
if (res != 0) throw new Exception("Error setting can mode");
_canFilter2.code = 0; // no filter for this moment
_canFilter2.mask = 0; //0xFFFFFFFF;
res = _CP2.WriteAcceptanceFilter(ref _canFilter2);
if (res != 0) throw new Exception("Error setting acceptance filter");
res = _CP2.Init();
if (res != 0) throw new Exception("Error initializing can bus");
CanPort.CanAcceptanceFilter _canFilterRet2;
res = _CP2.ReadAcceptanceFilter(out _canFilterRet2);
if (res != 0) throw new Exception("Error reading acceptance filter");
_canMask2 = CanPort.CanEventFlags.RECEIVED;
res = _CP2.SetCommMask(_canMask2);
if (res != 0) throw new Exception("Error setting can RXmask");
CanPort.CommTimeouts timeouts2 = new CanPort.CommTimeouts();
timeouts2.ReadIntervalTimeout = 10;
_CP2.SetCommTimeouts(ref timeouts2);
}
What is wrong in my code?
the init of _cp2 breaks _cp ...
kind regards