Sorry I forgot to attach my sample program in the first mail. here I have attached that. Hi Daniel, Thank you very much once again.Even though you don't know what my problem is, you are trying to help me. Thank you very much. Here I have attached a sample code which explains what I am trying to do and what the problem I am facing. I have given comments to explain my problem. please have a look at this program and try to help me!.
On 2/19/07, SaiKamesh Rathinasabapathy <[EMAIL PROTECTED]> wrote:
On 2/18/07, Daniel Elstner <[EMAIL PROTECTED]> wrote: > > Am Samstag, den 17.02.2007, 19:19 +0530 schrieb SaiKamesh > Rathinasabapathy: > > > I have already written a program in c++, which reads the data from the > > serial port. > > So I have no problem in reading the data from the barcode reader which > > > is connected to the serial port. > > Okay, then I don't know what your problem is. The thing is, the answer > to your question very much depends on the context. Without any context, > it's nearly impossible to help you. The answer might boil down to "hide > > it" or "delete it", but I reckon you'd have figured that out by yourself > if it really was that trivial. > > So, why don't you send us a sample program that roughly shows what > you're actually trying to do? And please CC to the list, too. > > > My problem is, when I run my application a window should be opened, > > that has a label on it "Scan the barcode using scanner". then I have > > to read the barcode, after reading the barcode the window should > > automatically be closed, then a new window should be opened. > > I don't know how to close the first window automatically, after > > reading the barcode. plz help me to so this. > > > If possible send me sample program. > > I already said that I don't have such a sample program. > > --Daniel > > > Hi Daniel, Thank you very much once again.Even though you don't know what my problem is, you are trying to help me. Thank you very much. Here I have attached a sample code which explains what I am trying to do and what the problem I am facing. I have given comments to explain my problem. please have a look at this program and try to help me!.
#include <termios.h> #include <stdio.h> #include <unistd.h> #include <fcntl.h> #include <sys/signal.h> #include <sys/types.h> #include <stdlib.h> #include <string.h> #include <iostream> //library for reading the infos from the config file #include "simpleini/SimpleIni.h" //-------------------------------------------------- #include <mysql.h> #define host "localhost" #define username "root" #define password "admin" #define db "IrisDB" #define FALSE 0 #define TRUE 1 volatile int STOP = FALSE; int error; using namespace std; #include <gtkmm.h> class DeviceInterface : public Gtk::Window { public: long BAUD/*for device*/, DATABITS, STOPBITS, PARITYON, PARITY, BAUDRATE/*for keyboard*/; int BaudRate, Data_Bits, Stop_Bits, Parity; static int wait_flag; int fd, tty; struct termios oldtio, newtio; //place for old and new port settings for serial port struct termios oldkey, newkey;//place tor old and new port settings for keyboardteletype struct sigaction saio; //definition of signal action Gtk::VBox vbox; Gtk::Entry entry;// Entry which is used to display the login info. Gtk::Window wind;//window which is going to be displayed first,this window should be closed after recieving the signal from the serial port DeviceInterface() { //the following are placed in second window------------ maximize(); add(vbox); vbox.pack_start(entry, Gtk::PACK_SHRINK); show_all_children(); //----------------------------------------------------- CSimpleIniA ini(false, false, false); SI_Error rc = ini.LoadFile("ExampleConfig.ini"); //reading Barcode Reader info from config file ------ BaudRate = atoi(ini.GetValue("Barcode//for first windowReader Configuration", "BaudRate", NULL)); Data_Bits = atoi(ini.GetValue("BarcodeReader Configuration", "Data_Bits", NULL)); Stop_Bits = atoi(ini.GetValue("BarcodeReader Configuration", "Stop_Bits", NULL )); Parity = atoi(ini.GetValue("BarcodeReader Configuration", "Parity", NULL)); //---------------------------------------------------- //reading Keyboard info from config file ------------ BAUDRATE = atol(ini.GetValue("Keyboard Configuration", "BAUDRATE", NULL)); //---------------------------------------------------- wait_flag = TRUE; } /*----------------------------------------------------------------------------* * Serial port: initialise io_port, set baud rate, set data bits, one stop bit*/ int rs_initialise (int io_port/*, const long int BaudRate, const char parity*/) { // set new port settings for non-canonical input processing //must be NOCTTY newkey.c_cflag = BAUDRATE | CRTSCTS | CS8 | CLOCAL | CREAD; newkey.c_iflag = IGNPAR; newkey.c_oflag = 0; newkey.c_lflag = 0; //ICANON; newkey.c_cc[VMIN]=1; newkey.c_cc[VTIME]=0; tcflush(tty, TCIFLUSH); tcsetattr(tty,TCSANOW,&newkey); switch (BaudRate) { case 38400: default: BAUD = B38400; break; case 19200: BAUD = B19200; break; case 9600: BAUD = B9600; break; case 4800: BAUD = B4800; break; case 2400: BAUD = B2400; break; case 1800: BAUD = B1800; break; case 1200: BAUD = B1200; break; case 600: BAUD = B600; break; case 300: BAUD = B300; break; case 200: BAUD = B200; break; case 150: BAUD = B150; break; case 134: BAUD = B134; break; case 110: BAUD = B110; break; case 75: BAUD = B75; break; case 50: BAUD = B50; break; } //end of switch baud_rate switch (Data_Bits) { case 8: default: DATABITS = CS8; break; case 7: DATABITS = CS7; break; case 6: DATABITS = CS6; break; case 5: DATABITS = CS5; break; } //end of switch data_bits switch (Stop_Bits) { case 1: default: STOPBITS = 0; break; case 2: STOPBITS = CSTOPB; break; } //end of switch stop bits switch (Parity) { case 0: default: //none PARITYON = 0; PARITY = 0; break; case 1: //odd PARITYON = PARENB; PARITY = PARODD; break; case 2: //even PARITYON = PARENB; PARITY = 0; break; } //end of switch parity //open the device(com port) to be non-blocking (read will return immediately) fd = open("/dev/ttyS0", O_RDWR | O_NOCTTY | O_NONBLOCK); if (fd < 0) { perror("/dev/ttyS0"); return 0; } //install the serial handler before making the device asynchronous saio.sa_handler = signal_handler_IO; sigemptyset(&saio.sa_mask); //saio.sa_mask = 0; saio.sa_flags = 0; saio.sa_restorer = NULL; sigaction(SIGIO,&saio,NULL); // allow the process to receive SIGIO fcntl(fd, F_SETOWN, getpid()); // Make the file descriptor asynchronous (the manual page says only // O_APPEND and O_NONBLOCK, will work with F_SETFL...) fcntl(fd, F_SETFL, O_ASYNC);//FASYNC); tcgetattr(fd,&oldtio); // save current port settings // set new port settings for canonical input processing newtio.c_cflag = BAUD | CRTSCTS | DATABITS | STOPBITS | PARITYON | PARITY | CLOCAL | CREAD; newtio.c_iflag = IGNPAR; newtio.c_oflag = 0; newtio.c_lflag = 0; //ICANON; newtio.c_cc[VMIN]=1; newtio.c_cc[VTIME]=0; tcflush(fd, TCIFLUSH); tcsetattr(fd,TCSANOW,&newtio); return 1; // OK } /*----------------------------------------------------------------------------* * Serial port: terminate io_port, sets DTR and RTS to low */ void rs_terminate(const int io_port) { // restore old port settings tcsetattr(fd,TCSANOW,&oldtio); tcsetattr(tty,TCSANOW,&oldkey); close(fd); //close the com port } /*----------------------------------------------------------------------------* * Serial port: read character from io_port (ignored in this version) */ char rs_getch(const int io_port) { static char buf[255]; // buffer for where data is put static int index = 0, count = 0; // check if data already in input buffer - if so return a character if(count>0) { count--; return buf[index++];} // otherwise check if any characters receivedfrom serial line if (wait_flag==FALSE) //if input is available { count = read(fd,buf,255); wait_flag = TRUE; /* wait for new input */ index=0; count--; //count++; return buf[index++]; // return first character } return 0; // return 0 if no character read } /************************************************** ************************* * signal handler. sets wait_flag to FALSE, to indicate above loop that * * characters have been received. * ************************************************** *************************/ static void signal_handler_IO (int status) { // printf("\n received SIGIO signal.\n"); wait_flag = FALSE; } }; int DeviceInterface::wait_flag;//this is a static variable, thats y // main terminal program int main(int argc, char *argv[]) { Gtk::Main kit(argc, argv); DeviceInterface obj; Gtk::Label label1("SWIPE THE CARD TO LOG IN");//for first window obj.wind.maximize();//for first window obj.wind.add(label1);//for first window obj.wind.show_all_children();//for first window int temp = 0; char buffer[600]; int i = 0; int port = 1; error=0; // open the RS232 serial line if(!obj.rs_initialise(port)) { exit(1); }//initializing the serial port Gtk::Main::run(obj.wind);// displaying the first window char letter; while(!STOP) { if((letter=obj.rs_getch(port))>0) // getting the data from the serial port charecter by charecter and storing those values in a charecter array. { buffer[i] = letter; i++; } if(strlen(buffer) >= 119) { temp = 1; break; } } if(temp == 1) { obj.wind.hide();//here i want to close the first window, but it is not working. } MYSQL *conn1; MYSQL_RES *res_set1; MYSQL_ROW row; conn1 = mysql_init(NULL);// initializing the connection mysql_real_connect(conn1,host,username,password,db,0,NULL,0); mysql_query(conn1, ("select * from tblLogin")); res_set1 = mysql_store_result(conn1); if((row = mysql_fetch_row(res_set1)) != NULL) { if(strcmp(row[0], buffer) == 0) { obj.entry.set_text("You are a valid user");//this message will be displayed in the entry of the second window,in the case of valid user } else { obj.entry.set_text("You are not a valid user");//this message will be displayed in the entry of the second window,in the case of invalid user } } Gtk::Main::run(obj);//this displays the second window, which contains an Gtk::entry on it,in that entry "you are a valid user" or "you are not a valid user" message will be displayed. obj.rs_terminate(port);//closing the serial port return 0; }
_______________________________________________ gtkmm-list mailing list gtkmm-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtkmm-list