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

The free LIN software API (Application Programming Interface) for Windows® (only for usage with the PCAN-USB Pro CAN/LIN interface)
Post Reply
pjanik
Posts: 3
Joined: Mon 2. Sep 2024, 14:54

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

Post by pjanik » Mon 2. Sep 2024, 15:39

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

M.Heidemann
Sales & Support
Sales & Support
Posts: 1083
Joined: Fri 20. Sep 2019, 13:31

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

Post by M.Heidemann » Mon 2. Sep 2024, 16:53

Hello Patryk,

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

BR

Marvin
---
Marvin Heidemann
PEAK-Support Team

pjanik
Posts: 3
Joined: Mon 2. Sep 2024, 14:54

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

Post by pjanik » Thu 5. Sep 2024, 10:38

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.

M.Heidemann
Sales & Support
Sales & Support
Posts: 1083
Joined: Fri 20. Sep 2019, 13:31

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

Post by M.Heidemann » Thu 5. Sep 2024, 14:00

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
---
Marvin Heidemann
PEAK-Support Team

pjanik
Posts: 3
Joined: Mon 2. Sep 2024, 14:54

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

Post by pjanik » Thu 5. Sep 2024, 14:32

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

Post Reply