Skip to content
Snippets Groups Projects
Commit e124698b authored by Isabella Skořepová's avatar Isabella Skořepová
Browse files

Make test port appear in list and change name to path

parent f9faaa79
No related branches found
No related tags found
No related merge requests found
......@@ -9,6 +9,7 @@ Controller::Controller(QObject *parent) : QObject(parent), connection(QDBusConne
new PortAdaptor(port);
port->dbusPath.setPath("/fake/test0");
connection.registerObject(port->dbusPath.path(), port);
ports.append(port);
}
QStringList Controller::PortList() const
......@@ -43,11 +44,10 @@ void Controller::Autodetect()
// Detect new
for(QSerialPortInfo info: QSerialPortInfo::availablePorts()) {
qDebug() << info.portName();
qDebug() << info.systemLocation();
bool isInList = false;
for(Port *port : ports) {
qDebug() << port->Name();
if(info.portName() == port->Name()) {
if(info.systemLocation() == port->Name()) {
isInList = true;
break;
}
......
......@@ -9,6 +9,7 @@
Port::Port(QString name, quint8 type, QObject *parent) : QObject(parent), closeTimer(), autoCloseTimer(), readTimer(), serialPort(name)
{
this->name = name;
this->type = type;
closeTimer.setInterval(5000);
closeTimer.setSingleShot(true);
......@@ -32,7 +33,7 @@ Port::Port(QString name, quint8 type, QObject *parent) : QObject(parent), closeT
QString Port::Name() const
{
if(!Exists()) return QString("REMOVED");
return serialPort.portName();
return name;
}
qint32 Port::Baudrate() const
......@@ -87,18 +88,20 @@ void Port::Write(QByteArray data)
debugWrite.append(QString::number(byte, 16));
}
qDebug().nospace().noquote() << debugWrite;
if(!serialPort.isOpen()) {
if(serialPort.open(QSerialPort::WriteOnly)) {
qDebug() << " Autoopened port";
qDebug() << " Wrote" << serialPort.write(data) << "bytes";
serialPort.flush();
serialPort.close();
qDebug() << " Port was closed";
if(type == 0) {
if(!serialPort.isOpen()) {
if(serialPort.open(QSerialPort::WriteOnly)) {
qDebug() << " Autoopened port";
qDebug() << " Wrote" << serialPort.write(data) << "bytes";
serialPort.flush();
serialPort.close();
qDebug() << " Port was closed";
} else {
qDebug().nospace().noquote() << " Port autoopen failed (" << errorString() << ") - no data written";
}
} else {
qDebug().nospace().noquote() << " Port autoopen failed (" << errorString() << ") - no data written";
qDebug() << " Wrote" << serialPort.write(data) << "bytes";
}
} else {
qDebug() << " Wrote" << serialPort.write(data) << "bytes";
}
emit DataSent(data);
}
......
......@@ -67,6 +67,7 @@ class Port : public QObject
void read();
private:
QString name;
quint8 type;
void notifyPropertyChanged( const char *propertyName );
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment