当前位置: 首页>>代码示例>>C++>>正文


C++ SerialPort类代码示例

本文整理汇总了C++中SerialPort的典型用法代码示例。如果您正苦于以下问题:C++ SerialPort类的具体用法?C++ SerialPort怎么用?C++ SerialPort使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了SerialPort类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: ExecCommand

bool MachineCommand::ExecCommand(SerialPort &sp, const char *cmd, const char *ret)
{
	char ans[5];

	do
	{
		// TODO: Check for errors in write/ReadLine in sp.
		sp.WriteLine(cmd);
		sp.ReadLine(ans, sizeof(ans));

		if (strcmp(ans, M_ANS_ERROR) == 0)
		{
			sp.WriteLine(M_DO_CR);
			sp.ReadLine(ans, sizeof(ans));
			if (strcmp(ans, M_ANS_CC) != 0)
			{
				// TODO: Set errormsg somewhere (??)
				throw MachineEvent(EVENT_MACHINE_ERROR, "Expected 'CC', recieved " + string(ans));
				return false;
			}
			else
			{
				continue;
			}
		}
	} while (strcmp(ans, ret) != 0);
	
	return true;
}
开发者ID:anderslindmark,项目名称:PickNPlace,代码行数:29,代码来源:MachineCommand.cpp

示例2: while

void CheckCurrPort::run()
{
//    qDebug()<<QTime::currentTime().toString()<<"startt";
    while(true){
        msleep(1500);
        bool found=0;
        foreach (const SerialPortInfo &info, SerialPortInfo::availablePorts()){  //SerialPortInfo &info, SerialPortInfo::availablePorts())

            if(info.portName()==currPort){
                found=1;
                SerialPort testConn;//(currPort);
                testConn.setPort(currPort);
                if(testConn.open(QIODevice::ReadWrite)){
                   //???? testConn.close();
                    emit portDisconnected();
                    //closeSerialPort(1);
//                    qDebug()<<QTime::currentTime().toString()<<"opened!";
                    //return;
                } /*else {
                    qDebug()<<QTime::currentTime().toString()<<"can not open";
                }*/
                break;
            }
       }
        if(!found){
//            closeSerialPort(1);            
//             qDebug()<<QTime::currentTime().toString()<<" not found!";
             emit portDisconnected();
             //return;
        }
    }
//    qDebug()<<QTime::currentTime().toString()<<"exitttt";
}
开发者ID:HelloZB,项目名称:Qt_Terminal,代码行数:33,代码来源:checkcurrport.cpp

示例3: thread_start

static void * thread_start(void *arg)
{
    SerialPort *port =  (SerialPort *)arg;
    int hCOM = port->getCom();

    const int buffSize = 1024;
    char buff[buffSize];
    while (port->mTreadFlag) {
        int rb = read(hCOM, buff, buffSize);
        if(rb>0) {
            port->mReadError = false;
            buff[rb]='\0';
            SerialPortRecieved(port, buff);
            port->lastCharRecieved = buff[rb-1];
        } else if(rb==0) {
            if(port->mReadError==false)
                SerialPortError(port, ERROR_READ_STRING);
            port->mReadError = true;
            usleep(50000);
        } else {
            port->mReadError = false;
            usleep(50000);
        }
    }
    port->mTreadFlag = true;
    return 0;
}
开发者ID:Nikolay-Kha,项目名称:CNCMachine,代码行数:27,代码来源:serialport_linux.cpp

示例4: main

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

    QApplication app(argc, argv);    

    mainWindow *mw = new mainWindow;
    SerialPort *sp = new SerialPort;
    QString *msg = new QString(QMainWindow::tr("<p>Начало проверки модуля МС-54.011</p>"));


    mw->setWindowTitle(QMainWindow::tr("КИНД.468354.011"));
    mw->resize(1000, 500);
    mw->show();

    msg->append(QMainWindow::tr("<p>setNextLine()</p>"));
    mw->setNextLine(msg);

    QList<QSerialPortInfo> listCom =  sp->getList();
    QListIterator<QSerialPortInfo> i(listCom);
    while(i.hasNext()){
        msg->append(i.next().portName());
        mw->setNextLine(msg);
    }

    return app.exec();
 }
开发者ID:krang4d,项目名称:buss32054,代码行数:25,代码来源:main.cpp

示例5: setSerialPort

void SerialMake::setSerialPort(SerialPort *instance)
{
    if(m_serialPort != instance)
    {
        if(m_serialPort)
        {
            SerialPort *serialPort = m_serialPort; m_serialPort = NULL;

            serialPort->setSerialMake(NULL);

            disconnect(serialPort, SIGNAL(portDestroyedOrChanged()),
                       this, SLOT(handlePortDestroyedOrChanged()));
        }

        if(instance)
        {
            m_serialPort = instance;

            m_serialPort->setSerialMake(this);

            connect(m_serialPort, SIGNAL(portDestroyedOrChanged()),
                    this, SLOT(handlePortDestroyedOrChanged()));
        }
    }
}
开发者ID:omniacreator,项目名称:omniacreator-plugin,代码行数:25,代码来源:serialmake.cpp

示例6: send_package

void send_package(SerialPort& port, MessagePackage& package) try
{
	array<uint8_t, 256> a;
	auto succ = package.SerializeToArray(a.data(), a.size());
	assert(succ);

	auto s = package.ByteSize();

	cout << ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> size = " << s << endl;
	cout << package.DebugString() << endl;

	printf("0x%02x ", s);
	for (size_t i = 0; i<s; ++i)
	{
		printf("0x%02x ", a[i]);
	}
	cout << endl;


	cout << ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" << endl;



	port.writebyte(static_cast<uint8_t>(s));
	port.write(a.data(), s);

	// exit(0);
}
catch(std::exception& ex)
{
	std::cerr << ex.what() << std::endl;
}
开发者ID:PIlin,项目名称:opencv-experiments,代码行数:32,代码来源:main.cpp

示例7: while

DWORD SerialPort::ThreadProc (LPVOID lpdwThreadParam ) {
    SerialPort *port =  (SerialPort *)lpdwThreadParam;
    HANDLE hCOM = port->get_com();
    DWORD read;
    const int buffSize = 1024;
    char buff[buffSize];
    while (true) {
        read = 0;
        bool res = ReadFile(hCOM, buff, buffSize, &read,0);
        if(!port->mTreadFlag)
        	break;
        if(res) {
            if(read > 0) {
                port->mReadError = false;
                buff[read]='\0';
                SerialPortRecieved(port, buff, read);
                port->mBytesRecivedSinceLastSend += read;
            } else {
                if(GetCommModemStatus(hCOM, &read)==0) {
                    if(port->mReadError == false)
                        SerialPortError(port, ERROR_READ_STRING);
                    port->mReadError = true;
                } else {
                    port->mReadError = false;
                }
                port->sleep(100);
            }
        } else {
            port->mReadError = true;
            SerialPortError(port, ERROR_READ_STRING);
            port->sleep(100);
        }
    }
    return 0;
}
开发者ID:LeftRadio,项目名称:esp8266-firmware,代码行数:35,代码来源:serialport_win.cpp

示例8: SerialPort

MM::Device* SerialManager::CreatePort(const char* portName)
{
   // check if the port already exists
   std::vector<SerialPort*>::iterator i;
   for (i=ports_.begin(); i!=ports_.end(); i++)
   {
      char name[MM::MaxStrLength];
      (*i)->GetName(name);
      if (strcmp(name, portName) == 0)
      {
          (*i)->LogMessage(("adding reference to Port " + std::string(portName)).c_str() , true);
         (*i)->AddReference();
         return *i;
      }
   }

   // no such port found, so try to create a new one
   SerialPort* pPort = new SerialPort(portName);
   //pPort->LogMessage(("created new Port " + std::string(portName)).c_str() , true);
   ports_.push_back(pPort);
   pPort->AddReference();
   //pPort->LogMessage(("adding reference to Port " + std::string(portName)).c_str() , true);
   return pPort;

}
开发者ID:erisir,项目名称:Micro-Manager,代码行数:25,代码来源:SerialManager.cpp

示例9: while

void * SerialPort::thread_start(void *arg) {
    SerialPort *port =  (SerialPort *)arg;
    int hCOM = port->get_com();

    const int buffSize = 1024;
    char buff[buffSize];
    while (true) {
        int rb = read(hCOM, buff, buffSize);
        if(!port->mTreadFlag)
        	break;
        if(rb>0) {
            port->mReadError = false;
            buff[rb]='\0';
            SerialPortRecieved(port, buff, rb);
            port->mBytesRecivedSinceLastSend += rb;
        } else if(rb==0) {
            if(port->mReadError==false)
                SerialPortError(port, ERROR_READ_STRING);
            port->mReadError = true;
            port->sleep(100);
        } else {
            port->mReadError = false;
            port->sleep(100);
        }
    }
    return 0;
}
开发者ID:LeftRadio,项目名称:esp8266-firmware,代码行数:27,代码来源:serialport_posix.cpp

示例10: on_actionCreateSerialPort_triggered

void ChooseConnectionDlg::on_actionCreateSerialPort_triggered()
{
    SerialPort * port = sConMgr2.createSerialPort();
    port->setName(tr("New Serial Port"));
    port->setDeviceName("COM1");
    this->focusNewConn(port);
    ui->connectionNameEdit->setFocus();
}
开发者ID:onenonlycasper,项目名称:Lorris,代码行数:8,代码来源:chooseconnectiondlg.cpp

示例11: onResourceAcquisition

 void
 onResourceAcquisition(void)
 {
   setEntityState(IMC::EntityState::ESTA_BOOT, Status::CODE_INIT);
   m_uart = new SerialPort(m_args.uart_dev, m_args.uart_baud);
   m_uart->setCanonicalInput(true);
   m_uart->flush();
 }
开发者ID:tausteen,项目名称:dune,代码行数:8,代码来源:Task.cpp

示例12: prSerialPort_Close

static int prSerialPort_Close(struct VMGlobals *g, int numArgsPushed)
{
	PyrSlot* self = g->sp;
	SerialPort* port = (SerialPort*)getSerialPort(self);
	if (port == 0) return errFailed;
	port->stop();
	return errNone;
}
开发者ID:8c6794b6,项目名称:supercollider,代码行数:8,代码来源:PyrSerialPrim.cpp

示例13: prSerialPort_RXErrors

static int prSerialPort_RXErrors(struct VMGlobals *g, int numArgsPushed)
{
	PyrSlot* self = g->sp;
	SerialPort* port = (SerialPort*)getSerialPort(self);
	if (port == 0) return errFailed;
	SetInt(self, port->rxErrors());
	return errNone;
}
开发者ID:8c6794b6,项目名称:supercollider,代码行数:8,代码来源:PyrSerialPrim.cpp

示例14: SerialPort

void BluetoothSinkPlugin::newConnection(string, QDBusUnixFileDescriptor fd, QVariantMap)
{
	SerialPort *bluetoothDev = new SerialPort();
	bluetoothDev->setDescriptor(fd.fileDescriptor());
	auto client = amb::make_shared(new amb::AmbRemoteServer(bluetoothDev, routingEngine));
	client->disconnected = [this, client]() {
		removeOne(&clients, client);
	};

	clients.push_back(client);
}
开发者ID:fredcadete,项目名称:automotive-message-broker,代码行数:11,代码来源:bluetoothplugin.cpp

示例15: main

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    QTextCodec *c = QTextCodec::codecForName("UTF-8");
    QTextCodec::setCodecForCStrings(c);
    QTextCodec::setCodecForLocale(c);
    QTextCodec::setCodecForTr(c);
    SerialPort w;
    w.show();
    
    return a.exec();
}
开发者ID:LuckJC,项目名称:qt_project,代码行数:12,代码来源:main.cpp


注:本文中的SerialPort类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。