8 years, 9 months ago.

USBSerial - C# .Net no data received

Hi There,

I am having trouble receiving in a C# .net SerialPort program. I have stripped down the mbed USB to barebones loopback test, but cannot receive any data no matter after trying numerous setting in connecting to the port. I have used a serial port monitor to look at the transaction data and only PC sent data is found, no mbed looped back data.

Using KL25Z for testing.

When I load a freescale CDC code example there is no problems receiving the data.

Am I missing something with the USBSerial methods of interfacing?

I have tested with a few terminal windows and most connect and loopback data no problem, though I did run into 1 that did not.

mbed config:

  1. include "mbed.h"
  2. include <USBSerial.h>

USBSerial serial;

int main() { char c; while (true) {

serial.printf("mbed serial port\r\n"); wait(.5); if(serial.available() >0){ c = serial._getc(); serial._putc(c); } } }

I have uploaded the c# and the link to the mbed project in this given zip file: https://www.dropbox.com/s/6zocyec10yztlu0/test_com.zip?dl=0

Suggestions?

Thanks Erik. Pretty buffering is not a problem as it is setup as 4096 bytes by default and there are never any bytes read in by the driver.

Maybe the forum would be a better place for this question...

posted by M J 25 Jun 2015

I've no problems with the debug serial port and c# but haven't tried USBSerial on the mbed.

However I have seen previous issues where a USB serial port (from an NXP LCP series processor but not mbed code) and the .net serial drivers didn't play nicely together. The .net code would work on other ports, non-c# applications could open the port fine, it was purely a compatibility issue between the two when trying to create the port. In that situation it threw an exception when opening the port so not the same as you are seeing but a sign that there is something a little odd in the c# serial handler.

We worked around it by using a 3rd party serial port driver in the c# code.

posted by Andy A 26 Jun 2015

1 Answer

8 years, 9 months ago.

I would first stick to getting it to work with serial port monitor program, before trying it with your own. I assume you are using the correct USB port? (So not the SDA one). The mbed is getting properly recognized in the list of com ports? Do you have it updated to the latest version of the USBDevice lib? (Earlier versions of the KL25 code + some of the newer USB chipsets do not work properly).

I have test this code on the frdm-k20,k22f and kl25z all with the same results. Updated the USBDevice libraries for mbed.

Running windows. The com port is detected no problems on the PC and I can successfully connecting with terminal windows, sniffer, c# program.

The mbed program simply runs in loopback and sends a periodic text string. I have tested with 3 terminal applications. 1 and 2 send and receive the data no problems. 3 send, but does not receive any data (same result as with the c# program).

I have tested many other available c# serial port applications withe same same results (no data received).

I have tested freescale drivers on the boards and all of the above work with no problems.

Everything is pointing to there being an issue with mbed drivers working with windows .Net C# drivers at this point. Not sure where to go from here. Any suggestions?

posted by M J 25 Jun 2015

Ah didn't understand it like that. That makes it alot weirder indeed, don't think I can help you with it, hopefully someone else can. I would check if there are somewhere some options regarding for example buffering in the C# com port, but that is really a wild guess from me.

posted by Erik - 25 Jun 2015