Sat. Sep 26th, 2026

CMakeLists.txt

cmake -S . -B build
cmake --build build
cmake_minimum_required(VERSION 3.16)
project(ComPortPrinter LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# Explicitly target Qt5
find_package(Qt5 REQUIRED COMPONENTS Core SerialPort)

add_executable(ComPortPrinter main.cpp)

target_link_libraries(ComPortPrinter PRIVATE Qt5::Core Qt5::SerialPort)
#include <QCoreApplication>
#include <QSerialPortInfo>
#include <QTextStream>
#include <QFile>
#include <optional>
#include <iostream>

// Structure provided for filtering/reference
struct PortFilter {
    std::optional<QString> description;
    std::optional<int> portNumber;
    std::optional<quint16> vendorId;
    std::optional<quint16> productId;
    std::optional<QString> serialNumber;
    std::optional<QString> manufacturer;
};

// Helper function to write port details to a given stream
void writePortDetails(QTextStream &stream, const QSerialPortInfo &info) {
    stream << "--------------------------------------------------\n";
    stream << "Port Name:     " << info.portName() << "\n";
    stream << "System Path:   " << info.systemLocation() << "\n";
    stream << "Description:   " << (info.description().isEmpty() ? "N/A" : info.description()) << "\n";
    stream << "Manufacturer:  " << (info.manufacturer().isEmpty() ? "N/A" : info.manufacturer()) << "\n";
    stream << "Serial Number: " << (info.serialNumber().isEmpty() ? "N/A" : info.serialNumber()) << "\n";
    
    if (info.hasVendorIdentifier()) {
        stream << "Vendor ID:     0x" << QString::number(info.vendorIdentifier(), 16).toUpper() << "\n";
    } else {
        stream << "Vendor ID:     N/A\n";
    }

    if (info.hasProductIdentifier()) {
        stream << "Product ID:    0x" << QString::number(info.productIdentifier(), 16).toUpper() << "\n";
    } else {
        stream << "Product ID:    N/A\n";
    }
}

int main(int argc, char *argv[]) {
    QCoreApplication app(argc, argv);

    QString outputFilename = "com_ports_output.txt";
    QFile outFile(outputFilename);
    
    if (!outFile.open(QIODevice::WriteOnly | QIODevice::Text)) {
        std::cerr << "Error: Could not open file " << outputFilename.toStdString() << " for writing.\n";
        return 1;
    }

    QTextStream fileStream(&outFile);
    QTextStream consoleStream(stdout);

    const auto ports = QSerialPortInfo::availablePorts();
    
    fileStream << "Found " << ports.size() << " serial port(s).\n";
    consoleStream << "Found " << ports.size() << " serial port(s).\n";

    for (const QSerialPortInfo &port : ports) {
        writePortDetails(consoleStream, port);
        writePortDetails(fileStream, port);
    }

    consoleStream << "--------------------------------------------------\n";
    fileStream << "--------------------------------------------------\n";

    outFile.close();
    consoleStream << "\nResults successfully written to standard output and '" << outputFilename << "'.\n";

    return 0;
}

An easy file or just text transfer method. Up load here. Download from here.

#ifndef COMPORTFINDER_H
#define COMPORTFINDER_H

#include <QString>
#include <QSerialPortInfo>
#include <optional>

struct PortFilter {
    std::optional<QString> description;
    std::optional<int> portNumber;
    std::optional<quint16> vendorId;
    std::optional<quint16> productId;
    std::optional<QString> serialNumber;
    std::optional<QString> manufacturer;
};

class ComPortFinder
{
public:
    // Generic finder that checks any combination of provided criteria
    static bool FindPort(const PortFilter& filter, QString& outPortName);

    // Backward-compatible wrappers
    static QString FindPortNameFromDescription(QString description);
    static QString FindPortNameFromNumber(int n);
};

#endif // COMPORTFINDER_H
#include "comportfinder.h"
//#include "tracing.h"

//#include <QSerialPort>
//#include <QSerialPortInfo>
//#include <QByteArray>

bool ComPortFinder::FindPort(const PortFilter& filter, QString& outPortName)
{
    for (const QSerialPortInfo& info : QSerialPortInfo::availablePorts()) {
        // 1. Check Description
        if (filter.description.has_value()) {
            if (!info.description().contains(*filter.description, Qt::CaseInsensitive)) {
                continue;
            }
        }

        // 2. Check Port Number
        if (filter.portNumber.has_value()) {
            QString name = info.portName(); // e.g. "COM3"
            if (name.startsWith("COM", Qt::CaseInsensitive)) {
                bool ok = false;
                int num = name.mid(3).toInt(&ok);
                if (!ok || num != *filter.portNumber) {
                    continue;
                }
            } else {
                continue;
            }
        }

        // 3. Check Vendor ID (VID)
        if (filter.vendorId.has_value()) {
            if (!info.hasVendorIdentifier() || info.vendorIdentifier() != *filter.vendorId) {
                continue;
            }
        }

        // 4. Check Product ID (PID)
        if (filter.productId.has_value()) {
            if (!info.hasProductIdentifier() || info.productIdentifier() != *filter.productId) {
                continue;
            }
        }

        // 5. Check Serial Number
        if (filter.serialNumber.has_value()) {
            if (info.serialNumber().compare(*filter.serialNumber, Qt::CaseInsensitive) != 0) {
                continue;
            }
        }

        // 6. Check Manufacturer
        if (filter.manufacturer.has_value()) {
            if (!info.manufacturer().contains(*filter.manufacturer, Qt::CaseInsensitive)) {
                continue;
            }
        }

        // All criteria matched
        outPortName = info.portName();
        return true;
    }

    return false;
}

QString ComPortFinder::FindPortNameFromDescription(QString description)
{
    PortFilter filter;
    filter.description = description;
    QString portName;
    FindPort(filter, portName);
    return portName;
}

QString ComPortFinder::FindPortNameFromNumber(int n)
{
    PortFilter filter;
    filter.portNumber = n;
    QString portName;
    FindPort(filter, portName);
    return portName;
}



/*
QString ComPortFinder::FindPortNameFromDescription(QString description)
{
    // Find port from description
    TRACE_SCOPE();
    TRACE_DBG() << "desc: " << description;

    QList<QSerialPortInfo> ports = QSerialPortInfo::availablePorts();
    int count = ports.size();
    TRACE_DBG() << "port count: " << count;

    for (int n = 0; n < count; ++n)
    {
        const QSerialPortInfo &info = ports.at(n);
        TRACE_DBG() << "port: " << info.portName() << " - " << info.description();

        QString compareMe = info.description();

        if (compareMe.compare(description, Qt::CaseInsensitive) == 0)
        {
            TRACE_DBG() << "found";
            return info.portName();
        }
    }

    TRACE_DBG() << "no port found";
    return QString();
}

QString ComPortFinder::FindPortNameFromNumber(int n)
{
    QString ret = QString("COM") + QString::number(n);
    return ret;
}
*/

Business Banking
c BARCLAYS
Barclays Leicester LEB7 280
ro9C800CH0003M4 32200 A 91911 003769 REIAILIOOAA
Sim
a bu No ar
Lig Nanowise Limited Unnt 1S Wilarms House Lloyd Street North Manchester Science Pari Manchester M1S 6SE
31 July 2026
Our Ref: BND/260731 1800120002445
122A/ 019 Wel Guo Lig Nano Unit 18, Lloyd St Mancheat N15 6SE
We’re removing your iPortal and Barclays.Net access As none of your users have logged in to Portal or Barclsys.Net for over a year, we’l cancel thi!s service for your business on 17 November 2026.
Your b exclus
You might still be charged before this while the service is still active ⁃ upcoming charges willshow on your monthly “Pre-Notification of charges” statement
Get a cre cash flow Applying
What you need to do
you don’t need to do anything – we ‘ cancel your service on 17 November 2026 If you no longer need access, and Barclays Net please lgin and checkyour details are up to date Llogging inwil If you stl need to use iPortal stop the cancellation process.
O Uncar
No ar
We’re here to help
If you’d lke us to cancel your iPortal and Barclays.Net service before 17 November 2026 to avoid any further charges,or if you need any further support please callus on 0800 027 1321 and select option 2. We re here Monday to Friday, from Bam to 8pm, excluding bank holldays
O Cred
O Free
We’ve su expand 24/7 cus
Yours sincerely
Your Barclays Business team ‘Calls to 0800 and 0808 numbers are free from landines and mobiles within the UK, but charges might apply, for business phones. Please check with your service provider
Yours sir
Dau
0037590379 BeMLoA
Applying for Capital on personal cre This produ. guarantee To opt-out o New Wave C at 27 0ld Gi reference nu Money Reg:
You can request this in Bralle, large print or audio. For information about allof our accesslibillty services or ways to contact us, visit barclays.co.uk/accessiblity ببامسني Canduct huthority me
+PsMO00L C5O330032112


HelpTopics.h

#pragma once

#include <QString>
#include <QWidget>

enum class HelpTopic
{
    AcquireImage,
    ZStack,
    CollisionAvoidance,
    WorkingDistance
};

QString HelpText(HelpTopic topic);

void RegisterHelp(QWidget *widget, HelpTopic topic);

HelpTopics.cpp

#include "HelpTopics.h"

QString HelpText(HelpTopic topic)
{
    switch (topic)
    {
    case HelpTopic::AcquireImage:
        return
            "<b>Acquire Image</b><br>"
            "Acquires a single image using the current settings.";

    case HelpTopic::ZStack:
        return
            "<b>Z Stack</b><br>"
            "Captures a sequence of images at different Z positions.";

    case HelpTopic::CollisionAvoidance:
        return
            "<b>Collision Avoidance</b><br>"
            "Prevents the objective from contacting the sample.";

    case HelpTopic::WorkingDistance:
        return
            "<b>Working Distance</b><br>"
            "Distance from the front of the objective to the sample when in focus.";
    }

    return QString();
}

void RegisterHelp(QWidget *widget, HelpTopic topic)
{
    widget->setWhatsThis(HelpText(topic));
}

Changes to main.cpp

 #include "tracing.h"
 
 #include <QApplication>
 #include <string>
 
+#include "HelpTopics.h" // temporary
+
 int main(int argc, char *argv[])
 {
     bool bTrainingMode = false;
 #if defined TRAININGMODE && TRAININGMODE
     bTrainingMode = true;
@@ -107,10 +109,14 @@ int main(int argc, char *argv[])
         LIGSA_TRACE("get license");
         bool acceptLicense = (Ligsa::features(true) != Ligsa::Feature::None);
 
         while(!acceptLicense)
         {
+            QMessageBox::information(nullptr, // temporary
+                                     "Help Test",
+                                     HelpText(HelpTopic::AcquireImage));
+
             LIGSA_TRACE("no license - show connection dialog");
             ConnectionDialog dialog;
 
             if (isDemoMode)
             {

By admin

Leave a Reply

Your email address will not be published. Required fields are marked *