int hybridHnd = Canlib.canOpenChannel(1, 0);
int memoHnd = Canlib.canOpenChannel(3, 0);
status = Canlib.canSetBusParams(hybridHnd, Canlib.canBITRATE_250K, 0, 0, 0, 1);
status = Canlib.canSetBusParams(memoHnd, Canlib.canBITRATE_250K, 0, 0, 0, 1);
Normally the time stamp is reset to zero when the channel handle is set to bus on. When using a time domain, we want the time stamp to only be reset to zero when the time domain is reset. So, we need to turn the normal behavior off using the canIoCtl function.
object autoResetOff = (UInt32)0;
status = Canlib.canIoCtl(hybridHnd, Canlib.canIOCTL_SET_BUSON_TIME_AUTO_RESET, ref autoResetOff);
status = Canlib.canIoCtl(memoHnd, Canlib.canIOCTL_SET_BUSON_TIME_AUTO_RESET, ref autoResetOff);
Then we add the handles to the time domain with the kvTimeDomainAddHandle function.
status = Canlib.kvTimeDomainAddHandle(myTimeDomain, hybridHnd);
status = Canlib.kvTimeDomainAddHandle(myTimeDomain, memoHnd);
Before going bus on, we need to reset the time domain to zero.
status = Canlib.kvTimeDomainResetTime(myTimeDomain);
We are now ready to place the channel handles bus on.
status = canBusOn(hybridHnd);
status = canBusOn(memoHnd);
At this point, the time stamps on the frames received on both channels will be synchronised. Here is the output from the complete example program where the columns are channel, identifier, flags, dlc, data bytes and time stamp from left to right.