Automotive and Embedded Networks

cancel
Showing results for 
Search instead for 
Did you mean: 

Reading CAN frames from 10 sensors Simultaneously

Solved!
Go to solution

Hello,

 

I have developed a code that reads CAN data frame from the CAN port (PCI CAN/2 series 2 board). The board have 2 CAN ports. I have connected a sensor to one of the ports and reading the CAN frames using my code. I want to use the same code to read CAN frames from 1o sensors simultaneously. Can anyone help me? I have tried creating SUB VI of my code but it reads only one port at a time.    

 

Thanks in advance

0 Kudos
Message 1 of 14
(7,273 Views)

Can you post your code?

 

I'd guess if your code isn't running in parallel, your sub VI is not marked as reentrant.  

0 Kudos
Message 2 of 14
(7,270 Views)

Hi,

 

please see the code attached.  This is not a sub VI but I want to use it as Sub VI to read data from 10 sensors simultaneously.

0 Kudos
Message 3 of 14
(7,268 Views)
Solution
Accepted by topic author swap15

Mark the VI as re-entrant, and you should be able to call it in parallel (VI Properties -> Execution -> Pre-allocated clone reentrant execution).  

 

Keep in mind, if you do this, you will need to use multiple files (as multiple threads cannot write to the same file handle).  

0 Kudos
Message 4 of 14
(7,261 Views)

hi,

 

thanks for the information. I want to write results in multiple files (i.e store the data of each sensor in individual file), I will take care of that.

0 Kudos
Message 5 of 14
(7,259 Views)

Hi,

 

one more question......how can I display my CAN data frame in a graphical format?.....I tried the available Graph options but it didn't worked for me......

0 Kudos
Message 6 of 14
(7,251 Views)

Using the old Frame API, you'll need to parse out each data frame into signals according to your network database.  That is, you'll have to convert the array of U8 you get out of the API into other data types, and then plot those.

 

If your hardware supports NI-XNET, I would highly recommend using that.  With XNET, you can load your DBC, and it does all the hard work for you.  If you're familiar with DAQmx, it should be a breeze to learn.

0 Kudos
Message 7 of 14
(7,239 Views)

HI,

 

I haven't worked with NI XNET. I think to use NI XNET I need compatible hardware but my CAN card doesn't support it. Concerning the data type conversion, I understood it partially. I tried it but it doesn't show complete data. Is it possible for you to show me the short example. (you can use the VI that I attached previously)

 

 

0 Kudos
Message 8 of 14
(7,236 Views)

Hi Gruenberg,

 

I have one question....in my code the while loop interates at 1000ms  i.e.  I want to read CAN data every second (1 value per sec). But when I log this data I see that it gives me 11 values per sec. Because of this my log file is getting very bigger unnnecessarily. I tried to figure it out but couldn't find any solution. Can you tell me why this is happening?

 

Please see attached docs.

 

Thanks in advance.

Download All
0 Kudos
Message 9 of 14
(7,098 Views)

Your sensor is sending out data faster than that--you'll just have to select which frame you want to record.  On the "data" output of ncReadNetMult.vi, inside the innermost case structure, use index array to select the first frame, build that into an array, and pass it to your VI that converts the frame to a string.

 

You will still need to read all the frames from the network, otherwise the buffer will fill.  

0 Kudos
Message 10 of 14
(7,083 Views)