コード例 #1
0
ファイル: posixSerial.cpp プロジェクト: JuhaniJ/rotfl
int PosixSerial::readSerial(char *buf, size_t &size)
{
    if(!initialized_) {
        if( initializePort() == CROI_ERROR ) {
            return CROI_ERROR;
        }
    }
    //non blocking read
    fcntl(fd_, F_SETFL, FNDELAY);
    //int origflags = fcntl(fd_, F_GETFL, 0);
    //fcntl(fd_, F_SETFL, origflags & ~O_NONBLOCK);

    size = read(fd_, buf, MAX_READ);

    fcntl(fd_, F_SETFL, 0);
//    fcntl(fd_, F_SETFL, origflags | O_NONBLOCK);

    if(size == -1){
        return CROI_ERROR;
    }

    return CROI_SUCCESS;




}
コード例 #2
0
ファイル: posixSerial.cpp プロジェクト: JuhaniJ/rotfl
int PosixSerial::readSerial(std::string & buf) {

    if(!initialized_) {
        if( initializePort() == CROI_ERROR ) {
            return CROI_ERROR;
        }
    }
    //non blocking read
    fcntl(fd_, F_SETFL, FNDELAY);
    //int origflags = fcntl(fd_, F_GETFL, 0);
    //fcntl(fd_, F_SETFL, origflags & ~O_NONBLOCK);

    int size = read(fd_, readBuf_, MAX_READ);

    fcntl(fd_, F_SETFL, 0);
//    fcntl(fd_, F_SETFL, origflags | O_NONBLOCK);

    if(size == -1){
        return CROI_ERROR;
    }

    //debug
    for(int i = 0; i < size; ++i) {
        printf("tuosta: %i\n",readBuf_[i]);
    }
    std::cout << std::endl;

    std::cout << size << std::endl;
    buf = std::string(readBuf_, readBuf_ + size);

    return CROI_SUCCESS;
}
コード例 #3
0
ファイル: SerialInterface.cpp プロジェクト: Issacchaos/hifi
void SerialInterface::pair() {
    
#ifndef _WIN32
    // look for a matching gyro setup
    DIR *devDir;
    struct dirent *entry;
    int matchStatus;
    regex_t regex;
    
    // for now this only works on OS X, where the usb serial shows up as /dev/tty.usb*,
    // and (possibly just Ubuntu) Linux, where it shows up as /dev/ttyACM*
    if((devDir = opendir("/dev"))) {
        while((entry = readdir(devDir))) {
#ifdef __APPLE__
            regcomp(&regex, "tty\\.usb", REG_EXTENDED|REG_NOSUB);
#else
            regcomp(&regex, "ttyACM", REG_EXTENDED|REG_NOSUB);
#endif
            matchStatus = regexec(&regex, entry->d_name, (size_t) 0, NULL, 0);
            if (matchStatus == 0) {
                char *serialPortname = new char[100];
                sprintf(serialPortname, "/dev/%s", entry->d_name);
                
                initializePort(serialPortname);
                
                delete [] serialPortname;
            }
            regfree(&regex);
        }
        closedir(devDir);
    }    
#endif
}
コード例 #4
0
ファイル: posixSerial.cpp プロジェクト: JuhaniJ/rotfl
int PosixSerial::writeSerial(const std::string buf) {

    if (!initialized_) {
        if( initializePort() == CROI_ERROR ) {
            return CROI_ERROR;
        }
    }

    int n = write(fd_, buf.c_str(), buf.size());

    std::cout << "sent bytes: " << n << std::endl;
    if(n != static_cast<int>(buf.size())) {
        return CROI_ERROR;
    }
    return CROI_SUCCESS;
}
コード例 #5
0
ファイル: posixSerial.cpp プロジェクト: JuhaniJ/rotfl
int PosixSerial::writeSerial(char *buf, size_t size)
{
    if (!initialized_) {
        if( initializePort() == CROI_ERROR ) {
            return CROI_ERROR;
        }
    }

    int n = write(fd_, buf, size);

    if(n != size) {
        return CROI_ERROR;
    }
    std::cout << buf << std::endl;
    return CROI_SUCCESS;
}
コード例 #6
0
ファイル: udp_waker.cpp プロジェクト: AlainRoy/htcondor
bool
UdpWakeOnLanWaker::initialize ()
{

    if ( !initializePacket () ) {

        dprintf (
            D_ALWAYS,
            "UdpWakeOnLanWaker::initialize: "
            "Failed to initialize magic WOL packet\n" );

        return false;

    }

    if ( !initializePort () ) {

        dprintf (
            D_ALWAYS,
            "UdpWakeOnLanWaker::initialize: "
            "Failed to initialize port number\n" );

        return false;

    }

    if ( !initializeBroadcastAddress () ) {

        dprintf (
            D_ALWAYS,
            "UdpWakeOnLanWaker::initialize: "
            "Failed to initialize broadcast address\n" );

        return false;

    }

    /* if we get here then we are fine */
    return true;

}