473,396 Members | 1,784 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Need help with USB programming in Linux

Hi
I am trying to write a file to a USB device using C program..
When i try to open the USB port, i find the foll error

"open_port: unable to open usbdev2.1_ep81: No such file or directory"

The command to open the USB port:
Expand|Select|Wrap|Line Numbers
  1. sprintf(portfile,"/dev/usbdev2.1_ep81");
  2. if((fd=open(portfile, O_RDWR | O_NOCTTY | O_NDELAY))==-1)
  3. perror("open_port: unable to open usbdev2.1_ep81");
  4.  
Please provide some inputs/help

Thanks,
Priya
Sep 6 '07 #1
18 4384
sicarie
4,677 Expert Mod 4TB
Please read your PM's, accessible via the link in the top right corner of the page.

You are trying to access the device from /dev/, which means you have not mounted it. In Linux the device needs to be mounted before it can be accessed. What flavor (distribution) are you running? I know Debian will automount and put it in /media/usbdisk/ so you might try looking around your / or /mnt directory for a 'media' or 'usb' folder.
Sep 6 '07 #2
Please read your PM's, accessible via the link in the top right corner of the page.

You are trying to access the device from /dev/, which means you have not mounted it. In Linux the device needs to be mounted before it can be accessed. What flavor (distribution) are you running? I know Debian will automount and put it in /media/usbdisk/ so you might try looking around your / or /mnt directory for a 'media' or 'usb' folder.
Hi
I am using Debian flavor.
What i m trying to do is use a C program to access USB device in the same way as the COM port are accessed in Serial Communication.
Thanks
Sep 6 '07 #3
sicarie
4,677 Expert Mod 4TB
Hi
I am using Debian flavor.
What i m trying to do is use a C program to access USB device in the same way as the COM port are accessed in Serial Communication.
Thanks
Just because it is a different device will mean that you will not be able to access it the same way you would access a serial communication. I mean, it's possible to write wrappers and everything to create that functionality, but you will need to access it differently, just because it is a USB device and not a serial device.

What version of Debian? Did you check the /media folder?
Sep 6 '07 #4
RRick
463 Expert 256MB
Devices need to be mounted before you can access them as directories and files. Take a look at the mount command (i.e. man mount) and google for "usb mount" for more details.

Many times linux will automatically mount devices for you at bootup and when they get plugged in. Take a look in your desktop for an icon and take a look in the root directory for /mnt and/or /media. The devices are mounted under these directories. Once you find the mounting directory use it like any other path. (i.e. /mnt/usb1/blah/blah/blah)
Sep 6 '07 #5
Just because it is a different device will mean that you will not be able to access it the same way you would access a serial communication. I mean, it's possible to write wrappers and everything to create that functionality, but you will need to access it differently, just because it is a USB device and not a serial device.

What version of Debian? Did you check the /media folder?
Following is the system details
Linux debianTSP 2.6.18-4-686 #1

Also i checked the media folder so it shows me the usbdisk dir created over there.

I want to access any of the following using C program
debianTSP:/media/usbdisk# ls -lart /dev/u*
crw-rw-rw- 1 root root 442, 0 2007-08-31 12:24 /dev/usbdev1.1_ep00
crw-rw---- 1 root root 442, 0 2007-08-31 12:24 /dev/usbdev1.1_ep81
crw-rw---- 1 root root 442, 1 2007-08-31 12:24 /dev/usbdev1.2_ep00
crw-rw---- 1 root root 442, 1 2007-08-31 12:24 /dev/usbdev1.2_ep81
Sep 6 '07 #6
sicarie
4,677 Expert Mod 4TB
Following is the system details
Linux debianTSP 2.6.18-4-686 #1

Also i checked the media folder so it shows me the usbdisk dir created over there.

I want to access any of the following using C program
debianTSP:/media/usbdisk# ls -lart /dev/u*
crw-rw-rw- 1 root root 442, 0 2007-08-31 12:24 /dev/usbdev1.1_ep00
crw-rw---- 1 root root 442, 0 2007-08-31 12:24 /dev/usbdev1.1_ep81
crw-rw---- 1 root root 442, 1 2007-08-31 12:24 /dev/usbdev1.2_ep00
crw-rw---- 1 root root 442, 1 2007-08-31 12:24 /dev/usbdev1.2_ep81
Ok, do me a favor and do

man ls

by specifying /dev/u* you are listing the contents of the /dev/ directory that start with u, doesn't matter if you're in /media/usbdisk/ or not because you are using the absolute path (starting with / ). "man" will allow you to look at how a command should be implemented - it's short for "manual". You can do that for almost any command.

Then try this:

cd /media/usbdisk/
ls -alh

That will show you the modules in /media/usbdisk. And you can then use those as RRick has said - use the path to them as you would any other path.
Sep 6 '07 #7
Thanks for the same.
Well i looked in /media/usbdisk/, it shows me the boot directory..
Also i m using a putty to access the machine :-(
Sep 6 '07 #8
Tried with the mount command..gave an error

mount /dev/usbdev1.1_ep00
mount: can't find /dev/usbdev1.1_ep00 in /etc/fstab or /etc/mtab
Sep 6 '07 #9
sicarie
4,677 Expert Mod 4TB
Tried with the mount command..gave an error

mount /dev/usbdev1.1_ep00
mount: can't find /dev/usbdev1.1_ep00 in /etc/fstab or /etc/mtab
What was the output of the 'ls' command in /media/usbdisk/ ?

Let's make sure it is not already mounted first...
Sep 6 '07 #10
RRick
463 Expert 256MB
Just4priya,

You're actually pretty close to getting something to work.

First, stay away from the /dev directory (unless you really know what you're doing). Its not going to work the way you expect it to work. Usually, devices (things in /dev) are mounted (by the mount command) to a file system (directories and files).

If you can access /media/usbdisk, then its already been mounted (maybe). Go to that directory and start looking for directories and files like Sicarie told you. Putty will work fine in this case. The normal files commands (i.e. ls, mkdir, cd) should work here. Try creating a file by copying one over or use the touch command. If these work, then your C program will be able to do the same.
Sep 7 '07 #11
Hi

The output of ls command is

ls -l /media/usbdisk/
boot/ .created_by_pmount

I don't have permissions to create a file /media/usbdisk/ :-(

Thanks
Sep 7 '07 #12
sicarie
4,677 Expert Mod 4TB
Hi

The output of ls command is

ls -l /media/usbdisk/
boot/ .created_by_pmount

I don't have permissions to create a file /media/usbdisk/ :-(

Thanks
You shouldn't have to create anything - it should be there already. I'm not sure your usb drive is mounted there. What's supposed to be on it? (ie - is there supposed to be a 'boot' directory as the root of the USB filesystem?)
Sep 7 '07 #13
You shouldn't have to create anything - it should be there already. I'm not sure your usb drive is mounted there. What's supposed to be on it? (ie - is there supposed to be a 'boot' directory as the root of the USB filesystem?)
I could see a boot directory available in /media/usbdisk/
Sep 7 '07 #14
sicarie
4,677 Expert Mod 4TB
I could see a boot directory available in /media/usbdisk/
Right, but is that a directory that is supposed to be on your USB disk?
Sep 7 '07 #15
RRick
463 Expert 256MB
Around and around and around we go. Its difficult to know for certain whether the usb drive is mounted or not. Is the boot directory correct or not?

There is one way to find out, but it takes a couple of system reboots.

Unplug all the USB drives, and then reboot. Good back to /media and look for the usbdrive and boot directories. If one or both disappear, then they probably belong to the removed drive(s).

Shutdown the computer, add one (1) usb drive, and bootup. Go back to /media and look again. Is anything added? If so, then there's your drive.

If nothing changes during all of this, then these directories do not connect to your usbdrive.
Sep 7 '07 #16
sicarie
4,677 Expert Mod 4TB
Around and around and around we go. Its difficult to know for certain whether the usb drive is mounted or not. Is the boot directory correct or not?

There is one way to find out, but it takes a couple of system reboots.

Unplug all the USB drives, and then reboot. Good back to /media and look for the usbdrive and boot directories. If one or both disappear, then they probably belong to the removed drive(s).

Shutdown the computer, add one (1) usb drive, and bootup. Go back to /media and look again. Is anything added? If so, then there's your drive.

If nothing changes during all of this, then these directories do not connect to your usbdrive.
Yeah, the OP is connecting via Putty, so I was going on "they don't have physical access".

You can also use the command 'df' to show mounted drives. Something should point to something with "usb" in the name...
Sep 7 '07 #17
Hi,

I was successfully able to mount the USB disk and write a file into it.
Thanks for all the help provided

Priya
Sep 12 '07 #18
RRick
463 Expert 256MB
Good for you. Mounting is not a trivial task for unix boxes.

Some unixes try to protect the user from "mount" and sometimes they succeed and sometimes they don't.
Sep 13 '07 #19

Sign in to post your reply or Sign up for a free account.

Similar topics

99
by: Jim Hubbard | last post by:
It seems that Microsoft not only does not need the classic Visual Basic developer army (the largest army of developers the world has ever seen), but now they don't need ANY Windows developer at a...
2
by: Clément | last post by:
Hello, i'm new to c++ and to linux, i have to develop a full web browser. I don't really know how to start and i'd like to know if any of you would have some kind of working plan/structure in...
5
by: mr.iali | last post by:
Hi Everyone I would like to get into software developent using a programming language like c++, java or pl/sql for oracle. I have no idea where to start from. Which language is there more...
1
by: Mathias Goldau | last post by:
Hi, Can someone tell me where I find some material (e.g. a compiler with graphics.h and conio.h (for free)) related to graphic programming BGI-like, and sound programming (not PC-speaker). The...
4
by: João Pires | last post by:
I have a program write in VB and I need to convert the code to C for Linux. Well, I began to do that but I have some problems ... - How can I write te code in C to comunicate with the serial...
2
by: Martin | last post by:
Hello, We are in the process of putting together an A class PHP Development team(ecommerce / billing applications) for a project in the Bay Area. Reqt. details: ReqId : Req-3616 - Senior PHP...
8
by: john | last post by:
To test a new piece of software designed to help with (among other things) eCommerce WWW site development. The software is fairly easy to use but you must fit a profile. Retail price is 120 GBP and...
17
by: Nirjhar Oberoi | last post by:
Hi, I am new to Linux and wanted to know how to use GCC to Compile the Code written in C? I dont want to use EMacs or VI for my editor. Can you suggest a good IDE for linux for C Programming.. ...
1
by: leeanngriego | last post by:
I have a client who has asked me to find him some solid up and coming embedded engineers. 2 to 3 years expereince with Embedded Linux, VxWorks, Nucleus or any other RTOS who has working in L2/L3...
8
by: Amar | last post by:
I am a system programmer , doing my program in C/RedHat LINUX ES4.0 version. I want to do concurrent programming in C , which will utilise my system's 4 processor simutaneously. I need some one's...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.