本文整理汇总了C++中QSerialPort::isOpen方法的典型用法代码示例。如果您正苦于以下问题:C++ QSerialPort::isOpen方法的具体用法?C++ QSerialPort::isOpen怎么用?C++ QSerialPort::isOpen使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QSerialPort
的用法示例。
在下文中一共展示了QSerialPort::isOpen方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: rgbChange
void SerialCommunication::rgbChange(int r, int g, int b)
{
data = "";
data.append("0" + QString::number(r) + "," + QString::number(g) + "," + QString::number(b) + "\n");
qDebug("Sending: " + data);
if (serial.isOpen())
serial.write(data);
}
示例2: SerialDisconnect
bool SerialCommunication::SerialDisconnect()
{ // serial disconnect
if (serial.isOpen())
{
serial.close();
return true;
}
return false;
}
示例3: SerialConnect
bool SerialCommunication::SerialConnect(QString PortName)
{ // serial connect
if (!serial.isOpen())
{
serial.setPortName(PortName);
serial.setBaudRate(QSerialPort::Baud9600);
serial.setDataBits(QSerialPort::Data8);
serial.setParity(QSerialPort::NoParity);
serial.setStopBits(QSerialPort::OneStop);
serial.setFlowControl(QSerialPort::NoFlowControl);
serial.open(QIODevice::ReadWrite);
serial.waitForBytesWritten(9000);
if (serial.isWritable()) {
return true;
}
}
return false;
}
示例4: run
void MainWindow::run()
{
QSerialPort availableport;
while(true){
availableport.setPortName("COM6");
availableport.open(QIODevice::ReadOnly);
availableport.setBaudRate(QSerialPort::Baud9600);
availableport.setDataBits(QSerialPort::Data8);
availableport.setParity(QSerialPort::NoParity);
availableport.setStopBits(QSerialPort::OneStop);
availableport.setFlowControl(QSerialPort::NoFlowControl);
if(availableport.isOpen()){
//DEBUG MODE ON
bioGuised->show();
delay(5000);
}
else{
bioGuised->hide();
}
}
}
示例5: QObject
GPSModule::GPSModule(QObject *parent) : QObject(parent)
{
QSerialPort* serial = new QSerialPort(this);
serial->setPortName(QString("/dev/ttyUSB0"));
serial->setBaudRate(QSerialPort::Baud9600);
serial->setDataBits(QSerialPort::Data8);
serial->setParity(QSerialPort::NoParity);
serial->setStopBits(QSerialPort::OneStop);
serial->open(QIODevice::ReadOnly);
if(serial->isOpen())
{
QNmeaPositionInfoSource *source = new QNmeaPositionInfoSource(QNmeaPositionInfoSource::RealTimeMode);
source->setDevice(serial);
if(source){
connect(source, SIGNAL(positionUpdated(QGeoPositionInfo)), this, SLOT(positionUpdate(QGeoPositionInfo)));
source->setPreferredPositioningMethods(QGeoPositionInfoSource::AllPositioningMethods);
source->setUpdateInterval(2000);
source->startUpdates();
}
}
}
示例6: QMainWindow
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
qRegisterMetaType<eegDataType::iterator>("eegDataType::iterator");
/// server
ui->serverPortSpinBox->setMaximum(65535);
int hostCounter = 0;
ui->serverAddressComboBox->addItem("local, 120");
ui->serverAddressComboBox->setItemData(hostCounter++,
QVariant("127.0.0.1:120"));
ui->serverAddressComboBox->addItem("local, home");
ui->serverAddressComboBox->setItemData(hostCounter++,
QVariant("127.0.0.1:35577"));
ui->serverAddressComboBox->addItem("Enceph");
ui->serverAddressComboBox->setItemData(hostCounter++,
QVariant("213.145.47.104:120"));
ui->serverAddressComboBox->addItem("pew");
ui->serverAddressComboBox->setItemData(hostCounter++,
QVariant("192.168.0.104:120"));
connect(ui->serverAddressComboBox, SIGNAL(highlighted(int)),
this, SLOT(serverAddressSlot(int)));
connect(ui->serverAddressComboBox, SIGNAL(currentIndexChanged(int)),
this, SLOT(serverAddressSlot(int)));
#if MY_LINROWS
ui->serverAddressComboBox->setCurrentText("pew");
#else
ui->serverAddressComboBox->setCurrentText("Enceph");
#endif
// ui->serverAddressComboBox->setCurrentText("pew"); /// fix via router, always 192.168.0.104
/// com
for(int i = 0; i < 9; ++i)
{
ui->comPortComboBox->addItem("COM"+QString::number(i+1));
}
ui->comPortComboBox->setCurrentText("COM5");
#if COM_IN_MAIN
connect(ui->connectComPortPushButton, SIGNAL(clicked()),
this, SLOT(comPortSlot()));
comPort = new QSerialPort(this);
connect(comPort, SIGNAL(error(QSerialPort::SerialPortError)),
this, SLOT(serialPortErrorSlot(QSerialPort::SerialPortError)));
connect(this->ui->comPortSendOnePushButton, SIGNAL(clicked()),
this, SLOT(sendOne()));
connect(this->ui->comPortSendTwoPushButton, SIGNAL(clicked()),
this, SLOT(sendTwo()));
#endif
#if 0
/// COM test
QSerialPort * comPort;
comPort = new QSerialPort(this);
comPort->setPortName(ui->comPortComboBox->currentText());
comPort->open(QIODevice::WriteOnly);
if(comPort->isOpen())
{
// cout << comPort->errorString() << endl;
cout << "serialPort opened: " + def::comPortName << endl;
cout << "portName: " << comPort->portName().toStdString() << endl;
cout << "dataBits: " << comPort->dataBits() << endl;
cout << "baudRate: " << comPort->baudRate() << endl;
cout << "dataTerminalReady: " << comPort->isDataTerminalReady() << endl;
cout << "flowControl: " << comPort->flowControl() << endl;
cout << "requestToSend: " << comPort->isRequestToSend() << endl;
cout << "stopBits: " << comPort->stopBits() << endl << endl;
}
comPortDataStream.setDevice(comPort);
#endif
/// socket
#if SOCKET_IN_MAIN
socket = new QTcpSocket(this);
#endif
#if !DATA_READER
socketDataStream.setDevice(socket);
socketDataStream.setByteOrder(QDataStream::LittleEndian); // least significant bytes first
#endif
#if SOCKET_IN_MAIN
//.........这里部分代码省略.........
示例7: run
void SerialPortThread::run()
{
bool __isStopped = true;
m_serialPortMutex.lock();
__isStopped = m_isStopped;
m_serialPortMutex.unlock();
qDebug("thread running");
SerialPortSettings::Settings __mSettings;
bool __isSettingsChanged = false;
QByteArray __dataReceived;
QByteArray __dataToSend;
// unsigned char rx_buffer[256];
QSerialPort serial;
while(!__isStopped)
{
m_serialPortMutex.lock();
if(m_isSettingsChanged){
m_isSettingsChanged =false;
__isSettingsChanged = true;
}
m_serialPortMutex.unlock();
if(__isSettingsChanged){
__isSettingsChanged =false;
if(serial.isOpen()){
serial.close();
}
m_serialPortMutex.lock();
__mSettings = m_currentSettings;
m_serialPortMutex.unlock();
serial.setPortName(__mSettings.name);
serial.setBaudRate(__mSettings.baudRate);
serial.setDataBits(__mSettings.dataBits);
serial.setParity(__mSettings.parity);
serial.setStopBits(__mSettings.stopBits);
serial.setFlowControl(__mSettings.flowControl);
emit message(QString("settings changed !"));
}//settings changed
if(!serial.isOpen()){
if(serial.open(QIODevice::ReadWrite)){
emit message(QString("open successfully !"));
}
else{
m_serialPortMutex.lock();
m_isStopped = true;
m_serialPortMutex.unlock();
emit message(QString("open failed !"));
break;
}
}//if not open , while loop break
/*=== opened , processing data here ===*/
m_serialPortMutex.lock();
if(!m_dataToSend.isEmpty()){
__dataToSend.append(m_dataToSend);
m_dataToSend.clear();
}
m_serialPortMutex.unlock();
if(! __dataToSend.isEmpty()){
if(serial.write(__dataToSend) > 0){
if (serial.waitForBytesWritten(100) == true) {
qDebug() <<"write successfully !";
__dataToSend.clear();
}
else
qDebug() <<"write time out !";
}
}
if (serial.waitForReadyRead(100)) {
__dataReceived = serial.readAll();
while (serial.waitForReadyRead(10))
__dataReceived += serial.readAll();
}
//unpack the data received
if(__dataReceived.size() > 0){
emit message(__dataReceived);
// for(int i = 0; i < __dataReceived.size(); i ++){
// if(FrameUnpack(__dataReceived.at(i),rx_buffer)){
// tHeader* pHeader = (tHeader*)rx_buffer;
// if( pHeader->cmd == CMD_ID_SENSOR_INFO){
// // Cmd_Data *pData = (Cmd_Data *)&rx_buffer[sizeof(tHeader)];//
// }
// else{
// }
// }
// }
}//unpack code end
//.........这里部分代码省略.........