LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-02-2010, 09:26 AM   #1
kievari
LQ Newbie
 
Registered: Jan 2010
Posts: 27

Rep: Reputation: 16
read serial port problem


Hi,
I have set up a connection on my serial port with a motor controller. When I command the motor as:
echo '#1p1000' > /dev/tts/0
everything works ok: motor starts to work as expected.

On this motor controller, I have a digital sensor connected to an input port which sends either LOW or HIGH. I can also query it:
echo 'A' > /dev/tts/0
how can I read the answer in Linux?
I tried:
echo < /dev/tts/0
but a blank line appears!
I also tried:
read LINE /dev/tts/0
after which Linux won't return the control to the prompt, as if it is waiting for data to appear on the serial port (then I use ctrl+c to break it).

I am sure that the motor controller is functioning and sensor is sending data properly, because I have tested it by a different board. So the only problem I have is the lack of Linux knowledge probably!

Also, I tried to read it in a program:
Code:
result1 = write(dev_tts0_fd, "A", 1);

if(result1<0)
{
	printf("can't write to serial port\n");
	exit(1);
}

sleep(1);

bytes_read = read (dev_tts0_fd, next_byte, sizeof (next_byte));
if(bytes_read<=0)
{
	printf("can't read from serial port\n");
	exit(1);
}
which returns: can't read from serial port!

Please give a hint!
Thank you!
 
Old 03-02-2010, 09:31 AM   #2
fpmurphy
Member
 
Registered: Jan 2009
Location: /dev/ph
Distribution: Fedora, Ubuntu, Redhat, Centos
Posts: 297

Rep: Reputation: 62
This FAQ might help you: http://tldp.org/HOWTO/Serial-Programming-HOWTO/
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
read serial port fails willydlw Linux - Newbie 1 04-08-2009 02:46 PM
Difficult to read serial port omwoyo Programming 3 07-03-2007 07:47 AM
When to read from the serial port? kad_79 Programming 3 06-15-2006 03:39 PM
Problem with Non-blocking serial port read ZX_SA Programming 0 01-18-2005 09:50 AM
Serial port Read Write SeanatIL Programming 2 07-14-2004 04:42 PM


All times are GMT -5. The time now is 03:09 AM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration