From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Kvaser CAN bus Interface Serial num

Solved!
Go to solution

Hi team , 

 

I am using Kvaser device USBcan Pro 4xHS. 

Installed the Kvaser drivers for windows and canlib application .  . 

 

Required  to get the Kvaser device serial number , EAN number along with the user selected Can Channel in interface . 

So by getting these combination of this , even interface was disturbed and reinserted it wont get allocated to wrong channel . 

Attached the link below for requirement  

https://www.kvaser.com/developer-blog/how-to-connect-to-a-specific-kvaser-can-channel/

 

General (kvaser.com) 

 

Planned to use 2 functions 

canOpenChannel() and canEnumHardwareEx()

 

In LabVIEW i used Call Library function to call dll but i couldnt make it with proper syntax. 

Getting error of 1097 . Referred below link 

knowledge.ni.com/KnowledgeArticleDetails?id=kA00Z000000PAckSAG&l=en-IN 

 

Changed the thread and calling convention method too . still i facing the same error . 

I guess i am writing a wrong syntax .

Guide me to get the serial number , EAN number with active channel chosen by user . 

Attached the  dll  along with my program  "Call library- Get Serial number" program also ..

where i need to modify ? 

I am Using the CAN bus and DLL calling for the first time in LabVIEW .Help me on this 

Thanks in advance

 

 

 

0 Kudos
Message 1 of 14
(2,148 Views)

DLL file was attached . Any help over this ?

Facing the error of 1097

0 Kudos
Message 2 of 14
(2,075 Views)

So you take an existing function kvCanOpenChannel, change its parameter signature to something else and wonder why it causes a memory protection exception, that LabVIEW dutifully catched for you and reported as 1097. You can't do that!

 

There really shouldn't be any need to call new not already implemented functions.

 

All you should need to do is to call kvCanGetNumberOfChannels.vi and then enumerate in a loop each of them for the kvCanGetChannelDataChannelName.vi and kfCanGet6ByteChannelData.vi with the "Card UPC Number" and kfCanGet8ByteChannelData.vi with the "Card Serial Number" selector. Use your EAN string and serial number data to convert to a 6 byte and 8 byte array as explained in that article and match them with the returned data until you find the right one. Et voila.

 

That article you refer to explains how to create your own function in C to do an open with the EAN and serial number. That does not mean that you can just reconfigure the CanOpen vi to call the original canOpen function in the DLL with these new parameters. You have to implement this whole function using the existing functions in the Can Library yourself and since you work in LabVIEW and not in C, the most prudent way to do that is by writing a LabVIEW VI that does this by calling the existing Can Library functions.

 

Do not try to fiddle with the Call Library Nodes! There is no need for that nor is it anything that a beginner should even attempt to do. 

 

 

Rolf Kalbermatter
My Blog
0 Kudos
Message 3 of 14
(2,054 Views)

For Kvaser hardware I would run the CANGetChannelData function, and it would return a string of some kind describing the hardware.  I don't know if the serial is in that string or not, because I don't have the hardware to test with any more.  But I do know that there is some kind of hardware index, and hardware channel number information in the string separated by the "#" symbol.

 

Attached is the VI that I would call in a While Loop until there was nothing returned to find all attached channels.  This VI was part of a larger LabVIEW toolkit that KVaser once provided.  I updated it a bit and posted some of the changes to my CAN blog when talking about connecting to non-NI hardware in Part 4.  That code is rough, doesn't handle 64 bit, doesn't handle CAN-FD, doesn't handle non-Windows platforms, and brings along lots of unneeded dependencies, but it might give you an idea of what is possible.

0 Kudos
Message 4 of 14
(2,030 Views)

Thanks Hooovahh, 

 

I already found that function and closed the requirement . 

I got the serial number by 8byte array [ hexa ] , it was formatted and converted to decimal . 

 

I tried to extract the EAN number (UPC) but facing  Issue with the "kvCanGet6ByteChannelData.vi" and got the error of -1 . [error in parameter].

Not even changed anything in library vi's . Really weird to see this error from official library .

Attached error screenshot 

 

 Randomly i gave 13 to item parameter and getting some hexa data . Help me on this . 

 

Download All
0 Kudos
Message 5 of 14
(2,008 Views)
Solution
Accepted by topic author Mrtechie

According to the API documentation the UPC request is an 8 byte request. Not sure why they put it into the 6 byte request VI.

 

#define canCHANNELDATA_CARD_UPC_NO   11

This define is used in canGetChannelData(), buffer mentioned below refers to this functions argument.

buffer points to a 8-byte area which receives the UPC (EAN) number for the card. If there is no UPC number, the buffer is filled with zeros. The UPC (EAN) number is coded as a BCD string with the LSB first, so e.g. 733-0130-00122-0 is coded as 0x30001220 0x00073301.

 

So try to add a ring control with the name UPC Number or similar to the 8 byte request and make it send the value 11 to the API in the according case structure on the diagram and see if that helps.

Rolf Kalbermatter
My Blog
0 Kudos
Message 6 of 14
(1,995 Views)

As discussed , I had a multiple Kvaser USB CAN devices  and tried to read the 2nd device Serial number and EAN number . It was failed . (Same Programs used )

 

Hardwares Used :

  • Kvaser USBcan Light 4xHS
  • Kvaser USBcan Light 2xHS
  • Virtual CAN Driver

 

My agenda was even User unplug and plug the device into different USB Interface or multiple devices connected at the same time I need to differentiate them by combination of EAN +Serial number + Active channel chosen by user .

 

Already Created program and completed testing for 1 device (Kvaser USBcan Light 4xHS ) it was working perfect ,

but change of interface or multiple devices at a same time means I am unable to read data

 

shall i proceed with CanLib channel number to differentiate or writing parameters in configuration file , then every time i can check and proceed for further ?

 

Guide me for the same .

 

Download All
0 Kudos
Message 7 of 14
(1,913 Views)

I don't have time to dig into the details right now, and your description is kind of confusing, but it most likely will boil down that you need to initiate an actual hardware re-enumeration so that the driver can detect the new hardware.

 

Basically the Kvaser driver has a variant of the canGetNumberOfChannels() API that also performs an internal hardware detection to enumerate new hardware. Basically you need to create a copy of the kvCanGetNumberOfChannels.vi that calls the API function canEnumHardwareEx() instead of the canGetNumberOfChannels() function. The signature is the same so all you will need to do is to change the function name in the Call Library Node.

 

Actually the kvCanGetNumberOfChannels.vi should have a boolean input that lets you decide if you want to do a hardware re-enumeration and if that boolean is true it should call above function instead of the existing one.

 

Attached VI is a modified version of the kvCanGetNumberOfChannels.vi. With cleaned up diagram too and a proper icon as well as a useful connector pane. VIs not using the 4-4-4 connector pane or a compatible one, are so last century!!! They indicate that a software producer made the LabVIEW drivers not as a second thought but more likely third or even fourth thought, and is likely committed to support it like a headache.

Rolf Kalbermatter
My Blog
0 Kudos
Message 8 of 14
(1,893 Views)

Hi Rolf , 

 

If both devices are connected at a same time , I am able to read the any 1 active device Serial number and EAN number only .

 

I can able to read the channel name of both devices and Total number of available channels connected .

But facing  issue while reading the Serial and EAN Number in  parallel. Guide me on this

attached image for your reference . 

0 Kudos
Message 9 of 14
(1,875 Views)

If you have more than one channel per device, you obviously won't have enough by just remembering the EAN and SerialNumber, but also need to add the onboard channel number into the information to remember. So you will need to query the SN, EAN and board channel number and store this triplet, then enumerate these three items for all available channels and try to match the information. I don't understand where the problem is.

Rolf Kalbermatter
My Blog
0 Kudos
Message 10 of 14
(1,869 Views)