From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, 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 bus and FTDI

Hello all,
 
I trying to communicate with some hardware (can-usb device).
This hardware uses FTDI chip, FT232.
 
I created one small program just to have basic communication with device.
Program successfully send can frames, and also receive readback from device.
But sometimes, received frames are merged together, which influence on correct reading. should be around 11 bytes, but instead is much more.
I tried to play with timing (between writing and reading) , sometimes is better but eventually it start to mix frames again.
I thought that to many frames is in buffer between reading, but timing change didn't bring much better results. 

Can someone advise why is this happening, and how to overcome problem?
Latency timer is set on 1ms, so this should be ok.
Please check VI in attachment.
 
Best regards and thank you..
Download All
0 Kudos
Message 1 of 10
(2,704 Views)

Hi milan,

 


@milan87 wrote:
This hardware uses FTDI chip, FT232.
Can someone advise why is this happening, and how to overcome problem?

Does that FT232 device support a "standard" VCP (virtual COM port) instead of accessing it using that DLL? Then you coul dhvae used the VISA functions coming with LabVIEW!

 

The problem is the typical "Don't use BytesAtPort!" error as has been described in this forum on nearly every thread about serial communication!

You are basically doing the same: reading FTDI queue status to get the number of bytes waiting in the buffer queue, combined with an arbitrary wait function. Don't do that: read the number of bytes as is expected in the message!

 

From what I see in your images I would use this approach:

  1. Read 3 bytes to get those "2, 50, 8" numbers. The 3rd value is the payload length of the CAN messages (I guess).
  2. Read those 8 bytes as indicated in step 1 to get the CAN payload.
  3. Back to step 1.

This procedure doesn't need any wait function…

 

On your VIs: you really should rework those FTDI functions to use error IO. This will allow to get rid of all those sequence frames as error wires allow very easy "THINK DATAFLOW!" programming!

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 10
(2,663 Views)

Hello GerdW,

 

first of all, thanks you on your help.

 

If I set the VI to read 3 bytes, instead of reading all bytes in buffer, then VI immediately collapse every time...

Only when I use ''Get number of bytes'', VI doesn't collapse.

What do you think?

 

It has virtual com port, but for now I need to complete vi with dll.

 

 

0 Kudos
Message 3 of 10
(2,642 Views)

Hi milan,

 

what does it mean when a "VI collapses"?

 

Why can't you use the VCP with VISA functions?

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 4 of 10
(2,633 Views)

Hi Gerd,

 

VI immediately stop responding and close. No error window.

 

I will check with visa.

0 Kudos
Message 5 of 10
(2,629 Views)

Hello,

 

I created VI which use visa.

Sending CAN frame is ok, everything normal, same as with ft2xx dll.

 

When try to read only 3 bytes and then the rest, communication doesn't work, and VI give a error. In att.

But when I read all bytes in buffer, I can read data but mixed up, same as with dll.

 

Any advice?

 

Thanks a lot.

 

Download All
0 Kudos
Message 6 of 10
(2,617 Views)

Hi milan,

 

again you are using BytesAtPort even though I wrote you should not use it…

 

The VISA reference might get closed in your state machine before you try to read/write using it.

Using "default if unwired" tunnels with references is a NO-GO! Use a shift register and wire all tunnels in all cases instead!

Your array constants contain more data than is visible: is this intended? For documentation issues you should always show ALL data that is contained in those arrays…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 7 of 10
(2,612 Views)

hi Gerd,

 

I use BytesAtPort because that's the only way I get some results.

As far I write some constant number of bytes to read, I get not responding VI.

 

Shift registers are added.

 

Constant arrays are ok, I have proper sending, and feedback from CAN node, only reading in VI are mixed.

I checked with oscilloscope.

 

What is wrong here?

 

Thanks.

0 Kudos
Message 8 of 10
(2,608 Views)

Hi milan,

 

simplified your VI, see attachment…

 


@milan87 wrote:

I use BytesAtPort because that's the only way I get some results.

As far I write some constant number of bytes to read, I get not responding VI.


This sounds weird!

Right now you just wire the BytesAtPort node, but don't use its output. And without that node your VI does not work anymore?

 


@milan87 wrote:

Constant arrays are ok, I have proper sending, and feedback from CAN node, only reading in VI are mixed.

I checked with oscilloscope.


So now you are saying the VI is working? Is it?

Can you show some resulting data from your VI?

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 9 of 10
(2,589 Views)

It isn't connected, because you advised not to use it. However, as I said, it work only when I connect this to read block, to readout all bytes in buffer.

If I use some other value then this, then VI stop and collapse.

 

I find what was the problem. This is not mixed frames, this is couple of frames merged in buffer. 

So I filter them, using DLC byte (as you suggested), and some other filtering.

So now I got couple of frames in one reading.

 

Thank you on your help.

0 Kudos
Message 10 of 10
(2,567 Views)