Simulate usb device

A

Andrea Crotti

I have to read/write on a usb device, where we normally attach things
that I don't have always available.

Since this usb connection only forwards data it would be theoretically
the same if I write and read over a file.

But how do I simulate the serial (usb) interface?
My collegue told me there some kind of acknowledgement needed for that.
But maybe then I should create a character device and fake there is
something attached to it?

Any hints or good links where to understand how it could be done?
Thanks
 
N

Nobody

I have to read/write on a usb device, where we normally attach things
that I don't have always available.

Since this usb connection only forwards data it would be theoretically
the same if I write and read over a file.

But how do I simulate the serial (usb) interface?

Is it a serial interface or a USB interface? If you just want a serial
interface, use a pseudo-tty (pty). See e.g.:

http://www.kernel.org/doc/man-pages/online/pages/man7/pty.7.html
 
K

Keith Thompson

Andrea Crotti said:
I have to read/write on a usb device, where we normally attach things
that I don't have always available.

Since this usb connection only forwards data it would be theoretically
the same if I write and read over a file.

But how do I simulate the serial (usb) interface?
My collegue told me there some kind of acknowledgement needed for that.
But maybe then I should create a character device and fake there is
something attached to it?

You really need to ask questions like this in a forum that deals with
your operating system, most likely comp.unix.programmer.
 
N

Nobody

Mm not sure, it's a usb device but we simply write data with "write" on
/dev/ttyUSB0.
So I'm not really sure if it's the linux kernel that manages it or what
really happens.

/dev/ttyUSB0 is a "terminal" device; typically a USB-to-RS232 converter,
although a wide variety of specialised USB devices use the CDC
(communication device class, i.e. "modem") interface, simply because
there's bound to be a suitable driver included in the OS.

For Linux, the main driver is cdc-acm.ko. This provides a serial
interface (/dev/ttyUSB*) for any device implementing the CDC interface.
I've used it to interface to PIC18 devices programmed with Microchip's
CDC implementation. From the perspective of a program accessing the
device, it looks just like a physical serial port.

A pseudo-TTY (pty) is similar to a socket pair (like a pipe, only
bi-directional), but implements the TTY line discipline (i.e. tcsetattr,
line-buffering, Ctrl-C/Ctrl-Z, etc). ptys are fundamental to any type of
"virtual terminal", including terminal emulators (xterm etc) and remote
login servers (telnetd, sshd, etc). They are needed any time that you need
to run a program with its stdin/stdout/stderr connected to something which
"looks like" a terminal.

The controlling application (e.g. xterm, sshd) creates and opens the
"master" device. It can then query the name of the slave device, which
will typically be /dev/pts/<N> (or, with the older BSD interface,
something like /dev/ttyp1). It can either open the slave itself and use it
for the std{in,out,err} of a child process (shell, login, whatever), or it
can just wait until something else explicitly opens it (e.g. manually
running "echo ... > /dev/pts/0" etc).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,954
Messages
2,570,116
Members
46,704
Latest member
BernadineF

Latest Threads

Top