I am using the PCAN Basic API with a USB adaptor which is working just fine, however I would like to
connect to a second CAN bus with a second adaptor running in the same Application software ,I would like to use the Application software as a gateway between the 2 systems
is this possible to do or do I have to use the Developer API ?
if it is possible with the Basic API is there a example some were?
Thank you for the support
Using 2 USB Adaptors
Using 2 USB Adaptors
Peter Erasmus
Automotive Engineering
Switzerland
Automotive Engineering
Switzerland
Re: Using 2 USB Adaptors
Hello Peter,
you are able to use up to 8 USB channels simultaneously within the same application using the PCAN-Basic.
We don't have an example doing this, but basicly you just need to make the connection process you have written in your app twice, one for each adaptor (CAN-Bus):
// PCAN-USB connected to the CAN-Bus A
PCANBasic.Initialize(PCANBasic.PCAN_USBBUS1, TPCANBaudrate.PCAN_BAUD_500K);
// PCAN-USB adaptor connected to the CAN-Bus B
PCANBasic.Initialize(PCANBasic.PCAN_USBBUS2, TPCANBaudrate.PCAN_BAUD_500K);
Then, you have to modify the way you read and write. You have to read from a channel and immediatly write to the other:
// Read from CAN-Bus A
PCANBasic.Read(PCANBasic.PCAN_USBBUS1, out CANMsg);
// Write to CAN-Bus B
PCANBasic.Write(PCANBasic.PCAN_USBBUS2, ref CANMsg);
Take into account that the PCAN-Basic does't allow you to write messages associated to a timestamp, so that the times between messages could be different when you re-write them to the second bus.
I hope this help. Good luck
you are able to use up to 8 USB channels simultaneously within the same application using the PCAN-Basic.
We don't have an example doing this, but basicly you just need to make the connection process you have written in your app twice, one for each adaptor (CAN-Bus):
// PCAN-USB connected to the CAN-Bus A
PCANBasic.Initialize(PCANBasic.PCAN_USBBUS1, TPCANBaudrate.PCAN_BAUD_500K);
// PCAN-USB adaptor connected to the CAN-Bus B
PCANBasic.Initialize(PCANBasic.PCAN_USBBUS2, TPCANBaudrate.PCAN_BAUD_500K);
Then, you have to modify the way you read and write. You have to read from a channel and immediatly write to the other:
// Read from CAN-Bus A
PCANBasic.Read(PCANBasic.PCAN_USBBUS1, out CANMsg);
// Write to CAN-Bus B
PCANBasic.Write(PCANBasic.PCAN_USBBUS2, ref CANMsg);
Take into account that the PCAN-Basic does't allow you to write messages associated to a timestamp, so that the times between messages could be different when you re-write them to the second bus.
I hope this help. Good luck

Best regards,
Keneth
Keneth
Re: Using 2 USB Adaptors
Mr Wagner thank you for you example and efforts to help !!Then, you have to modify the way you read and write. You have to read from a channel and immediatly write to the other:
I appoligisize if my statement regarding the gateway functionallity was misleading ,I want to read data from the 2 Busses ,at the moment i use your interrupt callBack to read CANA ,do I have to set up a second callBack for CANB ,The info you have given for connecting to CANA and CANB is very helpful and thank you very much for it.
I am not a windows programmer or software developer so I always have problems to understand how to implement the ideas is software examples like you showed me in your post is very much appreciated
Best regards
Peter
Peter Erasmus
Automotive Engineering
Switzerland
Automotive Engineering
Switzerland
Re: Using 2 USB Adaptors
Hi Peter,
you could change the code above to do something like this:
private void tmrRead_Tick(object sender, EventArgs e)
{
ReadMessagesFrom(PCANBasic.PCAN_USBBUS_1);
ReadMessagesFrom(PCANBasic.PCAN_USBBUS_2);
}
and this function...
... could be changed to receive a parameter (channel):
private void ReadMessagesFrom(byte channelHandle)
{
TPCANMsg CANMsg;
TPCANTimestamp CANTimeStamp;
TPCANStatus stsResult;
do
{
stsResult = PCANBasic.Read(channelHandle, out CANMsg, out CANTimeStamp);
if (stsResult == TPCANStatus.PCAN_ERROR_OK)
ProcessMessage(CANMsg, CANTimeStamp);
} while (btnRelease.Enabled && (!Convert.ToBoolean(stsResult & TPCANStatus.PCAN_ERROR_QRCVEMPTY)));
}
Best regards,
Keneth
If you mean with "interrupt callback" the function "ReadMessages" from the PCAN-Basic samples, it is up to you if you do the new read works within the same function or in a new one. To read from the second adaptor you have to do just the same steps, but using the handle of the new USB-Channel. Taking as example "reading with a timer" from the PCAN-basic samples (I will use C#), you could modify the code a little to get what you want:p.erasmus wrote: ...at the moment i use your interrupt callBack to read CANA ,do I have to set up a second callBack for CANB ...
Code: Select all
private void tmrRead_Tick(object sender, EventArgs e)
{
ReadMessages();
}
private void tmrRead_Tick(object sender, EventArgs e)
{
ReadMessagesFrom(PCANBasic.PCAN_USBBUS_1);
ReadMessagesFrom(PCANBasic.PCAN_USBBUS_2);
}
and this function...
Code: Select all
private void ReadMessages()
{
TPCANMsg CANMsg;
TPCANTimestamp CANTimeStamp;
TPCANStatus stsResult;
do
{
stsResult = PCANBasic.Read(m_PcanHandle, out CANMsg, out CANTimeStamp);
if (stsResult == TPCANStatus.PCAN_ERROR_OK)
ProcessMessage(CANMsg, CANTimeStamp);
} while (btnRelease.Enabled && (!Convert.ToBoolean(stsResult & TPCANStatus.PCAN_ERROR_QRCVEMPTY)));
}
private void ReadMessagesFrom(byte channelHandle)
{
TPCANMsg CANMsg;
TPCANTimestamp CANTimeStamp;
TPCANStatus stsResult;
do
{
stsResult = PCANBasic.Read(channelHandle, out CANMsg, out CANTimeStamp);
if (stsResult == TPCANStatus.PCAN_ERROR_OK)
ProcessMessage(CANMsg, CANTimeStamp);
} while (btnRelease.Enabled && (!Convert.ToBoolean(stsResult & TPCANStatus.PCAN_ERROR_QRCVEMPTY)));
}
Best regards,
Keneth
Best regards,
Keneth
Keneth
Re: Using 2 USB Adaptors
Hello Keneth
Thank you very much for your help it is highly appreciated ,You do not now how much you helped me
you guys at Peak are unbelieveable !!!
Have a nice weekend
Thank you very much for your help it is highly appreciated ,You do not now how much you helped me

you guys at Peak are unbelieveable !!!
Have a nice weekend
Peter Erasmus
Automotive Engineering
Switzerland
Automotive Engineering
Switzerland