FTDI Community

Please login or register.

Login with username, password and session length.
Advanced Search  

News:

Welcome to the FTDI Community!

Please read our Welcome Note

Technical Support enquires
please contact the team
@ FTDI Support


New Bridgetek Community is now open

Please note that we have created the Bridgetek Community to discuss all Bridgetek products e.g. EVE, MCU.

Please follow this link and create a new user account to get started.

Bridgetek Community

Author Topic: Can someone please explain how event characters are supposed to work?  (Read 19792 times)

Me123

  • Newbie
  • *
  • Posts: 8
    • View Profile

Hello.  I'm using the FTD2XX.dll to interface to a FT232RL chip and was noticing some odd behaviour.  I've turned on event characters and when I send a series of packets that are exactly 62 bytes (including the event character) then there is a very long delay before the data is available to my application.  I've read application note AN232B-04 a few times and this behaviour makes sense if I don't have event characters turned on, as the rate I am sending data back and the value of the latency timer means data wouldn't be sent until the USB buffer is full.  But as I have event characters turned on shouldn't the USB buffer be flushed every time an event character is seen in the data stream, or have I misunderstood something?

Many thanks
Logged

FTDI Community

  • Administrator
  • Hero Member
  • *****
  • Posts: 892
    • View Profile
Re: Can someone please explain how event characters are supposed to work?
« Reply #1 on: February 16, 2018, 01:48:21 PM »

Hello,

If the event character is enabled and it is detected in the data stream, then the contents of the devices buffer is sent immediately. The event character is not stripped out of the data stream by the device or by the drivers, it is up to the application to remove it. Event characters may be turned on and off depending on whether large amounts of random data or small command sequences are to be sent. The event character will not work if it is the first character in the buffer. It needs to be the second or higher. The reason for this being applications that use the Internet for example, will program the event character as '$7E'. All the data is then sent and received in packets that have '$7E' at the start and at the end of the packet. In order to maximise throughput and to avoid a packet with only the starting '$7E' in it, the event character does not trigger on the first position.

You may also want to take a look at the latency timer.

The latency timer is a form of time-out mechanism for the read buffer of FTDI devices. When a FT_Read instruction is sent to the device, data will not be sent back to the host PC until the requested number of bytes has been read. If the requested number of bytes never comes, the device would not send data back.

The latency timer counts from the last time data was sent back to the PC. If the latency timer expires, the device will send what data it has available to the PC regardless of how many bytes it is waiting on. The latency timer will then reset and begin counting again.

The default value for the latency timer is 16ms. This value may be customised by adding or changing the following entries in the FTDIPORT.INF file of the driver before installation.

[FtdiPort232.NT.HW.AddReg] 
 
HKR,,"LatencyTimer",0x00010001,50 
 
This example will set the default latency timer value to 50ms. The valid range for the latency timer is 1ms - 255ms, although 1ms is not recommended as this is the same as the USB frame length.

The latency timer value is held in the registry under:

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\FTDIBUS\{Device VID, PID and serial number}\0000\Device Parameters\LatencyTimer 
 
Please see AN232B-04 Data Throughput, Latency and Handshaking for additional information on the latency timer.

Best Regards,
FTDI Community
Logged

Me123

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Can someone please explain how event characters are supposed to work?
« Reply #2 on: February 16, 2018, 03:27:25 PM »

Hi, thanks for the reply. 

Yes I have seen that application note and read it several times, however it is still not clear to me what the behaviour should be when a packet of data is sent that ends in an event character and is 62 bytes long.

You state that if the event character is enabled and it is detected in the data stream, then the contents of the devices buffer is sent immediately. However, this is not true if the packet of data you are sending is 62 bytes long, at least not in my testing. This, combined with the fact that if you are sending packets of data with a smaller interval than the latency timer setting then the buffer will not be transmitted until it is full (default 4096bytes), means even if you are using event characters there can be very long delays between receiving data.  I would like to know if this is the expected behaviour, because it does not seem like it should be to me.

Thanks.
Logged

FTDI Community

  • Administrator
  • Hero Member
  • *****
  • Posts: 892
    • View Profile
Re: Can someone please explain how event characters are supposed to work?
« Reply #3 on: February 16, 2018, 04:38:00 PM »

Hello,

If you are sending 62 bytes of data and then the event character, then the event character could be sent in the next packet of data (64 bytes in total with two status bytes). This could violate this rule:

The event character will not work if it is the first character in the buffer.

However you need to decide whether you really need event characters. If you are sending 62bytes of data then it will be send immediately since you are sending a full buffer of data.

Best Regards,
FTDI Community

Logged

Me123

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Can someone please explain how event characters are supposed to work?
« Reply #4 on: February 16, 2018, 07:37:25 PM »

Hi.  I am sending 62 bytes including the event character.  It is not sent immediately, at least it is not available to be read out by my application and as I stated in my last post - because the latency timer never times out no data is available to be read until the USB buffer is full.  For me this happens 6.4 seconds after I start sending data, which seems a bit extreme.
Logged

FTDI Community

  • Administrator
  • Hero Member
  • *****
  • Posts: 892
    • View Profile
Re: Can someone please explain how event characters are supposed to work?
« Reply #5 on: February 20, 2018, 09:33:20 AM »

Hello,

This does not sound like normal behaviour.

There could be another issue.

Maybe there is a timeout?

Can you try removing the event character from the data stream and only send 62 bytes of data to see how long it takes to be available?

If you want to send an email to support1@ftdichip.com we could investigate this issue further?

Best Regards,
FTDI Community
Logged

Me123

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Can someone please explain how event characters are supposed to work?
« Reply #6 on: February 22, 2018, 09:46:34 AM »

OK thank you.  I will send an email to support.  Just to be clear though, if I were to send 62bytes of data without an event character then this absolutely is the expected behaviour.  This is because I am sending data faster than the set latency timeout and so data is not available until the USB buffer is full, so only when it has received 4096 bytes.  This is described in section 3.3 of application note AN232B-04.  I was expecting event characters to flush the USB buffer but they appear not to do that.
Logged

FTDI Community

  • Administrator
  • Hero Member
  • *****
  • Posts: 892
    • View Profile
Re: Can someone please explain how event characters are supposed to work?
« Reply #7 on: February 22, 2018, 02:42:22 PM »

Hello,

OK we have not received your email yet, I'll look out for it.

Have you considered adjusting the transfer size to better suit your application using FT_SetUSBParameters?
The default is 4096 bytes but can be adjusted in multiples of 64 bytes between 64 bytes and 64k bytes.
Please see the D2XX Programmer's Guide for more information.

Best Regards,
FTDI Community
Logged

Me123

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Can someone please explain how event characters are supposed to work?
« Reply #8 on: March 02, 2018, 10:20:23 AM »

Sorry, I was caught up with other things for the last week.  I've sent the email now.

Yes I have played with adjusting the transfer size, but I see that as a separate question, at the moment I just wanted to understand what the behaviour of event characters should be as it is not clear to me from reading the programmers guide or AN232B-04.  However, whilst on the subject of the transfer size, one thing I was curious about is what happens if it is set to e.g. 64 bytes and I send, say 70 bytes of data?  Is there a danger of losing the last few bytes or will all the data simply be made available in two packets?

Many thanks.
Logged

FTDI Community

  • Administrator
  • Hero Member
  • *****
  • Posts: 892
    • View Profile
Re: Can someone please explain how event characters are supposed to work?
« Reply #9 on: March 02, 2018, 11:31:03 AM »

Hello Miles,

Event characters will flush the current buffer on the IC but not the complete USB transfer buffer (4k by default).

There will be no loss of data as long as you are using flow control signals (eg CTS/RTS).

Also make sure that you are doing reads in your application correctly by checking the queue status (FT_GetQueueStatus), read what is available and repeat.

I have requested your code so that we can take a look so I will look out for that on email.

Best Regards,
FTDI Community
Logged