#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QtCore>
#include <QtGui>
#include "databaseconnection.h";
#include <mythread.h>
#include <QThread>
#include <QMutex>
#include "mysecondthread.h"
#include <QtSql>
#include <QDebug>
#include "qextserialport.h"
#include "qextserialenumerator.h"
QextSerialPort *port = new QextSerialPort("COM1",QextSerialPort::EventDriven);
MainWindow
::MainWindow(QWidget *parent
) : ui(new Ui::MainWindow)
{
// if(databaseconnection::databse()){
// QMessageBox::information(this,"connected","connected");
// }
// else if(!(databaseconnection::databse())){
// QMessageBox::information(this,"connected failed","failed");
// }
Mythread cob;
port=new QextSerialPort();
port->setBaudRate(BAUD9600);
port->setFlowControl(FLOW_XONXOFF);
port->setParity(PAR_NONE);
port->setDataBits(DATA_8);
port->setStopBits(STOP_1);
connect(port,SIGNAL(readyRead()),this,SLOT(on_pushButton_clicked()));
QList<QextPortInfo> ports = QextSerialEnumerator::getPorts();
ui->setupUi(this);
foreach (QextPortInfo info, ports) {
qDebug() << "port name:" << info.portName;
ui->portlab->addItem(info.portName);
}
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_pushButton_clicked()
{
//qDebug()<<"no data to read";
if(port->isOpen()){
if(port->write(command.toHex())){
qDebug()<<"written";
}
if(data==""){
qDebug()<<"no data to read"<<data;
ui->labelread->setText("wait while trying to read="+data);
}
else if(data.size()==3&& (data.startsWith("H"))){
qDebug()<<data;
ui->labelread->setText("the data read="+data);
} //data.data();
// QMessageBox::information(this,"opened","opened");
}
else{
}
//connect(port, SIGNAL(readyRead()), this, SLOT(onDataAvailable()));
//port->open();
}
void MainWindow::on_pushButton_2_clicked()
{
bb= "oloo";
idn="9000";
query.prepare("INSERT INTO user (name, idno) "
"VALUES (:name, :idno)");
query.bindValue(":name", bb);
query.bindValue(":idno", idn);
// query.exec();
if(query.exec()){
qDebug()<<" inserted connected";
}else{
qDebug()<<" not insert connected";
}
}
void MainWindow::on_pushButton_3_clicked()
{
if(port->isOpen()){
if(port->write(command.append(n))){
qDebug()<<"written";
}
else{
qDebug()<<" not written";
}
}
}
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QtCore>
#include <QtGui>
#include "databaseconnection.h";
#include <mythread.h>
#include <QThread>
#include <QMutex>
#include "mysecondthread.h"
#include <QtSql>
#include <QDebug>
#include "qextserialport.h"
#include "qextserialenumerator.h"
QextSerialPort *port = new QextSerialPort("COM1",QextSerialPort::EventDriven);
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
// if(databaseconnection::databse()){
// QMessageBox::information(this,"connected","connected");
// }
// else if(!(databaseconnection::databse())){
// QMessageBox::information(this,"connected failed","failed");
// }
Mythread cob;
port=new QextSerialPort();
port->setBaudRate(BAUD9600);
port->setFlowControl(FLOW_XONXOFF);
port->setParity(PAR_NONE);
port->setDataBits(DATA_8);
port->setStopBits(STOP_1);
port->open(QIODevice::ReadWrite);
connect(port,SIGNAL(readyRead()),this,SLOT(on_pushButton_clicked()));
QList<QextPortInfo> ports = QextSerialEnumerator::getPorts();
ui->setupUi(this);
foreach (QextPortInfo info, ports) {
qDebug() << "port name:" << info.portName;
ui->portlab->addItem(info.portName);
}
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_pushButton_clicked()
{
//qDebug()<<"no data to read";
if(port->isOpen()){
QByteArray command="0x03";
QString data = port->readAll();
if(port->write(command.toHex())){
qDebug()<<"written";
}
if(data==""){
qDebug()<<"no data to read"<<data;
ui->labelread->setText("wait while trying to read="+data);
}
else if(data.size()==3&& (data.startsWith("H"))){
qDebug()<<data;
ui->labelread->setText("the data read="+data);
} //data.data();
// QMessageBox::information(this,"opened","opened");
}
else{
QMessageBox::warning(this,"error","error");
}
//connect(port, SIGNAL(readyRead()), this, SLOT(onDataAvailable()));
//port->open();
}
void MainWindow::on_pushButton_2_clicked()
{
QString bb,idn;
bb= "oloo";
idn="9000";
QSqlQuery query;
query.prepare("INSERT INTO user (name, idno) "
"VALUES (:name, :idno)");
query.bindValue(":name", bb);
query.bindValue(":idno", idn);
// query.exec();
if(query.exec()){
qDebug()<<" inserted connected";
}else{
qDebug()<<" not insert connected";
}
}
void MainWindow::on_pushButton_3_clicked()
{
if(port->isOpen()){
QString n="0x02";
QByteArray command;
QString data = port->readAll();
if(port->write(command.append(n))){
qDebug()<<"written";
}
else{
qDebug()<<" not written";
}
}
}
To copy to clipboard, switch view to plain text mode
am not able to receive any response from the device.
Bookmarks