Application to read & display



HI!!
 I'm trying to make an application to display images from a frame grabber, at the same time i want
to read the serial port and display the data that's sent to me, the problems is when i open the
serial port the program don't display nothing.
The programs is to display is

#include <sys/time.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>

#include "include/FrameGrabber.hh"
#include "include/Read.hh"
#include "gtk.h"

#define WIDTH 384
#define HEIGHT 288

FrameGrabber *pGrabber;
Read *pRead;
void  *image_mmaped;
int nImSize;
int Wdes;
char Valor;


guchar bufIm[768*576*20];
guchar *pImColor;
GtkWidget *window;
GtkWidget *window_pack;
GtkWidget *top_pack;
GtkWidget *packer;
GtkWidget *button_pack;
GtkWidget *button_add;
GtkWidget *drawing_area;
GtkWidget *button_quit;
GtkWidget *bottom_pack;
GtkWidget *side_frame;
GtkWidget *button_top;
GtkWidget *button_right;
GtkWidget *button_bottom;
GtkWidget *button_left;
GtkWidget *side_pack;
GtkWidget *anchor_pack;

GtkWidget *anchor_frame;
GtkWidget *options_frame;

GtkWidget *options_pack;
GtkWidget *drawing_area2;

GdkGC dummy;
GtkWidget *frame_vert;


int SiguienteFrame();
void *new_testrgb_window(void *);
gint testrgb_rgb_cb(gpointer data);
char LeePuerto ();

void callback(GtkWidget *widget,gpointer data){
  g_print("delete event\n");
}


gint quit_func (GtkWidget *widget, gpointer dummy){
  gtk_main_quit ();
  return false;
}




void testrgb_rgb_test (GtkWidget *drawing_area){

  Wdes=gtk_timeout_add(100,testrgb_rgb_cb,drawing_area);

}

int testrgb_rgb_cb (gpointer data){

  GtkWidget *drawing_area=(GtkWidget*)data;
  SiguienteFrame();

  gdk_draw_gray_image (drawing_area->window, drawing_area->style->white_gc,
   0, 0, WIDTH+10, HEIGHT+10, GDK_RGB_DITHER_NONE,
         bufIm, WIDTH);

   return true;

}


void *new_testrgb_window(void *arg){

  window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
  gtk_signal_connect (GTK_OBJECT (window), "destroy",
        GTK_SIGNAL_FUNC (quit_func), NULL);

  window_pack = gtk_packer_new();
  gtk_container_add(GTK_CONTAINER(window), window_pack);
  gtk_container_border_width(GTK_CONTAINER(window), 4);

  top_pack = gtk_packer_new();
  gtk_packer_add_defaults(GTK_PACKER(window_pack),
     top_pack,
     GTK_SIDE_TOP,
     GTK_ANCHOR_CENTER,
     GTK_FILL_X);

  drawing_area = gtk_drawing_area_new();
  gtk_widget_set_usize(drawing_area, 400, 400);

  gtk_packer_add(GTK_PACKER(top_pack),
   drawing_area,
   GTK_SIDE_LEFT,
   GTK_ANCHOR_CENTER,
   GTK_FILL_X,
   0, 8, 8, 0, 0);
  packer = gtk_packer_new();
  gtk_container_add(GTK_CONTAINER(drawing_area), packer);

  button_pack = gtk_packer_new();
  gtk_packer_add(GTK_PACKER(top_pack),
   button_pack,
   GTK_SIDE_LEFT,
   GTK_ANCHOR_N,
   GTK_FILL_X,
   0, 0, 0, 0, 0);


  button_quit = gtk_button_new_with_label("Quit");
  gtk_packer_add(GTK_PACKER(top_pack),
   button_quit,
   GTK_SIDE_TOP,
   GTK_ANCHOR_CENTER,
   GTK_FILL_X,
   0, 8, 8, 0, 0);

  gtk_signal_connect_object (GTK_OBJECT (button_quit), "clicked",
        GTK_SIGNAL_FUNC (quit_func),
        GTK_OBJECT (window));


  bottom_pack = gtk_packer_new();
  gtk_packer_add_defaults(GTK_PACKER(window_pack),
     bottom_pack,
     GTK_SIDE_TOP,
     GTK_ANCHOR_CENTER,
     GTK_FILL_X);



  /********************************************************
   **Creamos un frame y botones para el servo A
   **
   *********************************************************/




    side_frame = gtk_frame_new("Servo  A");
    gtk_packer_add(GTK_PACKER(window_pack),
                   side_frame,
                   GTK_SIDE_LEFT,
                   GTK_ANCHOR_W,
                   GTK_FILL_Y,
                   0, 10, 10, 0, 0);

    side_pack = gtk_packer_new();
    gtk_container_add(GTK_CONTAINER(side_frame), side_pack);

    button_top = gtk_button_new_with_label("Up");
    button_bottom = gtk_button_new_with_label("Down");
    button_left = gtk_button_new_with_label("Left");
    button_right = gtk_button_new_with_label("Right");


    gtk_widget_set_usize(button_top, 50, -1);
    gtk_widget_set_usize(button_bottom, 50, -1);
    gtk_widget_set_usize(button_left, 50, -1);
    gtk_widget_set_usize(button_right, 50, -1);
    gtk_packer_add(GTK_PACKER(side_pack),
                   button_top,
                   GTK_SIDE_TOP,
                   GTK_ANCHOR_CENTER,
                   GTK_FILL_Y,
                   0, 5, 5, 0, 0);
    gtk_packer_add(GTK_PACKER(side_pack),
                   button_bottom,
                   GTK_SIDE_BOTTOM,
                   GTK_ANCHOR_CENTER,
                   GTK_FILL_Y,
                   0, 5, 5, 0, 0);
    gtk_packer_add(GTK_PACKER(side_pack),
                   button_left,
                   GTK_SIDE_LEFT,
                   GTK_ANCHOR_CENTER,
                   GTK_FILL_Y,
                   0, 10, 5, 0, 0);
    gtk_packer_add(GTK_PACKER(side_pack),
                   button_right,
                   GTK_SIDE_RIGHT,
                   GTK_ANCHOR_CENTER,
                   GTK_FILL_Y,
                   0, 10, 5, 0, 0);

    /********************************************************
     **Creamos un frame  y botones para controlar el servo B
     **
     *********************************************************/

    anchor_frame = gtk_frame_new("Servo B");
    gtk_packer_add(GTK_PACKER(window_pack),
                   anchor_frame,
                   GTK_SIDE_LEFT,
                   GTK_ANCHOR_W,
                   GTK_FILL_Y,
                   0, 10, 10, 0, 0);

    anchor_pack = gtk_packer_new();
    gtk_container_add(GTK_CONTAINER(anchor_frame), anchor_pack);

    button_top = gtk_button_new_with_label("Up");
    button_bottom = gtk_button_new_with_label("Down");
    button_left = gtk_button_new_with_label("Left");
    button_right = gtk_button_new_with_label("Right");


    gtk_widget_set_usize(button_top, 50, -1);
    gtk_widget_set_usize(button_bottom, 50, -1);
    gtk_widget_set_usize(button_left, 50, -1);
    gtk_widget_set_usize(button_right, 50, -1);
    gtk_packer_add(GTK_PACKER(anchor_pack),
                   button_top,
                   GTK_SIDE_TOP,
                   GTK_ANCHOR_CENTER,
                   GTK_FILL_Y,
                   0, 5, 5, 0, 0);
    gtk_packer_add(GTK_PACKER(anchor_pack),
                   button_bottom,
                   GTK_SIDE_BOTTOM,
                   GTK_ANCHOR_CENTER,
                   GTK_FILL_Y,
                   0, 5, 5, 0, 0);
    gtk_packer_add(GTK_PACKER(anchor_pack),
                   button_left,
                   GTK_SIDE_LEFT,
                   GTK_ANCHOR_CENTER,
                   GTK_FILL_Y,
                   0, 10, 5, 0, 0);
    gtk_packer_add(GTK_PACKER(anchor_pack),
                   button_right,
                   GTK_SIDE_RIGHT,
                   GTK_ANCHOR_CENTER,
                   GTK_FILL_Y,
                   0, 10, 5, 0, 0);


    /********************************************************
     **Creamos un frame para mostrar los datos que leeremos del
     **puerto
     *********************************************************/


    options_frame = gtk_frame_new("Datos");
    gtk_packer_add(GTK_PACKER(window_pack),
                   options_frame,
                   GTK_SIDE_LEFT,
                   GTK_ANCHOR_W,
                   GTK_FILL_Y,
                   0, 10, 10, 0, 0);

    options_pack = gtk_packer_new();
    gtk_container_add(GTK_CONTAINER(options_frame), options_pack);

    drawing_area2 = gtk_drawing_area_new();
    gtk_widget_set_usize(drawing_area2, 10, 10);
    gtk_packer_add(GTK_PACKER(options_pack),
                   drawing_area2,
                   GTK_SIDE_LEFT,
                   GTK_ANCHOR_W,
                   GTK_FILL_Y ,
                   0, 10, 10, 0, 0);


  gtk_widget_show_all(window);
  testrgb_rgb_test (drawing_area);

  return 0;

}

int SiguienteFrame(){

  pGrabber->LeeImagen(pImColor);

return 0;
}

char LeePuerto(){


  return pRead->LeerPuerto();

}


int main (int argc, char **argv){

  gtk_init (&argc, &argv);
  gdk_rgb_set_verbose (TRUE);
  pImColor=bufIm;
  gdk_rgb_init ();

  gtk_widget_set_default_colormap (gdk_rgb_get_cmap ());
  gtk_widget_set_default_visual (gdk_rgb_get_visual ());

  pGrabber=new FrameGrabber();  /* Frame Grabber*/
  pGrabber->GrabacionContinua(); /* Grab*/

  pRead=new Read();  /* Here i open the port */
                                    /*when i comment this line the program show images*/
/*just when i open the port ,without read, the programs can't show images*/


  new_testrgb_window(NULL);


  gtk_main ();

  return 0;

}
. AND I READ THE PORT WITH

#include "include/Read.hh"

Read::Read(){

if((fd = open(DEVICE, O_RDWR | O_NOCTTY ))<0);
      {perror(DEVICE); exit(-1); }

   tcgetattr(fd,&oldtio);
   bzero(&newtio, sizeof(newtio));

   newtio.c_cflag |= (BAUDRATE | CREAD | CLOCAL);
  newtio.c_cflag |=PARENB;
   newtio.c_cflag &=~PARODD;
   newtio.c_cflag &=~CSTOPB;
   newtio.c_cflag &=~CSIZE;
   newtio.c_cflag |=CS7;

   newtio.c_iflag =0;
  newtio.c_oflag = 0;
  newtio.c_lflag =0;
  newtio.c_cc[VTIME]    = 0;
  newtio.c_cc[VMIN]     = 1;


  tcflush(fd, TCIFLUSH);
  tcsetattr(fd,TCSANOW,&newtio);

 }


Read::~Read() {

  tcsetattr(fd,TCSANOW,&oldtio);
  close(fd);

}



char Read::LeerPuerto() {

  res = read(fd,buf,8);

  buf[1]='\0'; /* set end of string, so we can printf */
   //cout << (double)buf[0] << endl;
    return buf[0];
}
thanks i'll appreciate any help
regards





***************************************************************
Luis Mejias
luismejias hotmail com
________________________________________________________________
Computer Vision Group
http://www.disam.upm.es/vision
DISAM    lmejias etsii upm es
ETS Ingenieros Industriales   Phone: +34 91 7454660
Jose Gutierrez Abascal, 2               +34 91 3363061
28006 MADRID (SPAIN)           Fax:   +34 91 3363010
_________________________________________________________________





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]