Help answer threads with 0 replies.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


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

Rep: Reputation: 16
read serial port problem

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:
result1 = write(dev_tts0_fd, "A", 1);

	printf("can't write to serial port\n");


bytes_read = read (dev_tts0_fd, next_byte, sizeof (next_byte));
	printf("can't read from serial port\n");
which returns: can't read from serial port!

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

Rep: Reputation: 62
This FAQ might help you:


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 > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:01 AM.

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