LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware > Linux - Embedded & Single-board computer
User Name
Password
Linux - Embedded & Single-board computer This forum is for the discussion of Linux on both embedded devices and single-board computers (such as the Raspberry Pi, BeagleBoard and PandaBoard). Discussions involving Arduino, plug computers and other micro-controller like devices are also welcome.

Notices


Reply
  Search this Thread
Old 01-30-2012, 09:56 AM   #1
Ninaeve
LQ Newbie
 
Registered: Jan 2012
Posts: 21

Rep: Reputation: Disabled
Question Retrieve data from a USB port


Hi everybody.
I'm using uClinux and compiling with arm-linux-gcc.
I would like to connect to a USB GPS and retrieve its data saving them in a file.
The USB GPS is seen as a common read-only tty port .
I think I setted properly the \dev\ttyUSB0 port using the
struct termios options (bautrate, parity, 8 data bits etc)
and I can open it, but I can't manage to successfully retrieve data from it, it gives me blank spaces or unreadable characters.....
I tried with cat but it works only in the bash and like above.
If someone can give me any hint it would be very kind of him/her and I would be gratefull.
Thanks in advance and
1) Please I'm sorry for my English
2) Sorry I'm a Linux newby
 
Old 02-01-2012, 09:10 AM   #2
Ninaeve
LQ Newbie
 
Registered: Jan 2012
Posts: 21

Original Poster
Rep: Reputation: Disabled
Hi,
part of my code is

fd = open("/dev/ttyUSB0", O_RDWR | O_NOCTTY | 0);
options.c_cc[VMIN] = 1;
options.c_cflag |= (CLOCAL | CREAD);
options.c_cc[VTIME] = 60;
cfsetispeed(&options, B4800);
cfsetospeed(&options, B4800);
tcsetattr(fd, TCSANOW, &options);
read(fd, &read, 10);
printf("Reading on ttyUSB0 : %s\n", read);
cat.exe ./dev/ttyUSB0 > ./home/usr1/usbdata.txt ;


but the cat isn't recognized as a command and the read produce white spaces and an empty file.
If someone can give me a hint I would be gratefull.
Thank you in advance.
Best Regards
Ninaeve
 
Old 02-02-2012, 11:56 AM   #3
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
Are you sure there device can be expected to return human-readable ASCII data? If so, have you tried communicating with it interactively, using a known-good terminal emulator?

--- rod.
 
Old 02-03-2012, 08:07 AM   #4
Ninaeve
LQ Newbie
 
Registered: Jan 2012
Posts: 21

Original Poster
Rep: Reputation: Disabled
@ theNbomr

Thanks theNbomr,

I assumed that a GPS receiver would return human-readable ASCII data, otherwise.....
Can you please suggest me a (possibly freeware) known-good terminal emulator for Windows?
Thanks for the suggestions, I'll check them out.
Ninaeve
 
Old 02-03-2012, 10:35 AM   #5
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
I don't use Windows, but last time I did, it included something called Hyperterm (?). But why do you want to use Windows? Your first post talks about uClinux, termios, etc. In Linux, my preferred terminal emulator is C-Kermit. If the GPS receiver shows up as a serial port, that should be all you need.
You cannot always assume that devices communicate using ASCII string data. I've never used a GPS receiver, but many devices try to maximize throughput by using structured binary data. In such cases, you would need to have some documentation that explains how to interpret the data.

--- rod.
 
Old 02-04-2012, 02:50 AM   #6
formiaczek
LQ Newbie
 
Registered: Nov 2011
Posts: 8

Rep: Reputation: 0
Have you tried different baudrates? 4800 seems to be quite small as for decent devices.
 
Old 02-06-2012, 02:45 AM   #7
Ninaeve
LQ Newbie
 
Registered: Jan 2012
Posts: 21

Original Poster
Rep: Reputation: Disabled
First : Thank you all very much for the suggestions!

@ theNbomr: I use uClinux as embedded sistem but I unfortunately have to test in Windows, but I meant that in this way if I have some porting problem ^_^''' I can see what is happening anyway.
I'll test C-Kermit.

@ formiaczek: I checked the baudrate in the pdf data sheet the producer gave me (the very only document apart from the Windows drivers) so that's it, but I don't need high speed GPS, it's ok.
 
Old 02-06-2012, 08:38 AM   #8
onebuck
Moderator
 
Registered: Jan 2005
Location: Central Florida 20 minutes from Disney World
Distribution: SlackwareŽ
Posts: 13,927
Blog Entries: 45

Rep: Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159
Member response

Hi,
Quote:
Originally Posted by Ninaeve View Post
First : Thank you all very much for the suggestions!

@ theNbomr: I use uClinux as embedded sistem but I unfortunately have to test in Windows, but I meant that in this way if I have some porting problem ^_^''' I can see what is happening anyway.
I'll test C-Kermit.

@ formiaczek: I checked the baudrate in the pdf data sheet the producer gave me (the very only document apart from the Windows drivers) so that's it, but I don't need high speed GPS, it's ok.
Device documentation should provide the format for your GPS. I used a older Garmin with ASCII output without any issues. You just need to know the message format protocol, baud rate, byte/word format;
Quote:
Garmin;
However, creating a simple ASCII file will not work. I found out that the file generated by the Garmin is in UTF16, Little Endian. The first 2 bytes of the file is FF FE. The 2 bytes after that is "GC", encoded as 47 00 43 00. Each character is stored as 16 bits with the least significant byte first.
Do a Google or DuckDuckGo search to get the format protocol for your device.
HTH!
 
Old 02-06-2012, 09:39 AM   #9
Ninaeve
LQ Newbie
 
Registered: Jan 2012
Posts: 21

Original Poster
Rep: Reputation: Disabled
Hi ! The data are in NMEA http://en.wikipedia.org/wiki/NMEA_0183 code so they are indeed ASCII sentences with the baudrate, bit length etc I imposed.
So how do I read from the port and create an ASCII file with the data?
I'm a Linux newby and I'm aware of it.

If someone can give me a hint I will be gratefull.
Best Regards
Ninaeve
 
Old 02-06-2012, 11:15 AM   #10
onebuck
Moderator
 
Registered: Jan 2005
Location: Central Florida 20 minutes from Disney World
Distribution: SlackwareŽ
Posts: 13,927
Blog Entries: 45

Rep: Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159
Member response

Hi,

Please explain how you have the GPS device physically connected to your system(embed or desktop)? USB or USB to serial(adapter)? You are not clear enough as to the physical hardware.

What is the GPS model & manufacture?

Why are you speaking earlier about Microsoft Windows connection?

I would suggest we concentrate on using one system to communicate(embed) with the GPS. GPSdrive is a Garmin widget toolkit(example) for Gnu/Linux. Your GPS should have a toolkit of some sort to use.

Last edited by onebuck; 02-06-2012 at 11:22 AM. Reason: add link
 
Old 02-06-2012, 11:36 AM   #11
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
The way you access the device may be completely different in different OS's. The Windows driver may provide one style of abstraction, while a Linux driver provides a completely different style. Therefore, testing in one environment may provide no transferable information. You say that the Linux driver makes the device look like a serial port, so start from there.
Since we've established that the device may not be sending human-readable ASCII data, I suggest using SerLook in Linux (needs KDE, I think). This will allow you to look at the data in ways that don't make sense in a terminal emulator, and will provide a means to record the data to log files for your analysis.
--- rod.
 
Old 02-06-2012, 12:30 PM   #12
onebuck
Moderator
 
Registered: Jan 2005
Location: Central Florida 20 minutes from Disney World
Distribution: SlackwareŽ
Posts: 13,927
Blog Entries: 45

Rep: Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159
Member response

Hi,

Looks like you can use this daemon;

Quote:
excerpt from gpsd;
gpsd provides a TCP/IP service by binding to port 2947[4]. It accepts commands from that socket, and returns results back to it. These commands use a JSON-based syntax and return JSON responses[4] (older, now obsolete versions used single-letter commands). Concurrent operation is supported. Most GPS receivers are supported, whether serial, USB, or Bluetooth. Starting in 2009, GPSD supports AIS receivers as well.[5] Additionally gpsd supports interfacing with the UNIX network time protocol daemon ntpd via shared memory to enable setting the host platform's time via the GPS clock.
You still need to provide the requested information so we are not shooting in the dark.

FYI: I suggest that you look at 'How to Ask Questions the Smart Way' so in the future your queries provide information that will aid us in diagnosis of the problem or query.
 
Old 02-07-2012, 03:18 AM   #13
Ninaeve
LQ Newbie
 
Registered: Jan 2012
Posts: 21

Original Poster
Rep: Reputation: Disabled
Hi, and thank you all.
I'm sorry if I wasn' t clear/specific enough on describing my sistem.
(Forgetting about Windows, I'm cross compiling through Cygwin) I'm using a uClinux embedded system, Linux Kernel 2.6.14-M5.
The Realtek GPS is connected to the Linux mini-computer through a USB port but thanks to a Linux driver the USB port is seen as a normal serial port.


Thank you @onebuck and @theNbomr for the suggestions, I'll try with gpsd and SerLook.
Best Regards

Ninaeve
 
Old 02-09-2012, 08:30 AM   #14
Ninaeve
LQ Newbie
 
Registered: Jan 2012
Posts: 21

Original Poster
Rep: Reputation: Disabled
Arrow

Hi, thanks to various codes I managed to listen to my GPS but: I imposed in termios

options.c__cc[VMIN]=480

and the gcc complained : "warning: large integer implicitly truncated to unsigned type".

Is this actually a real problem?
Anyway : is it possible to vary the type of the termios options?

THANK you all for your suggestion and support
Best REgards
Ninaeve
 
Old 02-09-2012, 09:26 AM   #15
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
I haven't looked at the definition of c__cc, but I suspect it is a character type, which means the maximum value is either 127 or 255, depending on whether it it signed or unsigned. Moreover, setting VMIN to a non-zero value, while leaving VTIME at the default value of zero allows for the possibility of waiting forever if a character is dropped while reading a packet. See Serial Programming Guide for POSIX Operating Systems for the details.

--- rod.[COLOR="Silver"]

Last edited by onebuck; 02-09-2012 at 04:51 PM. Reason: network induced dupe
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] how to retrieve lost data on a usb stick zenofronia Linux - General 14 07-28-2013 08:49 PM
Retrieve data from a USB port Ninaeve Programming 2 01-30-2012 12:30 PM
USB data got corrupt- How to retrieve? babi Linux - Newbie 3 01-09-2012 07:54 AM
Best way to retrieve data baldurpet Linux - Software 3 12-25-2008 12:48 AM
Very urgent! Need to retrieve some data! Help bikov_k General 2 10-16-2004 06:51 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware > Linux - Embedded & Single-board computer

All times are GMT -5. The time now is 03:39 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration