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
Reading the serial number of a PCAN-USB Pro FD with PLinApi
-
- Sales & Support
- Posts: 1083
- Joined: Fri 20. Sep 2019, 13:31
Re: Reading the serial number of a PCAN-USB Pro FD with PLinApi
Hello Patryk,
Can you show us the code with which you try to read the serial number?
BR
Marvin
Can you show us the code with which you try to read the serial number?
BR
Marvin
---
Marvin Heidemann
PEAK-Support Team
Marvin Heidemann
PEAK-Support Team
Re: Reading the serial number of a PCAN-USB Pro FD with PLinApi
Sure here is my C# code:
I also tried doing it from C++ in case the interop does something funny. Here is the code:
In both cases I get the output:
All other PLinApi functions functioned correctly so far I can tell.
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;
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";
}
}
Code: Select all
3.0.3.255
-1
-1
-
- Sales & Support
- Posts: 1083
- Joined: Fri 20. Sep 2019, 13:31
Re: Reading the serial number of a PCAN-USB Pro FD with PLinApi
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
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
Marvin Heidemann
PEAK-Support Team
Re: Reading the serial number of a PCAN-USB Pro FD with PLinApi
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
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