Linux communication with mbed via C / C++ (not a termina).

03 Aug 2011

Hello all,

We would like to have a Linux computer talk with an mbed via its USB port, in order to transfer data and commands back and forth via a C or C++ program, NOT via a terminal. That is, we want the mbed to talk with a C/C++ program on the Linux machine directly.

On the mbed side, I presume the various Serial commands will do.

On the Linux computer side, I suppose that printf, etc., will also function once the right port is engaged (correct?). However, what I do not understand is how to get the Linux machine to recognize the particular USB port that the mbed will be connected to, or (frankly) any other details on how to establish that sort of serial communication. I also don't know which, if any, special libraries or drivers are necessary.

The Linux computer that we will use probably has old-fashioned serial ports too, if that would make things easier. For now, it will be running Slackware.

Can someone point me in the right direction?

Thank you!

03 Aug 2011

Hi,

I once tried talking to my mbed using a C++ code in windows.. i was able to send char data to mbed and set the 4 LEDs according to the lower 4 bits of the char... and I was able to echo back the same char saying "LEDs set as : A"

my source file included windows.h and dos.h.. the code established serial connection using the COM port..Obviouslt we cant use that headers in Linux.. i think something similar can be done in Linux..

http://sourceforge.net/projects/libusb/ try looking into this..

Will update.. i work on it..

03 Aug 2011

Thank you Krishna,

Libusb looks like overkill for our purposes. Perhaps I'm naive, but I'd like to hope that Linux can directly handle simple serial-like data transfers over USB. If not, then I wonder whether a USB to Serial adapter could do the trick. I presume that support for serial communication is built into every Linux.

The Windows/DOS headers of course wouldn't help, but what did the rest of your code look like?

Thanks again.

03 Aug 2011

This http://en.wikibooks.org/wiki/Serial_Programming/Serial_Linux link looks pretty interesting for explaining the Un*x APIs to use for interacting with serial (tty) devices with the C programming language.

03 Aug 2011

From the command line you can 'echo' or 'cat' to and from /dev/ttyUSBx in C you would use fopen with fgetc/fputc as usual with /dev/ttyUSBx as filename (x is the number of the USB serial port, if no other USB serial adapters are attached it would be /dev/ttyUSB0)

There are ways to force the kernel to assign fixed numbers to the USB serial devices if needed.

I am using two USB-serial adapters on a mythtv backend system and the devices have not changed numbers yet, the default order seems to based on the USB hostbusnumber they are connected too.

03 Aug 2011

Hii... Ive refereed the site below to write my code..

http://www.codeproject.com/KB/windows/mobileconnect.aspx

regards

04 Aug 2011

Thank you for the starting tips. We'll look into it some more.

Thanks again.

04 Aug 2011

I would like to digress a little. Has anyone managed to come up with windows communication with mbed via C/C++ without a terminal program?

You cant use:

/dev/USB0 first usb /dev/USB1 second usb so on..

or

/dev/ttyACM0 if use mini-usb