Automotive and Embedded Networks

cancel
Showing results for 
Search instead for 
Did you mean: 

Add CRC field and a counter to a CAN frame

Hello, 

 

I'm using XNET / Labwindows CVI on WIN7. 

I developed a function to send CAN frame using "nxWriteSignalSinglePoint()" in single mode. It works good. I can see written frames each 20ms. These frame are static, so, ech time a execute the write function, I can see the same frame sent each 20ms.

 

Now, I need keep all this. But I need to add 2 fileds : 

- CRC : the CRC code of my frame

- Count : from 0 to 15 and then get back to zero.

 

I need to do this dynamically and it's important to keep the 20ms sending frames period.

 

Thanks in advance, 

0 Kudos
Message 1 of 12
(6,966 Views)

I don't use CVI, but in LabVIEW for this type of issue I used the Frame Output Queued Mode, which still maintains the hardware timing and will write frames at the rate specified by the database.  The difference is that each frame is defined as it needs to be written.  So you will provide an array of 5 frames to write, and each will go out 20ms after the previous frame.  After the 5 frames have been written the bus goes idle.  So what you can do is periodically read the number of frames in the queue still, and as it gets low, add more frames to be sent by calling the write function again.

0 Kudos
Message 2 of 12
(6,962 Views)

Hello Hooovahh

 

Unless I did not understand your solution, I do not have multiple frames to send, but only one.
What ever the sending mode, I can accept it as long as it respects the frame format as descriped on the DBC file and its timing (each 20ms).
Can you send me a sample code even in LabVIEW please?

 

thank you in advance,

0 Kudos
Message 3 of 12
(6,955 Views)

You might have one frame, but you want to be able to change the value of each frame, as each frame is being written, correct?  That way a counter or CRC could be changed with each frame?

 

So my suggestion is to periodically check the number of frames in the queue to be written, then when it gets low, add some more frames to the bucket.  When you add the more frames they can have the payload you want, so things like a counter can increment with each frame write.

 

Example_VI_BD.png

0 Kudos
Message 4 of 12
(6,944 Views)

The pattern Hooovahh describes uses queues to send frames with the same ID but with differing payloads. This pattern will allow you to queue up frames with payloads n, n+1, n+2... and the hardware will take care of sending the frames out on the bus when the minimum transmit time allows. 

 

CRC values are both generated and checked in the hardware of the XNET device. At this time, XNET does not support user level manipulation of CRC values.

 

 

Jeff L
National Instruments
0 Kudos
Message 5 of 12
(6,940 Views)

The counter is also a field IN the frame. It changes each 20ms and so we need to recalculate the CRC each time. 

Counter is initilized at 0 and when it is equal to 15, it goes again from zero. 

 

See this layout in the attached PDF please. 

 

0 Kudos
Message 6 of 12
(6,939 Views)

@JefeL, 

 

Yes, I guess that it is not possible to manipulate the XNET level by user. But how can I do so ? 

0 Kudos
Message 7 of 12
(6,936 Views)

And if I try to send 16 frames, each frame with a Counter value, like this : 

0- xxx xxxx 00xxx ... CRC0

1- xxx xxxx 01xxx ...CRC1

2- xxx xxxx 02xxx ...CRC2

...

15- xxx xxxx 15xxx ...CRC15

 

And then can I send these frames each 20ms, and be able to stop sending any time, and restart sending from the last one where I stopped the communication ? 

 

I'm just thinking.. 

0 Kudos
Message 8 of 12
(6,926 Views)

Hi , Im an electronics student and it's my first experience using cvi and i'm searching help ! the step that you already  did it can help me ! plzz can you give the file !  

Thanks in advance, 

0 Kudos
Message 9 of 12
(5,067 Views)

In the 3 years since this thread was created I made a CAN blog, and made two posts on the CRC and Counter.  One describing what I have mentioned in this thread regarding a bucket filling solution, and the other going into an undocumented feature of XNet hardware which may be able to help.  If you want this feature in future versions of the XNet API I suggest going and voting for the idea here.  And if you want to look into the standard way of doing this checkout Part 9 of my blog, and if you want to look at the undocumented and unsupported possible solution checkout Part 10.  All of these example are in LabVIEW not CVI, but the API is similar since XNet is what is being called.

0 Kudos
Message 10 of 12
(5,062 Views)