01-12-2012 09:55 AM
Good evening, I asked questions about the use of the function ncGetHardwareInfo library (CAN) with the NI PXI-1033 rack Although MAX CAN detect the card and the self-test passes the function always returns 0 CAN boards. The returned status is always 0.
Have a nice day
Robertoi Guerzoni
Solved! Go to Solution.
01-16-2012 12:30 PM
Hello Roberto,
are you calling the function in the correct way? Can you take a look in the following manual in page 11-62? It explains how the ncGetHardwareInfo should be called.
http://www.ni.com/pdf/manuals/370289n.pdf
Saluti,
01-17-2012 02:38 AM
Thanks for the reply.
Unfortunately I'm pretty sure you run the call correctly.
The call is made in the class constructor HardwareInfo
////////////////////////////////////////////////////////////////////////
// SUMMARY:
// Hardware info details
////////////////////////////////////////////////////////////////////////
public ref class HardwareInfo
{
protected:
int _status; // Internal calls status
int _CardsCount; // Number of installed cards
int _PortsCount; // Number of available ports
NetString _swVersion;
public:
//
// SUMMARY:
// Class constructor
//
HardwareInfo(void);
public:
//
// SUMMARY:
// Number of installed cards
//
property int Cards
{
int get()
{
return this->_CardsCount;
}
}
//
// SUMMARY:
// Number of installed ports
//
property int Ports
{
int get()
{
return this->_PortsCount;
}
}
//
// SUMMARY:
// CAN software version
//
property NetString SoftwareVersion
{
NetString get()
{
return this->_swVersion;
}
}
//
// SUMMARY:
// Validate object
//
property bool IsValid
{
bool get()
{
return (this->_status == 0);
}
}
};
//////////////////////////////////////////////////////////////////////////
// HardwareInfo
//////////////////////////////////////////////////////////////////////////
HardwareInfo::HardwareInfo(void)
{
_CardsCount = 0;
_PortsCount = 0;
_swVersion = nullptr;
u32 Major;
this->_status = ncGetHardwareInfo(1,1,NC_ATTR_VERSION_MAJOR,sizeof(Major),&Major);
if (STATUS_SUCCEDED != this->_status)
return;
u32 Minor;
this->_status = ncGetHardwareInfo(1,1,NC_ATTR_VERSION_MINOR,sizeof(Minor),&Minor);
if (STATUS_SUCCEDED != this->_status)
return;
u32 Update;
this->_status = ncGetHardwareInfo(1,1,NC_ATTR_VERSION_UPDATE,sizeof(Update),&Update);
if (STATUS_SUCCEDED != this->_status)
return;
u32 Phase;
this->_status = ncGetHardwareInfo(1,1,NC_ATTR_VERSION_PHASE,sizeof(Phase),&Phase);
if (STATUS_SUCCEDED != this->_status)
return;
u32 Build;
this->_status = ncGetHardwareInfo(1,1,NC_ATTR_VERSION_BUILD,sizeof(Build),&Build);
if (STATUS_SUCCEDED != this->_status)
return;
char Version[64] = {0};
sprintf_s(Version,sizeof(Version),"%d.%d.%d.%d.%d",Major,Minor,Update,Phase,Build);
_swVersion = gcnew String( Version );
u32 CardsCount = 0;
this->_status = ncGetHardwareInfo(1,1,NC_ATTR_NUM_CARDS,sizeof(CardsCount),&CardsCount);
if (STATUS_SUCCEDED != this->_status)
return;
this->_CardsCount = CardsCount;
int CardPorts = 0;
for (int c = 1; c <= _CardsCount; ++c)
{
this->_status = ncGetHardwareInfo(c,1,NC_ATTR_NUM_PORTS,sizeof(CardPorts),&CardPorts);
if (STATUS_SUCCEDED != this->_status)
break;
this->_PortsCount += CardPorts;
}
}
Test
private static bool HardwareTest1()
{
NewTest("Testing hardware");
var HardwareInfo = new HardwareInfo();
if (HardwareInfo.IsValid)
{
Console.WriteLine("CAN SW Version:{0}", HardwareInfo.SoftwareVersion);
Console.WriteLine("Total Cards:{0} Total Ports:{1}", HardwareInfo.Cards, HardwareInfo.Ports);
if (HardwareInfo.Cards > 0)
{
NewTest("Test cards details");
for (int i = 1; i <= HardwareInfo.Cards; ++i)
{
Console.WriteLine("Card:{0}", i);
//TODO print card properties...
}
}
TestPassed();
}
else
{
TestFailed();
}
return IsTestPassed;
}
Output
MAX
Saluti
Roberto Guerzoni
01-17-2012 02:52 AM
I also noticed that other CAN library functions do not work with the NI-PXI-1033
private static bool GetPropertyValueTest1()
{
NewTest("Testing GetPropertyValue");
//const int VCAN1 = 256;
const int VCAN1 = 1;
const string ChannelList = "FloatChannel,WordChannel";
uint wTaskRef = 0;
Console.WriteLine("ChannelAPI.InitStart(ChannelList, VCAN1, EnumIoMode.Output, 0, out wTaskRef)");
status = ChannelAPI.InitStart(ChannelList, VCAN1, EnumIoMode.Output, 0, out wTaskRef);
if (status < 0)
{
Console.WriteLine(Service.StatusToString(status));
return TestFailed();
}
Object Value = null;
Console.WriteLine("ChannelAPI.GetPropertyValue(0, \"FloatChannel\", EnumCanProperty.ChanDataType, out Value);");
status = ChannelAPI.GetPropertyValue(wTaskRef, "FloatChannel", EnumCanProperty.ChanDataType, out Value);
if (status < 0)
{
Console.WriteLine(Service.StatusToString(status));
return TestFailed();
}
EnumChannelDataType dt;
Enum.TryParse( Value.ToString(), out dt );
Console.WriteLine("Channel \"FloatChannel\" data type is {0}", dt);
Console.WriteLine("ChannelAPI.GetPropertyValue(0, \"FloatChannel\", EnumCanProperty.ChanUnitString, out Value);");
status = ChannelAPI.GetPropertyValue(wTaskRef, "FloatChannel", EnumCanProperty.ChanUnitString, out Value);
if (status < 0)
{
Console.WriteLine(Service.StatusToString(status));
return TestFailed();
}
Console.WriteLine("Channel \"FloatChannel\" Unit is {0}", Value);
Console.WriteLine("ChannelAPI.GetPropertyValue(0, \"WordChannel\", EnumCanProperty.ChanDataType, out Value);");
status = ChannelAPI.GetPropertyValue(wTaskRef, "WordChannel", EnumCanProperty.ChanDataType, out Value);
if (status < 0)
{
Console.WriteLine(Service.StatusToString(status));
return TestFailed();
}
Enum.TryParse(Value.ToString(), out dt);
Console.WriteLine("Channel \"WordChannel\" data type is {0}", dt);
Console.WriteLine("ChannelAPI.GetPropertyValue(0, \"WordChannel\", EnumCanProperty.ChanUnitString, out Value);");
status = ChannelAPI.GetPropertyValue(wTaskRef, "WordChannel", EnumCanProperty.ChanUnitString, out Value);
if (status < 0)
{
Console.WriteLine(Service.StatusToString(status));
return TestFailed();
}
Console.WriteLine("Channel \"WordChannel\" Unit is {0}", Value);
status = ChannelAPI.Clear(wTaskRef);
if (status < 0)
{
Console.WriteLine(Service.StatusToString(status));
return TestFailed();
}
return TestPassed();
}
Saluti
Roberto Guerzoni
01-17-2012 11:57 AM
Can you please write which operating system are you using and which version of drivers are you using for interacting with the CAN device?
01-17-2012 12:17 PM
Hi A.V.
My operating system is Windows 7 64 bit,
My drivers are NI-XNET v1.4.0f0 and NI-CAN 2.7.3f2
Best Regards
Roberto Guerzoni.
P.S. The software was uploaded to Community suc as example. search
01-23-2012 02:44 AM
Hi, I have finally found the problem and want to share the solution.
In order to use the CAN functions with the NI PXI-1033 and XNET CAN boards it's required the
Compatibility Layer installation.
This options must be checked in the NI-XNET driver
Installing this option the tests exposed in the shared file https://decibel.ni.com/content/docs/DOC-20307
are passed.
Thank you
Roberto Guerzoni