PLIN API Read Hardware - Name

The free LIN software API (Application Programming Interface) for Windows® (only for usage with the PCAN-USB Pro CAN/LIN interface)
Post Reply
enwbedia
Posts: 5
Joined: Thu 5. Jan 2012, 15:31

PLIN API Read Hardware - Name

Post by enwbedia » Thu 5. Jan 2012, 15:52

Hello,
I want to read the hardware-name of the device "pcan-usb pro" using PLIN-API 11.01.2011 - Version 2.2.28.71.

code:

Peak.Lin.TLINError lLINErr;
StringBuilder lnName = new StringBuilder();

lLINErr = Peak.Lin.PLinApi.GetHardwareParam(lwHw, Peak.Lin.TLINHardwareParam.hwpName,lnName,47);

lLINErr == errBufferInsufficient :?

What did i do wrong?

Thx!
enwbd

K.Wolf
Software Development
Software Development
Posts: 141
Joined: Wed 22. Sep 2010, 15:37

Re: PLIN API Read Hardware - Name

Post by K.Wolf » Fri 6. Jan 2012, 14:38

Hi,

if you do not explicitly set the StringBuilder capacity, it won't have a capacity of 47 characters.

Please try this:


StringBuilder lnName = new StringBuilder(Peak.Lin.PLinApi.LIN_MAX_NAME_LENGTH);

lLINErr = Peak.Lin.PLinApi.GetHardwareParam(lwHw, Peak.Lin.TLINHardwareParam.hwpName, lnName, (ushort)lnName.Capacity);

enwbedia
Posts: 5
Joined: Thu 5. Jan 2012, 15:31

Re: PLIN API Read Hardware - Name

Post by enwbedia » Mon 9. Jan 2012, 10:53

Hello,

ok, that works, but I get only an empty string back. The StringBuilder capacity is 30 and the length 0. :?:
enwbd

K.Wolf
Software Development
Software Development
Posts: 141
Joined: Wed 22. Sep 2010, 15:37

Re: PLIN API Read Hardware - Name

Post by K.Wolf » Tue 10. Jan 2012, 12:36

In my test it works properly. What is the return value of GetHardwareParam()?
The hardware is plugged in and the hardware handle is 1 or 2?

enwbedia
Posts: 5
Joined: Thu 5. Jan 2012, 15:31

Re: PLIN API Read Hardware - Name

Post by enwbedia » Wed 11. Jan 2012, 11:29

Hi,
the return-value is "errOK" and the hardware handle is "1".

code to get lin-devices with name and handle:

public static PLin_HandlerInfo[] GetDevices()
{
List<PLin_HandlerInfo> returnval = new List<PLin_HandlerInfo>(15);
PLin_HandlerInfo HandlerInfo = new PLin_HandlerInfo();
ushort[] lwHwHandles;
ushort lwHw;
ushort lwBuffSize, lwCount;
TLINError lLINErr;

lwHwHandles = new ushort[8];
lwBuffSize = 8;
lwCount = 0;

int lnHwType;
byte lnChannel,lnDevNo;
StringBuilder lnName = new StringBuilder(Peak.Lin.PLinApi.LIN_MAX_NAME_LENGTH);

lLINErr = PLinApi.GetAvailableHardware(lwHwHandles, lwBuffSize, out lwCount);
if (lLINErr == Peak.Lin.TLINError.errOK)
{
for (byte i = 0; i < lwCount; i++)
{
// Get the handle of the hardware.
lwHw = lwHwHandles;
// Read the type of the hardware with the handle lwHw.
PLinApi.GetHardwareParam(lwHw, Peak.Lin.TLINHardwareParam.hwpType, out lnHwType, 0);
if (lnHwType == Peak.Lin.PLinApi.LIN_HW_TYPE_USB)
{

lLINErr = PLinApi.GetHardwareParam(lwHw, Peak.Lin.TLINHardwareParam.hwpName, lnName, (ushort)lnName.Capacity);

// Read the device number of the hardware with the handle lwHw.
PLinApi.GetHardwareParam(lwHw, Peak.Lin.TLINHardwareParam.hwpDeviceNumber, out lnDevNo, 0);
// Read the channel number of the hardware with the handle lwHw.
PLinApi.GetHardwareParam(lwHw, Peak.Lin.TLINHardwareParam.hwpChannelNumber, out lnChannel, 0);

HandlerInfo.hwHandler = (byte)lwHw;
HandlerInfo.Name = "PCAN-USB Pro LIN (ID: " + lnDevNo.ToString("X2") + "h)" + " - Channel " + lnChannel.ToString();

returnval.Add(HandlerInfo);
}
}
}
return returnval.ToArray();
}
enwbd

K.Wolf
Software Development
Software Development
Posts: 141
Joined: Wed 22. Sep 2010, 15:37

Re: PLIN API Read Hardware - Name

Post by K.Wolf » Wed 11. Jan 2012, 12:42

Hi,

The code is ok.
Are you sure you have the latest PLIN-API properly installed on your computer? Older PLIN Manager service EXEs (PLinMng.exe) before v2.2.27 did not return the correct hardware name when retrieving the hwpName parameter. You can find the PLinMng.exe in the \Windows\System32 directory.
The version numbers of PLinMng.exe and PLinApi.dll should all be 2.2.28.71.

enwbedia
Posts: 5
Joined: Thu 5. Jan 2012, 15:31

Re: PLIN API Read Hardware - Name

Post by enwbedia » Wed 11. Jan 2012, 14:06

OK, that was the problem. :P Thank you!
enwbd

enwbedia
Posts: 5
Joined: Thu 5. Jan 2012, 15:31

Re: PLIN API Read Hardware - Name

Post by enwbedia » Wed 11. Jan 2012, 15:01

Hello,

i still have a question about the function "GetHardwareParam" with the parameter "hwpDeviceNumber".

PLinApi.GetHardwareParam(lwHw, TLINHardwareParam.hwpDeviceNumber, out lnDevNo, 0);

The device number is not the number, which is storaged in the device. This number seemed to be reassigned by the PLin-manager. When this is correct, there is no possibility to identify clearly the device with the help of this number.
When i disconnect two devices and plug in them again for example, they could have another number then before. Is that right?

The PCanBasic API offers the function "GetValue" and "SetValue" with the parameter "PCAN_DEVICE_NUMBER".
This number seems to be a "real" device number.

PCANBasic.GetValue(temphandle, TPCANParameter.PCAN_DEVICE_NUMBER, out iBuffer, sizeof(UInt32));
enwbd

K.Wolf
Software Development
Software Development
Posts: 141
Joined: Wed 22. Sep 2010, 15:37

Re: PLIN API Read Hardware - Name

Post by K.Wolf » Thu 12. Jan 2012, 08:38

Hi,

according to the PLIN-API documentation, the parameter hwpDeviceNumber returns the index of the device, where the first PCAN-USB Pro adapter has index 1, the second has index 2 and so on.
What you are trying to retrieve is the hwpIdNumber parameter, which is an arbitrary 32-bit value that can be programmed into the hardware. In contrary to CAN hardware, each LIN channel can have its own ID.
I admit that the choice of the parameter names is sometimes a bit unfortunate :?

Post Reply