LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
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 05-30-2009, 05:09 AM   #1
Priyachu
LQ Newbie
 
Registered: May 2009
Posts: 2

Rep: Reputation: 0
Duplex communication thro serial port


Hi,

I am writing an application in C on a Beagleboard (running Ubuntu) which reads sound samples from a microphone (using ALSA APIs), compresses them and writes it to the serial port to a radio (which broadcasts it). For duplex communication, i need to receive the data from the radio (by reading from the serial port), uncompress it and send it to the speaker (again through ALSA APIs). The problem here is that the whole operation is performed in a loop. I am writing byte by byte into the port and sending it to the radio. However the radio writes 80 bytes as and when it receives a packet and there is no synchronization between the two devices. Effectively i am unable to read any data from the serial port. Can anyone suggest a better method of implementation ?

Thanks in advance,
Priya.
 
Old 05-30-2009, 09:49 AM   #2
mknirsch
Member
 
Registered: Feb 2003
Location: Germany
Distribution: SLES 10, SuSe 11.x
Posts: 31

Rep: Reputation: 16
Hello Priyachu,

when I get you right you send out and receive data from a character device; all within a single loop. You miss synchronization between the I/o packets and you are unable to receive data.

Let us start with your devices. Take a look into the /dev path:
# ls -l /dev/*tty*
The device files listed in /dev are interfaces to the (device)drivers. The ls command also shows the major number - the driver number of a system device. When you check the /dev directory you probably will notice that many devicefiles share one major number. The serial interface for example has many major numbers even it is still the same physical interface. The various numbers represent different drivers assigned to that interface, terminals, modems etc.
First please check that you are using the right driver, not a terminal driver for example for your serial communication.

The R/W access to character devices utilizes file I/O. You already know this from I/O redirection in your shell. The command
# cat readme.txt > /dev/lp0
redirects the terminal I/O of the file "readme.txt" to the local printer. In a c code you of course can do the same:
int fd; # filedescriptor
fd = open( /dev/stty0", O_RDWR); # alow all I/O
if (fd >= 0)
write(fd, buffer, buffersize);
close(fd)
Use the system function ioctl to gain complete control over your block device and do not forget to fflush your I/O buffers.

Martin
 
Old 06-09-2009, 01:10 PM   #3
Priyachu
LQ Newbie
 
Registered: May 2009
Posts: 2

Original Poster
Rep: Reputation: 0
Thanks Martin. I am now using two separate threads - one for reading from the mic and writing to the serial port and the other for reading from the serial port and writing to the speaker. I am facing another problem here. The speaker expects samples at 8kHz. So I am using a non blocking read to get 80 bytes from the serial port and passing it as soon as possible to the speaker. Here again I have synchronization issues because of the non blocking read. I am not able to get 80 bytes. A blocking read may not provide data at the required speed. Please suggest what can be done.

Thanks,
Priya.
 
  


Reply

Tags
port, programming, serial


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
serial port communication vidyaraj Linux - Software 2 03-15-2004 12:32 AM
communication with serial port vidyaraj Linux - Hardware 0 03-09-2004 09:32 PM
serial port communication vidyaraj Linux - Software 6 03-02-2004 07:46 PM
communication via serial port perdesiz Linux - Software 0 11-13-2003 07:23 AM
how to create ppp server in RH 7.2 as small ISP thro serial port pentium5 Linux - General 5 07-06-2002 07:35 AM


All times are GMT -5. The time now is 09:04 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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration