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


C++ CommPortPtr类代码示例

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


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

示例1: tr

bool
MacroPacket::read(CommPortPtr dev, int len, QString &err)
{
    if (command == 0) {
        if (MACRO_DEBUG) printf("reading command from device\n");
        int n = dev->read(&command, 1, err);
        if (n <= 0) {
            err = (n < 0) ? (tr("read command error: ") + err) : tr("read timeout");
            return false;
        }
        checksum += command;
        len--;
        if (MACRO_DEBUG) printf("command %s\n" ,cEscape(&command,n).toLatin1().constData());
    }

    if (MACRO_DEBUG) printf("reading %d from device\n", len);
    char buf[len];
    int n = dev->read(&buf, len, err);

    if (n <= 0) {
        err = (n < 0) ? (tr("read error: ") + err) : tr("read timeout");
        return false;
    } else if (n < len) {
        err += QString(tr(", read only %1 bytes instead of: %2"))
            .arg(n).arg(len);
        return false;
    }

    if (MACRO_DEBUG) printf("payload %s\n" ,cEscape(buf,n).toLatin1().constData());
    addToPayload(buf,n);

    return true;
}
开发者ID:cernst72,项目名称:GoldenCheetah,代码行数:33,代码来源:MacroDevice.cpp

示例2: QString

bool
PowerTapDevice::doWrite(CommPortPtr dev, char c, bool hwecho, QString &err)
{
    if (PT_DEBUG) printf("writing '%c' to device\n", c);
    int n = dev->write(&c, 1, err);
    if (n != 1) {
        if (n < 0)
            err = QString(tr("failed to write %1 to device: %2")).arg(c).arg(err);
        else
            err = QString(tr("timeout writing %1 to device")).arg(c);
        return false;
    }
    if (hwecho) {
        char c;
        int n = dev->read(&c, 1, err);
        if (n != 1) {
            if (n < 0)
                err = QString(tr("failed to read back hardware echo: %2")).arg(err);
            else
                err = tr("timeout reading back hardware echo");
            return false;
        }
    }
    return true;
}
开发者ID:27sparks,项目名称:GoldenCheetah,代码行数:25,代码来源:PowerTapDevice.cpp

示例3: dev2path

static bool
dev2path(CommPortPtr dev, QString &path, QString &err)
{
    // Read device path out of device name.  Sketchy.
    QRegExp rx("^Serial: (.+)$");
    if (!rx.exactMatch(dev->name())) {
        err = "SRM download not supported by device " + dev->name();
        return false;
    }
    path = rx.cap(1);
    return true;
}
开发者ID:mdherynk,项目名称:GoldenCheetah,代码行数:12,代码来源:SrmDevice.cpp

示例4: switch

bool
SrmDevices::exclusivePort( CommPortPtr dev )
{
    switch( protoVersion ){
      case 5:
        if( dev->type() == "Serial" && dev->name().contains( "PL2303" ) )
            return true;
        break;

      case 6:
      case 7:
        if( dev->type() == "D2XX" && dev->name().startsWith( "POWERCONTROL" ) )
            return true;
        break;
    }

    return false;
}
开发者ID:ClaFio,项目名称:GoldenCheetah,代码行数:18,代码来源:SrmDevice.cpp

示例5: QString

QVector<CommPortPtr>
D2XX::myListCommPorts(QString &err)
{
    QVector<CommPortPtr> result;
    if (!lib) {
        lib = new D2XXWrapper;
        if (!lib->init(err)) {
            delete lib;
            lib = NULL;
            return result;
        }
    }
    DWORD numDevs;
    FT_STATUS ftStatus = lib->create_device_info_list(&numDevs);
    if(ftStatus != FT_OK) {
        err = QString("FT_CreateDeviceInfoList: %1").arg(ftStatus);
        return result;
    }
    FT_DEVICE_LIST_INFO_NODE *devInfo = new FT_DEVICE_LIST_INFO_NODE[numDevs];
    ftStatus = lib->get_device_info_list(devInfo, &numDevs);
    if (ftStatus != FT_OK)
        err = QString("FT_GetDeviceInfoList: %1").arg(ftStatus);
    else {
        for (DWORD i = 0; i < numDevs; i++)
            result.append(CommPortPtr(new D2XX(devInfo[i])));
    }
    delete [] devInfo;
    // If we can't open a D2XX device, it's usually because the VCP drivers
    // are installed, so it should also show up in the list of serial devices.
    for (int i = 0; i < result.size(); ++i) {
        CommPortPtr dev = result[i];
        QString tmp;
        if (dev->open(tmp))
            dev->close();
        else
            result.remove(i--);
    }
    return result;
}
开发者ID:FuzzyBunnys,项目名称:GoldenCheetah,代码行数:39,代码来源:D2XX.cpp

示例6: readOneByOne

static int
readOneByOne(CommPortPtr dev, void *buf, size_t nbyte, QString &err)
{
    char * data = ((char *)buf);
    int rtn=0;

    for (size_t i = 0; i < nbyte; i++)
    {
        int n = dev->read(data + i, 1, err);
        if (n <= 0) {
            return rtn;
        }
        if (data[i] == START_1){
            int n = dev->read(data + i, 1, err);
            if (n <= 0) {
                return rtn;
            }
        }
        rtn++;
    }
    return rtn;
}
开发者ID:JanDeVisser,项目名称:GoldenCheetah,代码行数:22,代码来源:JouleDevice.cpp

示例7: defined

bool
SrmDevices::supportsPort( CommPortPtr dev )
{
#if defined(SRMIO_HAVE_TERMIOS) || defined(SRMIO_HAVE_WINCOM)
    // we could check device name starts with "com" or "/dev"
    // but we wouldn't have got here unless it was a supported
    // serial port anyway.
    if( dev->type() == "Serial" )
        return true;
#endif

#ifdef SRMIO_HAVE_D2XX
    if( dev->type() == "D2XX" ){
        switch( protoVersion ){
          case 6:
          case 7:
            return true;
        }
    }
#endif

    return false;
}
开发者ID:ClaFio,项目名称:GoldenCheetah,代码行数:23,代码来源:SrmDevice.cpp

示例8: while

int
PowerTapDevice::readUntilNewline(CommPortPtr dev, char *buf, int len, QString &err)
{
    int sofar = 0;
    while (!hasNewline(buf, sofar)) {
        assert(sofar < len);
        // Read one byte at a time to avoid waiting for timeout.
        int n = dev->read(buf + sofar, 1, err);
        if (n <= 0) {
            err = (n < 0) ? (tr("read error: ") + err) : tr("read timeout");
            err += QString(tr(", read %1 bytes so far: \"%2\""))
                .arg(sofar).arg(cEscape(buf, sofar));
            return -1;
        }
        sofar += n;
    }
    return sofar;
}
开发者ID:27sparks,项目名称:GoldenCheetah,代码行数:18,代码来源:PowerTapDevice.cpp

示例9: cEscape

bool
MacroPacket::write(CommPortPtr dev, QString &err)
{
    const char *msg = cEscape(data(), payload.count()+2).toLatin1().constData();

    if (MACRO_DEBUG) printf("writing '%s' to device\n", msg);

    int n = dev->write(data(), payload.count()+2, err);
    if (n != payload.count()+2) {
        if (n < 0) {
            if (MACRO_DEBUG) printf("failed to write %s to device: %s\n", msg, err.toLatin1().constData());
            err = QString(tr("failed to write to device: %1")).arg(err);
        }
        else {
            if (MACRO_DEBUG) printf("timeout writing %s to device\n", msg);
            err = QString(tr("timeout writing to device"));
        }
        return false;
    }

    if (MACRO_DEBUG) printf("writing to device ok\n");
    return true;
}
开发者ID:cernst72,项目名称:GoldenCheetah,代码行数:23,代码来源:MacroDevice.cpp


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