Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Simulate usb device

Reply
Thread Tools

Simulate usb device

 
 
Andrea Crotti
Guest
Posts: n/a
 
      07-31-2010
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
 
Reply With Quote
 
 
 
 
Nobody
Guest
Posts: n/a
 
      07-31-2010
On Sat, 31 Jul 2010 16:30:29 +0200, Andrea Crotti wrote:

> 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/...an7/pty.7.html


 
Reply With Quote
 
 
 
 
Andrea Crotti
Guest
Posts: n/a
 
      07-31-2010
>
> 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/...an7/pty.7.html


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.

Thanks for the link, very nice!
 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      07-31-2010
Andrea Crotti <> writes:
> 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.

--
Keith Thompson (The_Other_Keith) kst- <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
 
Reply With Quote
 
Nobody
Guest
Posts: n/a
 
      08-01-2010
On Sat, 31 Jul 2010 19:05:17 +0200, Andrea Crotti wrote:

>> 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/...an7/pty.7.html

>
> 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).

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Plug-in USB hardware device captures keystrokes on Mac and PC USB keyboards. Theo Computer Security 15 12-06-2012 02:10 AM
Need to send data from windows through usb to a usb device reachnisarga Software 0 11-23-2010 06:28 AM
Re: USB issue ... some USB 2 ports working only in USB 1 mode hungsolo2005@yahoo.com A+ Certification 0 06-14-2006 07:26 PM
802.11g router / 1 x 802.11b device / 1 x 802.11g device Oli Wireless Networking 3 09-27-2004 11:56 PM
USB 2 device connecting as USB 1 Bishoop Computer Support 0 06-07-2004 11:04 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57