C++ (Qt)class SerialDeviceInfo;class SerialDevice{//...public://... SerialDevice(const QString &device, QObject *parent = 0); //see setDevice(QString); SerialDevice(const SerialDeviceInfo &info, QObject *parent = 0); void setDevice(const SerialDeviceInfo &info); void setDevice(const QString &device); //device may be: "\\\\\\\\.\\\\COM1", "COM1", "/dev/ttyS0", "ttyS0"... QString device() const; //returns something like "\\\\\\\\.\\\\COM1", "/dev/ttyS0"...//...};
C++ (Qt)port->name = "COM24", "ttyS45"port->fileName = "\\\\\\\\.\\\\COM24", "/dev/ttyS45"port->deviceName = "FTDI serial USB converter", "Prolific USB-to-Serial Comm Port (COM4)"
C++ (Qt)QList<SerialDeviceInfo> ports = SerialDeviceInfo::availableDevices();//SerialDevice *port = new SerialDevice(ports[0], this);//SerialDevice *port = new SerialDevice("COM1", this);SerialDevice *port = new SerialDevice("/dev/ttyS0", this);port->open();port->setBaudRate(SerialDevice::Baud15200);port->setParity(SerialDevice::NoParity);port->setStopBits(SerialDevice::OneStop);port->setDataErrorPolicy(SerialDevice::SkipPolicy);//...
C++ (Qt)...QString device() const; //returns something like "\\\\\\\\.\\\\COM1", "/dev/ttyS0"......
C++ (Qt)SerialDeviceInfo::deviceName() = "COM24", "ttyS45"SerialDeviceInfo::deviceLocation() = "\\\\\\\\.\\\\COM24", "/dev/ttyS45"SerialDeviceInfo::description()= "FTDI serial USB converter", "Prolific USB-to-Serial Comm Port"
C++ (Qt)QComboBox *combo = new QComboBox();SerialPort *port = new SerialPort(); QStringList names = SerialPort::availablePortNames();combo->addItems(names); connect(combo, SIGNAL(currentIndexChanged(const QString&)), this, SLOT(setPortName(const QString&))); This::setPortName(const QString& name){ port->setName(name);}
C++ (Qt)class SerialPort;class SerialPortInfoPrivate; class SerialPortInfo{public: SerialPortInfo(); //produces NULL info SerialPortInfo(const SerialPortInfo&other); //copy constructor explicit SerialPortInfo(const SerialPort &port); SerialPortInfo& operator=(const SerialPortInfo&other); void swap(SerialPortInfo&other); QString name() const; //COM1, ttyS0... QString systemLocation() const; //"\\\\\\\\.\\\\COM24", "/dev/ttyS45" QString description() const; //"Последовательный порт", "Prolific USB-to-Serial Comm Port", "Motorola Phone (E1 iTunes)" QString manufacturer() const; //"(Стандартные порты)", "Prolific Technology Inc." bool isNull() const; bool isBusy() const; QList<int> standardBauds() const; static QList<SerialPortInfo> availablePorts();private: Q_DECLARE_PRIVATE(SerialPortInfo) SerialPortInfoPrivate *d_ptr;};