I have tiny6410 code that read data from serial port.
here is my source code :
--------------------------------------------------------
#include "mainwindow.h"
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <stdio.h> /* Standard input/output definitions */
#include <string.h> /* String function definitions */
#include <unistd.h> /* UNIX standard function definitions */
#include <fcntl.h> /* File control definitions */
//#include <errno.h> /* Error number definitions */
#include <termios.h> /* POSIX terminal control definitions */
#include <string> /*To use string type*/
#include <iostream>
#include<string>
#include <QtSql/qsql.h>
using namespace std;
//--------------------------------------------
int fd; /* File descriptor for the port */
#define MAXDATASIZE 100
//-------------------------------------
void closeport(void)
{
close(fd);
}
//-------------------------------------
void configport(void)
{
struct termios tty;
struct termios tty_old;
memset (&tty, 0, sizeof tty);
/* Error Handling */
if ( tcgetattr ( fd, &tty ) != 0 ) {
// std::cout << "Error " << errno << " from tcgetattr: " <<
strerror(errno) << std::endl;
}
/* Save old tty parameters */
tty_old = tty;
/* Set Baud Rate */
cfsetospeed (&tty, (speed_t)B9600);
cfsetispeed (&tty, (speed_t)B9600);
/* Setting other Port Stuff */
tty.c_cflag &= ~PARENB; // Make 8n1
tty.c_cflag &= ~CSTOPB;
tty.c_cflag &= ~CSIZE;
tty.c_cflag |= CS8;
tty.c_cflag &= ~CRTSCTS; // no flow control
tty.c_cc[VMIN] =1;// 0; // read doesn't block
tty.c_cc[VTIME] = 10;// 2 but befor it 5; // 0.5
seconds read timeout
tty.c_cflag |= CREAD | CLOCAL; // turn on READ & ignore ctrl
lines
/* Make raw */
cfmakeraw(&tty);
/* Flush Port, then applies attributes */
tcflush( fd, TCIFLUSH );
if ( tcsetattr ( fd, TCSANOW, &tty ) != 0) {
// std::cout << "Error " << errno << " from tcsetattr" << std::endl;
}
}
//------------------------------------
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_pushButton_clicked()
{
int numbytes;
char buf2[MAXDATASIZE];
QString portname="ttySAC3";//ui->txtport->text();
//QString portname=ui->txtport->text();
portname="/dev/"+portname;
fd=open(portname.toLatin1().data(),O_RDWR|O_NOCTTY|O_NDELAY);
if (fd==-1)
{
ui->lblerr->setText("unable to open port ");
return;
}
else
{
ui->lblerr->setText("<span style='color:green;'>succesfully open
port </span>");
fcntl(fd,F_SETFL,0);
//*****************************
// SerialCodes
//*****************************]
ui->txtcardno->setText("befor fork");
if(!fork())
{
ui->txtcardno->setText("befor while");
while(1)
{
memset(buf2,'\0',MAXDATASIZE);
ui->txtcardno->setText("befor read");
//------------------------------------------------
if ((numbytes = read(fd,buf2, MAXDATASIZE-1)) == -1)
{
ui->txtcardno->setText("Error");
}
else
{
ui->txtcardno->setText("");
buf2[numbytes] = '\0';
//printf("RFID MONITORING => '%s'\n",buf2);
//QString s(buf2);
ui->txtcardno->setText("ok......................");
//break;
}
}
}
}
}
-------------------------------------------------------
all of these code run except fork block. ui->txtcardno->setText("befor
fork");just txtcardno text is befor fork. and then nothing happan.
why the application does not run fork code block?

