Page 2 of 2

Re: PCAN USB Multiple Hardware same PC

Posted: Fri 4. Dec 2020, 16:22
by M.Heidemann
Hello John,

I would suggest the following approach:

Get the latest PCAN-Linux Driver package:

http://www.peak-system.com/fileadmin/me ... 0.2.tar.gz

PCAN-Linux driver Documentation:
http://www.peak-system.com/fileadmin/m ... an_eng.pdf

Note: Please see the requirements in chapter 2.2

Install the CharDev-variant of the PCAN-Linux driver, by executing in the extracted PCAN-Linux driver-folder:

Code: Select all

make clean
make
sudo make install
Load the driver:

Code: Select all

sudo modprobe pcan
With

Code: Select all

cat /proc/pcan
you'll be to see the available devices.

you can use the read/write interface to identfiy the device, like so (will initialize the device with 500k and starts reading, the LED will blink):

Code: Select all

cat /dev/pcanusbX
Afterwards you can assign a device-ID to the device by using the pcan-settings-tool described in the chapter 4.7.3 of the PCAN-Linux documentation:

sudo test/pcan-settings -f=/dev/pcanusbX -d=0
sudo test/pcan-settings -f=/dev/pcanusbY -d=1

etc...

This device-id is written into the non-volatile memory of the interface.
you can now uninstall the CharDev-driver by calling this from the driver directory:

sudo make uninstall

Now you can set up the SocketCAN-compatible NetDev driver:

Code: Select all

make clean
make NET=NETDEV_SUPPORT
make install
and load the driver

sudo modprobe pcan

Now use the "assign"-parameter to fix the device assignment of channels (can0, can1, etc) to a device-ID

Edit the file:

/etc/modprobe.d/pcan.conf

and add the following line

"pcan options assign=devid"

This will make sure the channels assignment is tied to the device-id

Now either reboot or reload the the driver

Code: Select all

sudo rmmod pcan
sudo modprobe pcan
this feature is not available in the mainline-kernel driver.

Alternatively we do offer a PCIe chip solutions,
for more information in that regard, please contact us at support[at]peak-system.com

Best Regards

Marvin

Re: PCAN USB Multiple Hardware same PC

Posted: Mon 7. Dec 2020, 16:00
by johngassel
Thanks!

Re: PCAN USB Multiple Hardware same PC

Posted: Wed 9. Jun 2021, 19:15
by Shail
Hello,
  1. We are using PCAN USB API. Can u explain below usage API ?
    • How we can make use of PCAN_DEVICE_ID?
    • How we can use PCAN_ATTACHED_CHANNELS ?
    • How to use CAN_SetValue and CAN_getValue API usage ?
    F.Vergnaud wrote:
    Tue 18. Aug 2020, 16:58
    As Marvin said if you have only one USB device, the handle will always be PUDS_USBBUS1.
    But there are possible workarounds to your problem. The device ID is your own value to identify devices, so:
    - you can identify the device you are connected to within your application via the PCAN-Basic parameter PCAN_DEVICE_ID (previously known as device number).
    - or before connecting, use PCAN-Basic and the parameter PCAN_ATTACHED_CHANNELS to list all the connected devices, then connect to the one that matches your requested device id.
  2. Can u explain in detail how to Identifying a Hardware if multiple PCAN hardware connected to same PC on different usb port?
  3. How to use below condition when we are using PCAN UDS Basic API?

    Code: Select all

    Repeat From PCAN_PCIBUS1 To PCAN_PCIBUS16
    {
        Get the value CHANNEL_CONDITION on Channel-X (PCAN_PCIBUSX)
        If “CHANNEL_CONDITION Contains PCAN_CHANNEL_AVAILABLE” Then
        {
             Include Channel-X to the Available-Channels-List
        }
    }
  4. Show The PCAN-Channels available for connection are:

    Code: Select all

    Print List Available-Channels-List
    Thanks in advance

Re: PCAN USB Multiple Hardware same PC

Posted: Thu 10. Jun 2021, 12:33
by M.Heidemann
Hello,

You can use the underlying PCANBasic and its functions for this.

I'd recommend to download the PCANbasic package using the following link:

This way we are both refeering to the same dcomuentation and examples.

1)
"PCAN_DEVICE_ID" is a hardware-parameter, it can be GET/SET using the
CAN_GetValue/CAN_SetValue functions. More information on this parameter can be found in the PCANBasic Parameter docuemntation on page 11.

"PCAN_ATTACHED_CHANNELS" is also a parameter, which can be get using the CAN-GetValue parameter. This parameter is used to get information about all existing PCAN channels on a system in a single call, regardless of their current availability.

The PCANBasic example application showcases its usage, it is
used to get information for all channels currently present, furthermore each channel
is checked for availability and FD-capability:

Code: Select all


// Includes all no-Plug&Play Handles
    for (int i = 0; i < (sizeof(m_NonPnPHandles) /sizeof(TPCANHandle)) ; i++)
        cbbChannel.AddString(FormatChannelName(m_NonPnPHandles[i]));

    stsResult = m_objPCANBasic->GetValue(PCAN_NONEBUS, PCAN_ATTACHED_CHANNELS_COUNT, (void*)&iChannelsCount, sizeof(iChannelsCount));
    if (stsResult == PCAN_ERROR_OK)
    {
        info = new TPCANChannelInformation[iChannelsCount];
        stsResult = m_objPCANBasic->GetValue(PCAN_NONEBUS, PCAN_ATTACHED_CHANNELS, (void*)info, iChannelsCount * sizeof(TPCANChannelInformation));
        if (stsResult == PCAN_ERROR_OK)
            // Include only connectable channels
            //
            for (int i=0; i < (int)iChannelsCount; i++)
                if (info[i].channel_condition & PCAN_CHANNEL_AVAILABLE)
                {
                    bIsFD = info[i].device_features & FEATURE_FD_CAPABLE;
                    cbbChannel.AddString(FormatChannelName(info[i].channel_handle, bIsFD));
                }

        delete [] info;-
    }
 
CAN_SetValue and CAN_GetValue

The PCANBasic example has plenty of examples for setting and getting parameters:

Here an example for setting "PCAN_CHANNEL_IDENTIFYING":

Code: Select all

        iBuffer = bActivate ? PCAN_PARAMETER_ON : PCAN_PARAMETER_OFF;
        stsResult = m_objPCANBasic->SetValue(m_PcanHandle, PCAN_CHANNEL_IDENTIFYING, (void*)&iBuffer, sizeof(iBuffer));
        if(stsResult == PCAN_ERROR_OK)
        {
            info.Format("The procedure for channel identification was successfully %s", bActivate ? "activated" : "deactivated");
            IncludeTextMessage(info);
        }
        break;
 
as well as gettting the status of the parameter:

Code: Select all

 stsResult = m_objPCANBasic->GetValue(m_PcanHandle, PCAN_CHANNEL_IDENTIFYING, (void*)&iBuffer, sizeof(iBuffer));
        if(stsResult == PCAN_ERROR_OK)
        {
            info.Format("The identification procedure of the selected channel is %s", (iBuffer == PCAN_PARAMETER_ON) ? "ON" : "OFF");
            IncludeTextMessage(info);
        }
        break;
Please check the Example-Application, PCANBasic documentation and PCANBasic Parameter docuemntation for reference.

2)

You could for example use the Device-ID to identify a device in software, for a phyiscal
identification you could use the aformentioned parameter "PCAN_CHANNEL_IDENTIFYING" to
have the LED of the device blink.

The former could be handled with If-conditions,
,for example using "PCAN_ATTACHED_CHANNELS" which also returns the device-id,
to identify a specific device and use it.



3)

You can use PCAN-UDS handles as well to get the
CHANNEL_Condition" parameter.

4)

See the aformentioned Example for "PCAN_ATTACHED_CHANNELS", this is basically what the shown code will do. If you check the example you'll see that the returned info will be added as a string to a GUI element. The same could also be done in a console context.

For further questions feel free to contact us again.

Best Regards

Marvin

Re: PCAN USB Multiple Hardware same PC

Posted: Thu 10. Jun 2021, 13:15
by Shail
Hello,

Thanks for your reply.

We are using PCAN-UDS API 2013 (ISO 14229-1:2013) older version.
1) If we have connected two PCAN USB Hardware with same PC how we can understand which one is active at present and communicating using PCAN UDS API?
how could we iterate through all hardware handels and use "GetStatus" to see if an device is active?

2) How we need to Identify PCAN USB device connected to which PCAN USB Bus on PC?
3) Is PCAN USB Bus same as ECU CAN channel ? How we can understand which can channel communicating with PCAN UDS API via PCAN USB hardware?
4) Can u give example PCAN_DEVICE_ID, PCAN_ATTACHED_CHANNELS and PCAN_CHANNEL_IDENTIFYING using PCAN UDS API handle?

Re: PCAN USB Multiple Hardware same PC

Posted: Thu 10. Jun 2021, 14:41
by M.Heidemann
Hello Shail,

We highly recommend to have a look at the examples for PCANBasic and
to refer to the documentation, once questions arise.

1)

You can not determine if a hardware is currently initalized by PCANBasic or PCAN-UDS specifically, you can however assess if the channel is occupied or not.

Also, no need to iterate through the handles to get their status, just use "PCAN_ATTACHED_CHANNELS" to do this, as shown in the examples provided
in the PCANBasic package and the PCANBasic parameter documentation.

2)
I specifically mentioned "PCAN_CHANNEL_IDENTIFIYING", which will phyiscally
show which channel (LED) is responding.
Alterntively you can assign a device-id to internal hardware handle,
which was explained at the very start of this thread.

3)

What is ECU channel refering to? Can you elaborate?
Apart from that, as mentioned ealier, no it's not possbile to determine which API
exactly is using a channel (They all are built on top of PCANBasic, so in reality PCANBAsic actually initializes the channel)

4)

The handles used are the same for both PCANBasic and PCAN-UDS, hence why i said that you can use the PCAN-UDS handles, you can copy the example for using "PCAN_ATTACHED_CHANNLS" given in the PCANbasic example and adjust it to your needs.

Best Regards

Marvin