Chinaunix首页 | 论坛 | 博客
  • 博客访问: 204598
  • 博文数量: 36
  • 博客积分: 2501
  • 博客等级: 少校
  • 技术积分: 420
  • 用 户 组: 普通用户
  • 注册时间: 2007-04-18 23:27
个人简介

时间就是一切。

文章分类

全部博文(36)

文章存档

2023年(1)

2017年(2)

2016年(6)

2014年(1)

2009年(1)

2008年(15)

2007年(10)

我的朋友

分类: C/C++

2008-02-09 20:35:37

/*serial.cpp*/

/****************************************************************************
** Form implementation generated from reading ui file 'serialport.ui'
**
** Created by: The User Interface Compiler ($Id: qt/main.cpp   3.3.6   edited Aug 31 2005 $)
**
** WARNING! All changes made in this file will be lost!
****************************************************************************/

#include "serialport.h"
#include "serialsend.h"
#include "serialrecv.h"
#include
#include
#include
//#include
#include
#include
#include
#include

/*
 *  Constructs a Form1 as a child of 'parent', with the
 *  name 'name' and widget flags set to 'f'.
 *
 *  The dialog will by default be modeless, unless you set 'modal' to
 *  TRUE to construct a modal dialog.
 */
Form1::Form1( QWidget* parent, const char* name, bool modal, WFlags fl )
    : QDialog( parent, name, modal, fl )
{
    if ( !name )
    setName( "SERIALPORT" );

    textLabel1 = new QLabel( this, "textLabel1" );
    textLabel1->setGeometry( QRect( 50, 30, 105, 60 ) );

    textLabel2 = new QLabel( this, "textLabel2" );
    textLabel2->setGeometry( QRect( 50, 200, 100, 53 ) );

    pushButton3 = new QPushButton( this, "pushButton3" );
    pushButton3->setGeometry( QRect( 60, 260, 81, 31 ) );

    pushButton2 = new QPushButton( this, "pushButton2" );
    pushButton2->setGeometry( QRect( 60, 100, 81, 31 ) );

    //textEdit1 = new QTextEdit( this, "textEdit1" );
    //textEdit1->setGeometry( QRect( 160, 60, 340, 130 ) );

   textEdit1=new QMultiLineEdit ( this, "textEdit1" );
   textEdit1->setGeometry( QRect( 160, 20, 380, 130 ) );

    //textEdit2 = new QTextEdit( this, "textEdit2" );
    //textEdit2->setGeometry( QRect( 160, 240, 341, 120 ) );

     textEdit2=new QMultiLineEdit ( this, "textEdit2" );
     textEdit2->setGeometry( QRect( 160, 190, 380, 130 ) );

    pushButton4 = new QPushButton( this, "pushButton4" );
    pushButton4->setGeometry( QRect( 330, 330, 100, 41 ) );
    languageChange();
    resize( QSize(600, 380).expandedTo(minimumSizeHint()) );
    clearWState( WState_Polished );

   connect( pushButton4, SIGNAL( clicked() ), this, SLOT(goodBye() ) );
   connect( pushButton2, SIGNAL( clicked() ), this, SLOT( serialS() ) );
   connect( pushButton3, SIGNAL( clicked() ), this, SLOT( serialR() ) );
}

/*
 *  Destroys the object and frees any allocated resources
 */
Form1::~Form1()
{
    // no need to delete child widgets, Qt does it all for us
}

/*
 *  Sets the strings of the subwidgets using the current
 *  language.
 */
void Form1::languageChange()
{
    setCaption( tr( "Serial port" ) );
    textLabel1->setText( tr( "please input\n"
"  your data \n"
"and press SEND" ) );
    textLabel2->setText( tr( "press RECEVIE \n"
" start receive\n"
"data" ) );
    pushButton3->setText( tr( "RECEIVE" ) );
    pushButton2->setText( tr( "SEND" ) );
    pushButton4->setText( tr( "EXIT" ) );
}
void Form1::goodBye()
{
                                                                                                        close(fd);
    tcsetattr(fd,TCSANOW,&termiosoldtio);
    close();
}

 /*serial.h*/

/****************************************************************************
** Form interface generated from reading ui file 'serialport.ui'
**
** Created by: The User Interface Compiler ($Id: qt/main.cpp   3.3.6   edited Aug 31 2005 $)
**
** WARNING! All changes made in this file will be lost!
****************************************************************************/

#ifndef FORM1_H
#define FORM1_H

#include
#include

class QVBoxLayout;
class QHBoxLayout;
class QGridLayout;
class QSpacerItem;
class QLabel;
class QPushButton;
//class QTextEdit;
class QMultiLineEdit;

class Form1 : public QDialog
{
    Q_OBJECT

public:
    Form1( QWidget* parent = 0, const char* name = 0, bool modal = FALSE, WFlags fl = 0 );
    ~Form1();

    QLabel* textLabel1;
    QLabel* textLabel2;
    QPushButton* pushButton3;
    QPushButton* pushButton2;
   // QTextEdit* textEdit1;
    //QTextEdit* textEdit2;
    QMultiLineEdit* textEdit1;
    QMultiLineEdit* textEdit2;
    QPushButton* pushButton4;

protected:

protected slots:
    virtual void languageChange();
   virtual void serialS();
   virtual void serialR();
  void goodBye();                                                                                 
};

#endif // FORM1_H

 

/*serialrecv.h*/

/*#include "serialport.h"
#include
#include
#include
#include
#include */
#include
//#include

void Form1::serialR()
 {
    QString str1,str2;
/*  int fd,resrecv;
    struct  termios termiosoldtio;
    struct termios newtio;
    char buf[255];
//  int  strbuf;
    printf("opening serial 0 \n");
    fd=open("/dev/tts/0",O_RDWR | O_NOCTTY );//| O_NDELAY);
    if(fd<0)
        {
            perror("/dev/tts/0");
            exit (1);
           
        }
    printf("serve oldserial\n");
    tcgetattr(fd,&termiosoldtio);
    printf("set newserial\n");
    bzero(&newtio,sizeof(newtio));
    newtio.c_cflag = B115200 | CS8 | CLOCAL | CREAD;
    newtio.c_iflag = IGNPAR;
    newtio.c_oflag = 0;
    newtio.c_lflag = 0;//ICANON;
    newtio.c_cc[VMIN] = 1;
    newtio.c_cc[VTIME] = 50;
    tcflush(fd,TCIFLUSH);
    tcsetattr(fd,TCSANOW,&newtio);
    printf(" output your data\n");
    */
//  while(1)
//      {
                    str1=textEdit1->text();
                    //lineEdit1->setText(str1);
                    //s1[0]=ch;
                    //ressend = write(fd,str1,1);
                    //resrecv = read(fd,buf,255);
                    //printf("%s\n", buf);
                    //for(strbuf=0;strbuf                        //buf[strbuf+1]=='\0';
                        textEdit2->setText(str1);
//      }

//  printf("exit\n");
    //close(fd);
    //tcsetattr(fd,TCSANOW,&termiosoldtio);
 }     

 

/*serialsend.h*/

#include "serialport.h"
#include
#include
#include
#include
#include
#include
#include

void Form1::serialS()
 {
    QString str1,str2;
    int fd,ressend;
    struct  termios termiosoldtio;
    struct termios newtio;
//  char s1[255];
    printf("opening serial 0 \n");
    fd=open("/dev/tts/0",O_RDWR | O_NOCTTY );//| O_NDELAY);
    if(fd<0)
        {
            perror("/dev/tts/0");
            exit (1);
           
        }
    printf("serve oldserial\n");
    tcgetattr(fd,&termiosoldtio);
    printf("set newserial\n");
    bzero(&newtio,sizeof(newtio));
    newtio.c_cflag = B115200 | CS8 | CLOCAL | CREAD;
    newtio.c_iflag = IGNPAR;
    newtio.c_oflag = 0;
    newtio.c_lflag = ICANON;
    //newtio.c_cc[VMIN] = 1;
    //newtio.c_cc[VTIME] = 10;
    tcflush(fd,TCIFLUSH);
    tcsetattr(fd,TCSANOW,&newtio);
    printf(" output your data\n");
    str1=textEdit1->text();
//  while(1)
//      {
                    str1=textEdit1->text();
                    //s1[0]=ch;
                    //s1[0]=str1;
                    textEdit2->setText(str1);
                    ressend = write(fd,str1,10);
                    //resrecv = read(fd,&buf,255);
                    //printf("%s\n", buf);
                    //textEdit2->setText(str1);
//      }

//  printf("exit\n");
//  textEdit2->setText(buf);
//  close(fd);
//  tcsetattr(fd,TCSANOW,&termiosoldtio);
 }
 


 

/*main.cpp*/

#include
#include "serialport.h"

/*
int main(int argc,char *argv[])
{
  QPEApplication app(argc,argv);
  Form1 *dialog = new Form1;
  app.setMainWidget(dialog);
  dialog->show();
  return app.exec();
}
*/

QTOPIA_ADD_APPLICATION("serilaport",Form1)
QTOPIA_MAIN
 

/*serial.pro*/

TEMPLATE = app

CONFIG  = qtopia warn_on release

HEADERS  = serialport.h \
   
  serialrecv.h \
   
  serialsend.h

SOURCES  = main.cpp \
   
  serialport.cpp

#INTERFACES =

TARGET  = serialport

/*serial.desktop*/

[Desktop Entry]

Comment=An Example Program

Exec=serialport

Icon=serialport

Type=Application

Name=serialport

阅读(1825) | 评论(1) | 转发(0) |
给主人留下些什么吧!~~

chinaunix网友2009-06-18 14:46:18

"serialport.h"在哪?