LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

CAN message manipulation

Solved!
Go to solution

Hi All,

 

I'm new to LabView and i'm finding it extremely challenging, mainly due to data types.

 

Firstly I need my project to save all CAN messages.

Secondly I need to inspect the ArbitationID and act on it accordingly (some resulting in a CAN write)

Then I need to file the data accordingly and show some data on the GUI

 

Usign the single read I can convert the CAN message inc timestamp to a string and save it but if i try and convert it to a cluster for manipulatuion all I get is the 8 bytes of data

 

If I use the multi CAN read I can't break the 5 elements within a cluster within an array down to save the message

 

Any thoughts?

0 Kudos
Message 1 of 16
(4,308 Views)

It sounds like you don't have much experience with LabVIEW at all.  Here are some free training if you are interested:

 

3 Hour Introduction http://www.ni.com/white-paper/5243/en/

6 Hour Introduction http://www.ni.com/white-paper/5241/en/

LabVEW Basics http://www.ni.com/gettingstarted/labviewbasics/

Self Paced training for students http://www.ni.com/academic/students/learn/

Self Paced training beginner to advanced, SSP Required http://sine.ni.com/myni/self-paced-training/app/main.xhtml

LabVIEW Wiki on Training http://labviewwiki.org/LabVIEW_tutorial#External_Links

 

Beyond that I'd recommend looking at the Example Finder found under the Help menu.  You didn't say your hardware but I assume it is XNET.  There are several examples with different ways to perform the read, and they will return different data types.  Opening the context help can show the structure of the data and help you understand how to get what you need.

 

If you need more help try to post a VI of what you have tried.

0 Kudos
Message 2 of 16
(4,290 Views)
Hi, I'm using the NI USB-8473 interface. I've been through a fair few of the examples and videos NI offer as well as exploring the example finder for the last week.

The examples are of little help as they tend to output to another hardware or GUI with a very specific format. Trying to alter an example seems to get me nowhere either as it leads to trying to shoe horn it leading to type incompatability or loss of data.

I accept this is due to me not understanding the type of logic/work that underpins LabVIEW, at the moment the way problems are approached looks completely foriegn!

I'll post my VI tomorrow.

Thanks for the response.
0 Kudos
Message 3 of 16
(4,274 Views)

Hi,

 

Attached is my VI project, its a bit of a mess but all it is doing is looking at the various stages of the CAN output and saving it to 3 different files.

 

My design has been complicated as I'm usign the multi read which produces an 8 x 2D array which may or may not contain a message depending on how many were recieved in the 10ms refresh window.

 

I used the top file to see if the messages spread out into the higher arrays and confirmed that they do.  Ideally I'd like to stop that from happening but it does nto look like this can be done.  So i need to come up with some kind of scalable array reader which reads and acts upon all messages before the 10ms window is up.

 

First and formost every message has to be acted upon, I can not lose or ignore a single one.

 

How should I go about this, there does not seem to be a straight forward solution with the CAN VIs provided and I dont want to go down the route of re-inventing the wheel. 

 

Cheers

 

 

 

 

0 Kudos
Message 4 of 16
(4,250 Views)
Solution
Accepted by topic author Unkle77

I've seen much worst code, but you are making several mistakes that I think make things more difficult.

 

When you perform the read your output is an array of frames.  Each Frame is a cluster of 5 things, Timestamp, ArbID, IsRemote, Data Length, and the Data.  The Array to Cluster function you are using is not the one you should use.  That will take an array and turn it into clusters, but you must define the size and it defaults to 9, so what happens if you get 10 frames in a read?  The last one is lost for ever.  All reads that read more then 9 frames will lose the ones after the 9th.  Additionally what happens if you have no frames?  Well it converts it into 9 frames that are blank, but you go and log those anyway.

 

What you really need to do is process each frame one at a time, looking at the output and then deciding what to do.  This can easily be done in a For loop.  A For loop will pull out each frame one at a time and allow you do do stuff with it and manipulate it in a way that makes sense, or conditionally log different data to different files.  

 

Attached is an edited version that will process each frame, and depending on the ArbID will write to one of 3 files.  If the ArbID is between 0 and 0x12 it goes to one file, from 0x13 through 0x200 it goes to another, and then all other frames go to a 3rd file.  I also updated the format into the file to be a little cleaner and I think it will contain the same information in a tab delimeted file.  This is of course an example I have no idea what you really need your program to do.

Message 5 of 16
(4,246 Views)

Hi Hoovahh,

 

Thansk so much for the work you did to my project.  From the tidy up and clear setup of concept, I could set out and get the bare bones of my project.

 

I came here to ask another question but I worked it out just now 😄 

The bane of my life, decimal/hex mismatches........ I didnt see that x in the corner of the case box!

 

thanks again for taking the time to help!

0 Kudos
Message 6 of 16
(4,210 Views)

Yup the radix on the case structure can be seen when using the numeric data type by right clicking the case and selecting Radix.  You can accomplish something similar using the Coerce In Range to find if a number is in a specific range but for this example it was just easier to use the case structure.

 

EDIT:  By the way I noticed no kudos or marking any post as answering the question.  Doing this helps the community and helps other users looking for similar help.  Thanks.

Message 7 of 16
(4,171 Views)

Hello,

 

I working on a similar problem acquiring CAN frame data from a radar and processing the information to plot. 

 

I am having issues trying to find the best way to log the data. I have tried write to text file, write to binary file and write to spreadsheet file. The issue with write to binary file and spreadsheet file is the file size gets too big (Due to 500kBaud data rate). The write to measurement file VI has an option to write to multiple files after reaching a certain file size but the CAN frame (2D array of string) cannot be input as dynamic data without scrambling the data. 

 

What is the best way to save the CAN frames into a log file?

How to set a filter to identify certain CAN frames?

 

I would be glad if you could help me with this question. 

 

Also, I am using NI-PXI 8512 board with XNET. I am attaching the code for reference. 

 

 

0 Kudos
Message 8 of 16
(3,976 Views)

You really should make a new thread for a new question.  But I'll still help.

 

The XNET test panel built into MAX has logging capability.  And it logs to a TDMS file.  Now for compatability I can see why you might want to just log to a text file ant that works too.  I've dealt with a stream of 500Kbaud CAN data logging it all and it isn't really that much data.  500Kbaud is only 62KBytes/second.  Many high speed DAQ cards can read several hundred thousand samples per second.  And a sample is a double which is 64 bits.  So logging it isn't the problem, its the technique to log the data that is the problem.

 

Opening and closing the log each time is going to be a problem.  Just open it once, and close it once.  Also no need to make a new log file each time you get data.  Why are you making a new file each read?  Just append to the one file.

 

Why are you reading frames as a stream of bytes, just read them as frames and you don't need the conversion.

 

Also why are you converting frames to signals, open an other session for reading signals.  XNet supports opening multiple sessions on the same interface.  Look at the CAN Frame and Signal Input Same Port.vi in the Example Finder.

 

You were also missing the VI that converts frames to string but one is already made for you.

 

Attatched is a version with some of these changes.

 

EDIT:  Oh and I show how to filter based on Arb ID.

0 Kudos
Message 9 of 16
(3,964 Views)

Hey,

 

I thought it would be more cohesive in the same thread but next time. 

 

Firstly, thank you for the help with the code. 

 

The write to binary file version accumulates a lot of data quickly and the file size gets too big. As you estimated, 62Kbytes/s is only 17MB in a minute but my file sizes reached 300MB in a test lasting more than 5minutes. The code I had uploaded was making a new file every cycle but I was working to make a new file every 1.5GB or so, like writing to multiple files after one file reaches a certain size (Like in the write to measurement file function). This way, I can drive around for sometime and collect the data for offline analysis.

 

The session from conversion is used for FRAME to Signal conversion, but that block can be removed if I take the session directly from RAW to CAN. I could remove that section all together and make it lighter. 

 

The updated code you sent does not write to table and makes one file that rewrites itself with a limit of 503KB. This is due to the buffer size of 4900frames.

 

I am working on a big project, radar sensing around the car for environement perception. I am new to labview and learning to use the software (Completing Core1 and Core2 with video tutorials). I'm thinking bigger scale now with respect to the whole project that recieves information from 5 radars, 10 ultrasonics, processed Camera data into the PXI system. My goal is to make a code for reading data from 5 radars, log and create an interactive front panel with radar target graphs, information, and more complex, chaning attributes of target on the plots. For example, make moving targets apprear in a fading trajectory, colour coding for size/ movement. 

 

Logging to table, most importantly, saving it efficiently, then plotting the data are my primary requirements. I would focus on scaling and project progres work for the later issues. 

0 Kudos
Message 10 of 16
(3,949 Views)