The Raspberry pi is a device which uses the Broadcom controller chip which is a SoC (System on Chip). This SoC has the ARM11 processor which runs on 700 MHz at its core. The operating systems like Archlinux ARM, OpenELEC, Pidora, Raspbmc, RISC OS and the Raspbian and also Ubuntu versions are available for the Raspberrypi board. Linux operating systems especially Ubuntu is preferred for all kind of programming and development. The Raspberrypi is a board actually designed for helping computer education for remote schools but it is a nice platform for programmers especially beginners to explore various coding techniques.
The function mkfifo() creates a temporary file at the required directory with the required access permissions set on it. The prototype of the function is declared as the following;
The first argument is the required pathname of the directory where the named pipe needs to be created. The second argument is the user permission that needs to be set on the file. Using the value 0777 as the second argument allows permission to all users of the system to read from and write into that named pipe. For using this function in the C code, two header files <sys/types.h> and <sys/stat.h> should be included.
The open () function opens a particular file at a specified path with the required flags set and it returns a file descriptor corresponding to that file to the process which called the open function. Using that file descriptor the process can access the file.
#include <unistd.h> #include <stdlib.h> #include <stdio.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h>
#define OUR_INPUT_FIFO_NAME “/tmp/my_fifo”
unsigned char rx_buffer [ 256 ];
int rx_length;
int our_input_fifo_filestream = -1;int result;
int main (){printf ( “Making FIFO…\n” );
result = mkfifo ( OUR_INPUT_FIFO_NAME, 0777 );
our_input_fifo_filestream = open ( OUR_INPUT_FIFO_NAME, ( O_RDONLY | O_NONBLOCK ) );
while ( 1 )
{rx_length = read ( our_input_fifo_filestream, ( void* ) rx_buffer, 255 ); //Filestream, buffer to store in, number of bytes to read (max)
if ( rx_length > 0 )
{rx_buffer [ rx_length ] = ‘\0’;
printf ( “FIFO %i bytes read : %s\n”, rx_length, rx_buffer );}else;}}