7 years, 2 months ago.

Using Windows FlushFileBuffers API to flush mbed com port return error ERROR_INVALID_FUNCTION

Dear sirs, we use mbed com port connected to mcu uart on PC, and use this interface to communicate with mcu. And we found that if use FlushFileBuffers after Write function, it will return ERROR_INVALID_FUNCTION. But if we use other usb2uart chip (such as: FTDI, Prolific) connected to mcu uart directly, this flush API will work well. Is this API not supported by mbed com port driver?

Thanks, Andy

1 Answer

7 years, 2 months ago.

Hi Andy,

I'm able to reproduce this same problem using my Windows 7 machine and the mbed serial driver. I don't know the details of the mbed serial driver, but it would not surprise me if this function wasn't implemented. If you switch out the mbed serial driver with the one that comes with Windows then FlushFileBuffer works correctly.

Which version of Windows are you using? If you are using Windows 10 then you don't need the mbed serial driver at all, since the Windows 10 driver has both the surprise USB disconnect bug fixed and installs automatically.

Thanks, Russ

Accepted Answer

Hello Russ, Thanks for your feedback, The window version I use is Windows 7, and you mean this kind of issue would be happened in Windows 7 instead of Windows 10? In other words, this issue could not have solution in Windows 7?

Many thanks,

Andy

posted by Andy Sun 07 Mar 2017

This issue happens if you install the mbed serial driver, regardless of Windows version.

If you want FlushFileBuffer to be available on Windows 7 you can replace the mbed serial driver with the native Windows driver by following the directions in the "Driver required on Windows" section here: https://developer.mbed.org/handbook/USBSerial

One difference though is instead of looking for an unknown device in device manager, you'll need to look for the mbed serial port.

posted by Russ Butler 07 Mar 2017

Hi Russ, I follow the instruction from https://developer.mbed.org/handbook/USBSerial. But still can't switch the driver successfully, and it still appear in mbed Serial Port. Do you try this before?

regards,

Andy

posted by Andy Sun 13 Mar 2017

Yeah, I have switched drivers without any problem. What error do you see when trying to replace the driver? Even after the driver has been switched the name will be very similar. In my case the windows driver added "Virtual" to the name of the serial port. mbed driver - "mbed Serial Port (COMx)" windows driver - "Mbed Virtual Serial Port (COMx)"

To check that you have switched to the built in Windows driver (usbser.sys) you can follow these steps:

  • Right click on device
  • Select "Properties"
  • Open "Driver" tab
  • Click "Driver Details"
  • You should see "C:\windows\system32\DRIVERS\usbser.sys" and not "C:\windows\system32\DRIVERS\mbedSerial_x64.sys"
posted by Russ Butler 13 Mar 2017

Hi Russ, sorry for the late reply. I've accessed the serial port successfully after using the suggestion you provided before. And I have another question that is when we switch to different USB port, we need to reinstall this driver again!? is any other way to prevent reinstalling again?

Andy

posted by Andy Sun 22 Jun 2017