LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to use Labview drivers for USB-CAN Adapter

Hi,

I just recently started working with CAN and I have a PCAN-USB adapter. I'm trying to create a programme for monitoring a series of CAN based devices and I've found Labview drivers at the link below. However, I'm not really sure how to start. I have the specs for the device but I don't know how to proceed. 

 

Should I create messages and channels and a data base in MAX first?  If anyone has programmed with this dongle before please give me a guide how you went about it. 

 

Labview drivers - http://www.labviewportal.eu/en/device-i-o/82-pcan-usb-driver.

 

Thanks 

0 Kudos
Message 1 of 22
(9,797 Views)

I have not used this specific CAN adapter, but I have used other CAN adapters from both NI and other companies.  The CAN database in MAX is useful only if you are using an NI CAN device.  For all other CAN devices you need to use the format that the library uses; most likely that will be raw CAN frames.

 

If you do want to use the NI-CAN interface on top of the PCAN library, you can use NI-CAN virtual channels 255 and 256.  These are internally connected, so that anything you send on one is received on the other.  This makes it possible to do translation between raw frames and channels defined in a database, by opening one interface for frames and the other for channels.  You read raw frames from the real device and send them to CAN255, then read them on CAN256; for writing, you do the opposite.  However, this still requires understanding how to read and write raw frames on the underlying device, so I'd start there.

Message 2 of 22
(9,795 Views)

Hi Nathand,

 

Do you know any materials or papers on writing and reading raw frames that you can refer me to?

 

Thanks

0 Kudos
Message 3 of 22
(9,777 Views)

Wadel wrote:

Do you know any materials or papers on writing and reading raw frames that you can refer me to?


Are you just looking for an introduction to CAN?  A web search for "controller area network introduction" will come up with many results, such as

http://www.ni.com/white-paper/2732/en (from NI)

http://www.kvaser.com/en/about-can.html (from KVaser, another CAN vendor)

http://ww1.microchip.com/downloads/en/AppNotes/00713a.pdf (from Microchip, a microprocessor vendor whose chips support CAN)

 

Do you have a specific device that uses CAN that you need to connect to?

0 Kudos
Message 4 of 22
(9,767 Views)

No I'm not looking for an intro to CAN. I just want to understand how to handle raw frames of the device as you mentioned in your earlier reply. 

0 Kudos
Message 5 of 22
(9,756 Views)

@Wadel wrote:

No I'm not looking for an intro to CAN. I just want to understand how to handle raw frames of the device as you mentioned in your earlier reply. 


I'm not sure what you're asking here.  Have you looked at the library to which you linked?  It includes PCAN_WRITE.vi, which writes a raw frame, and PCAN_READ.vi, which reads a raw frame.  If you already understand the CAN protocol, then the use of these functions should be obvious.  The actual contents of those frames depends on the device that sends or receives them, which is why I asked if you have a particular device that you plan to use.

0 Kudos
Message 6 of 22
(9,753 Views)

 I looked at those functions. In my experience I've always had defined frames and a data base so you can simply read or write a defined channel in your program. If you open the PCAN_Write fucntion for example, and you what to send a command to the CAN device, do you just enter the arbitration ID, message type and length and then enter the value(hex) of the actual data you want to write?  

0 Kudos
Message 7 of 22
(9,746 Views)

Yes, that's it.

 

If you want to use a database with defined messages, you'll need to do the conversion from the message to the corresponding raw frame and vice versa.  One option is the CAN Frame Channel Conversion Library.  Another option, as I previously mentioned, is to install NI-CAN (the older interface, not XNET).  NI-CAN provides two "virtual" interfaces, CAN255 and CAN256, which you can use without any NI CAN hardware.  If you open CAN255 with the Channel API and CAN256 with the Frame API, you can write a message in the database to CAN255, read it back as a frame from CAN256, reformat slightly and use PCAN_Write to send it.  To read a message, do the reverse.

0 Kudos
Message 8 of 22
(9,741 Views)

Hi nathand,

 

Thanks for your reply.

 

If I don't have a database to work with and I have my device specifications. How can I avoid having to manually convert the raw frames to useful data? Since this CAN adapter ins't a NI hardware, I can't create a database in MAX. 

 

My other question is how to configure communication with multiple CAN devices on the network. 

 

Thanks

0 Kudos
Message 9 of 22
(9,710 Views)
You can create a database on MAX and use either of the approaches I suggested in my previous message. It's not that hard to interpret CAN packets manually, though - it's only 8 bytes of data at a time maximum.

As for multiple devices, again an understanding of CAN is helpful. Any message on the bus is received by all devices, so no special configuration is required in software. Just make sure that the electrical termination is correct (the last device needs a terminating resistor).
0 Kudos
Message 10 of 22
(9,705 Views)