source: projects/punch-card/punch-card-editor/src/libs/qextserialport/examples/qespta/QespTest.cpp @ 53

Last change on this file since 53 was 53, checked in by sven, 14 years ago

Punch Card Editor, ongoing development

  • Extended new Deck interface, expanding the undo framework
  • Implemented editor changes via undo framework
  • revised the menu and toolbar actions and structure (now dynamic construction at deck load time), implemented undo viewer
  • Started implementation of device driver framework in menu
  • Embedded the Qextserialport library (http://qextserialport.sourceforge.net/)
  • Started the Documation M200 Client device driver (well, just created the directory structure and qmake project file infrastructure)
  • At the current state, the complete project compiles :-)

Statistics: About 3500 Lines of code (without libqextserialport)

-- sven @ workstation

  • Property svn:executable set to *
File size: 2.9 KB
Line 
1/* qesptest.cpp
2**************************************/
3#include "qesptest.h"
4#include <qextserialport.h>
5#include <QLayout>
6#include <QLineEdit>
7#include <QTextEdit>
8#include <QPushButton>
9#include <QSpinBox>
10
11QespTest::QespTest(QWidget* parent) 
12        : QWidget(parent)
13
14{
15    //modify the port settings on your own
16  port = new QextSerialPort("COM1");
17  port->setBaudRate(BAUD19200);   
18  port->setFlowControl(FLOW_OFF);
19  port->setParity(PAR_NONE);   
20  port->setDataBits(DATA_8);   
21  port->setStopBits(STOP_2);   
22
23  message = new QLineEdit(this);
24
25  // transmit receive
26  QPushButton *transmitButton = new QPushButton("Transmit");
27  connect(transmitButton, SIGNAL(clicked()), SLOT(transmitMsg()));
28  QPushButton *receiveButton = new QPushButton("Receive");
29  connect(receiveButton, SIGNAL(clicked()), SLOT(receiveMsg()));
30  QHBoxLayout* trLayout = new QHBoxLayout;
31  trLayout->addWidget(transmitButton);
32  trLayout->addWidget(receiveButton);
33 
34        //CR LF
35  QPushButton *CRButton = new QPushButton("CR");
36  connect(CRButton, SIGNAL(clicked()), SLOT(appendCR()));
37  QPushButton *LFButton = new QPushButton("LF");
38  connect(LFButton, SIGNAL(clicked()), SLOT(appendLF()));
39  QHBoxLayout *crlfLayout = new QHBoxLayout;
40  crlfLayout->addWidget(CRButton);
41  crlfLayout->addWidget(LFButton);
42
43        //open close
44  QPushButton *openButton = new QPushButton("Open");
45  connect(openButton, SIGNAL(clicked()), SLOT(openPort()));
46  QPushButton *closeButton = new QPushButton("Close");
47  connect(closeButton, SIGNAL(clicked()), SLOT(closePort()));
48  QHBoxLayout *ocLayout = new QHBoxLayout;
49  ocLayout->addWidget(openButton);
50  ocLayout->addWidget(closeButton);
51
52  received_msg = new QTextEdit();
53 
54  QVBoxLayout *myVBox = new QVBoxLayout;
55  myVBox->addWidget(message);
56  myVBox->addLayout(crlfLayout);
57  myVBox->addLayout(trLayout);
58  myVBox->addLayout(ocLayout);
59  myVBox->addWidget(received_msg);
60  setLayout(myVBox);
61
62  qDebug("isOpen : %d", port->isOpen());
63}
64
65QespTest::~QespTest()
66{
67    delete port;
68    port = NULL;
69}
70
71void QespTest::transmitMsg()
72{
73  int i = port->write((message->text()).toAscii(),
74                       (message->text()).length());
75  qDebug("trasmitted : %d", i);
76}
77
78void QespTest::receiveMsg()
79{
80        char buff[1024];
81        int numBytes;
82 
83        numBytes = port->bytesAvailable();
84        if(numBytes > 0) 
85        {
86            if(numBytes > 1024) numBytes = 1024;
87       
88            int i = port->read(buff, numBytes);
89                buff[i] = '\0';
90            QString msg = buff;
91       
92                received_msg->append(msg);
93                received_msg->ensureCursorVisible();
94                qDebug("bytes available: %d", numBytes);
95                qDebug("received: %d", i);
96  }
97}
98
99
100void QespTest::appendCR()
101{
102        message->insert("\x0D");
103}
104
105void QespTest::appendLF()
106{
107        message->insert("\x0A");
108}
109
110void QespTest::closePort()
111{
112        port->close();
113        qDebug("is open: %d", port->isOpen());
114}
115
116void QespTest::openPort()
117{
118        port->open(QIODevice::ReadWrite);
119        qDebug("is open: %d", port->isOpen());
120}
121
Note: See TracBrowser for help on using the repository browser.
© 2008 - 2013 technikum29 • Sven Köppel • Some rights reserved
Powered by Trac
Expect where otherwise noted, content on this site is licensed under a Creative Commons 3.0 License