Page 1 of 1

Reading the serial number of a PCAN-USB Pro FD with PLinApi

Posted: Mon 2. Sep 2024, 15:39
by pjanik
Hello,

I am trying to read the serial number of my device with the GetHardwareParam function of the PLinApi in C# 12/.NET 8. The value returned in the out parameter is always -1. I also tried initializing the hardware before the call. However, other values retrieved with the GetHardwareParam function work without initialization. Should I be able to read the serial number of the device? If yes, could this mean that there is something faulty with the device? If no, why shouldn't I be able to read the serial number via the API?

Thanks in advance

Patryk

Re: Reading the serial number of a PCAN-USB Pro FD with PLinApi

Posted: Mon 2. Sep 2024, 16:53
by M.Heidemann
Hello Patryk,

Can you show us the code with which you try to read the serial number?

BR

Marvin

Re: Reading the serial number of a PCAN-USB Pro FD with PLinApi

Posted: Thu 5. Sep 2024, 10:38
by pjanik
Sure here is my C# code:

Code: Select all

using System.Runtime.CompilerServices;
using Peak.Lin;

Console.WriteLine();

TLINVersion version = default;
PLinApi.GetVersion(ref version);
Console.WriteLine($"{version.Major}.{version.Minor}.{version.Revision}.{version.Build}");

ushort hardwareCount = default;

PLinApi.GetAvailableHardware(null, 0, out hardwareCount);

for (ushort i = 1; i <= hardwareCount; i++)
{
    PLinApi.GetHardwareParam(i, TLINHardwareParam.hwpSerialNumber, out int serial, (ushort)Unsafe.SizeOf<int>());
    Console.WriteLine(serial);
}

return;
I also tried doing it from C++ in case the interop does something funny. Here is the code:

Code: Select all

#include <iostream>
#include <windows.h>
#include "PLinApi.h"

int main()
{
    TLINVersion version;
    LIN_GetVersion(&version);

    std::cout << version.Major << "." << version.Minor << "." << version.Revision << "." << version.Build << "\n";
    int hardwareCount;
    LIN_GetAvailableHardware(nullptr, 0, &hardwareCount);
    for (int i = 1; i <= hardwareCount; i++)
    {
        int serial;
	    LIN_GetHardwareParam(i, hwpSerialNumber, &serial, sizeof(serial));
        std::cout << serial << "\n";
    }
}
In both cases I get the output:

Code: Select all

3.0.3.255
-1
-1
All other PLinApi functions functioned correctly so far I can tell.

Re: Reading the serial number of a PCAN-USB Pro FD with PLinApi

Posted: Thu 5. Sep 2024, 14:00
by M.Heidemann
Hello,

Thank you!

After checking back with our development department:

This parameter is not used at the moment, therefore your result is invalid.

We do no programm serial numbers onto our devices which could be read out,
some vendors using our hardware however use the serial number, therefore
it's part of the API.

I'll make sure this is elaborated further on in the documentation.

BR

Marvin

Re: Reading the serial number of a PCAN-USB Pro FD with PLinApi

Posted: Thu 5. Sep 2024, 14:32
by pjanik
Hello,

Thank you for your answer!

This is unfortunate. There seems to be no way to programmatically differentiate between devices after reconnection or PC restart using the PLinApi other than writing the device id manually. If one could uniquely identify a device it would be possible to remember what LIN cluster it was previously used with. The user than has the possibility to continue using it with the cluster or change it if the cluster changed as well.

Best Regards

Patryk