From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, 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: 

CAN communication

Hello all,

 

I am trying to get to grips with CAN communication using a USB-8473 but i am fairly new to Labview and need some pointers. Ive attached some code of what ive done so far. Its very basic and broken as it stands.

 

I want to be able to specify several different CAN messages with individual timings and watch the activity on the CAN bus Rx and Tx. (basically sort of a mini can analyser).

 

Ive looked at the examples that come with the 8473 but trying to incorporate them into my bespoke programe is a little difficult for a beginner. If anyone can review my code and give me some help that would be great.

 

Best Regards

0 Kudos
Message 1 of 5
(2,361 Views)

You should work through some LabVIEW basics before starting the CAN communication.  From the VI you posted I can't determine what you're trying to do, and there are many problems with it.  None of your interior loops will ever stop because the stop condition is read only once outside the loop (unless you started the program with stop buttons 2-4 pushed, which wouldn't make much sense), and the outside loop won't even complete it's first execution because the loops inside it don't terminate.

 

Why are you trying to build an array?  Does your program read from the CAN bus, write to it, or both?  Do you just want to send out CAN messages periodically, or you're trying to read them as well?

 

A good start would be a program that sends out a single CAN message at a desired rate.  Once you can do it with one message, then work up to sending several.  You can send different messages by using multiple independent loops, but a better approach would be a single loop and an array of messages where you track the last time at which each message was sent and the rate at which to send them, and whenever the current time is greater than the last time plus the rate, resend that message and update the last sent time.  That way you can expand to any number of messages easily with a single stop condition.

0 Kudos
Message 2 of 5
(2,348 Views)

Hi Nathand,

 

Yes i am a total beginner regarding labview, ive completed a few of the basics and was hoping i could learn while working through my own project. The three loops inside one big loop was just what i initially thought might work.

 

I want to read and write CAN messages on the same channel (My 8473 is only a single channel and has certain hardware limitations). The messages are periodic.

 

I like your suggestion about one loop, would this be very accurate? i dont mind a 1ms or 2ms inaccuracy in timing but anything more might cause me problems. Eventually i have plans to make this a subVI so need it as efficient as possible.

 

I am using arrays because the examples demonstrate using arrays.

0 Kudos
Message 3 of 5
(2,342 Views)

If you really want accurate periodic transmission, you'll want a more-expensive CAN device that can do hardware-timed transmission.  On a desktop operating system like Windows, LabVIEW won't get you guaranteed 1-2ms accuracy in software.

 

I'm a little confused about making it a subVI - do you plan to call this VI once and leave it running in the background while something else is happening?  Your initial structure won't work as a subVI that you call repeatedly.

 

You can do the reading and writing in separate loops.  What do you need to do with the data you read?

 

For testing purposes, the NI-CAN driver provides two virtual (simulated) interfaces that are internally "connected" to each other, CAN256 and CAN257.  Anything sent on one shows up on the other.  You may find this helpful for testing your code without the CAN bus connected.

0 Kudos
Message 4 of 5
(2,340 Views)

Its just me getting ahead of myself as far as what i want to achieve. I suppose once i have a working bit of code that reads and writes on the CAN bus i can create a subvi to use in another application.

 

The more i use the USB-8473 i am becoming to realise its not such a good piece of kit. Most of the features i would like are not supported.

 

0 Kudos
Message 5 of 5
(2,332 Views)