本文整理汇总了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;
}
示例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";
}
示例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;
}
示例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();
}
示例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()));
}
}
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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();
}
示例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();
}
示例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;
}
示例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;
}
示例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);
}
示例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();
}