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