Page 1 of 1

PLIN API Read Hardware - Name

Posted: Thu 5. Jan 2012, 15:52
by enwbedia
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!

Re: PLIN API Read Hardware - Name

Posted: Fri 6. Jan 2012, 14:38
by K.Wolf
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);

Re: PLIN API Read Hardware - Name

Posted: Mon 9. Jan 2012, 10:53
by enwbedia
Hello,

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

Re: PLIN API Read Hardware - Name

Posted: Tue 10. Jan 2012, 12:36
by K.Wolf
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?

Re: PLIN API Read Hardware - Name

Posted: Wed 11. Jan 2012, 11:29
by enwbedia
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();
}

Re: PLIN API Read Hardware - Name

Posted: Wed 11. Jan 2012, 12:42
by K.Wolf
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.

Re: PLIN API Read Hardware - Name

Posted: Wed 11. Jan 2012, 14:06
by enwbedia
OK, that was the problem. :P Thank you!

Re: PLIN API Read Hardware - Name

Posted: Wed 11. Jan 2012, 15:01
by enwbedia
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));

Re: PLIN API Read Hardware - Name

Posted: Thu 12. Jan 2012, 08:38
by K.Wolf
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 :?