Example #1
0
void Repetier::moveAxisToPos(char axis, double pos) throw (std::string)
{
    char send[this->bufsize], serialAns[this->bufsize], *test;
    if (axis >= 'a' && axis <= 'z') {
        axis -= 'a';
        axis += 'A';
    }
    if (axis != 'X' && axis != 'Y' && axis != 'Z') {
        std::string exc = "Repetier: Invalid axis.";
        throw exc;
    }
    sprintf(send, "G1 %c%.3lf", axis, pos);
    prepareStringToSend(send, this->bufsize);
    if (isCommaDecimalMark == true) {
        commaDecimalMarkToPoint(send, this->bufsize);
    }
    arduinoAccess.lock();
    arduino->writeStr(send);
    do {
        arduino->readUntil(serialAns, '\n', this->bufsize);
    } while (strstr(serialAns, "ok") == NULL);
    sprintf(send, "M114");
    prepareStringToSend(send, this->bufsize);
    arduino->writeStr(send);
    do {
        arduino->readUntil(serialAns, '\n', this->bufsize);
    } while (strstr(serialAns, "X:") == NULL);
    arduinoAccess.unlock();
    if (isCommaDecimalMark == true) {
        pointDecimalMarkToComma(serialAns, this->bufsize);
    }
    switch (axis) {
    case 'X':
        sscanf(serialAns, "X:%lf ", &this->currentX);
        break;
    case 'Y':
        test = strstr(serialAns, "Y:");
        sscanf(test, "Y:%lf ", &this->currentY);
        break;
    case 'Z':
        test = strstr(serialAns, "Z:");
        sscanf(test, "Z:%lf ", &this->currentZ);
        break;
    default:
        break;
    }
}
Example #2
0
bool Repetier::setBedTemp(int temp)
{
    char send[bufsize], serialAns[bufsize];
    int newBedTemp;
    if (this->tempBed == temp) {
        return false;
    }
    sprintf(send, "M140 S%d", temp);
    prepareStringToSend(send, this->bufsize);
    if (isCommaDecimalMark == true) {
        commaDecimalMarkToPoint(send, this->bufsize);
    }

    communicationBool.lock();
    arduinoAccess.lock();
    arduino->writeStr(send);
    do {
        arduino->readUntil(serialAns, '\n', this->bufsize);
    } while (serialAns[0] != 'T');
    prepareStringToReceive(serialAns, bufsize);
    if (isCommaDecimalMark == true) {
        pointDecimalMarkToComma(serialAns, this->bufsize);
    }
    if (sscanf(serialAns, "TargetBed:%d", &newBedTemp) != 0) {
        if (newBedTemp == temp) {
            this->tempBed = temp;
            if (logout) {
                //this->log->insertInfo(logtxt);
                char *logtxt = (char*)malloc(101 * sizeof(char));
                sprintf(logtxt, "Temperature of bed changed to %d oC.", this->tempBed);
                try {
                    this->log->insertInfo(logtxt);
                } catch (std:: string e) {
                    throw e;
                }
            }
            arduinoAccess.unlock();
            communicationBool.unlock();
            return true;
        } else {
            if (logout) {
                //this->log->insertInfo(logtxt);
                char *logtxt = (char*)malloc(101 * sizeof(char));
                sprintf(logtxt, "Attempted to change bed temperature to %d oC.", temp);
                try {
                    this->log->insertInfo(logtxt);
                } catch (std:: string e) {
                    throw e;
                }
            }
            arduinoAccess.unlock();
            communicationBool.unlock();
            return false;
        }
    }
    arduinoAccess.unlock();
    communicationBool.unlock();
    return false;
}
Example #3
0
bool Repetier::setFanSpeed(int speed)
{
    char send[this->bufsize], serialAns[this->bufsize];
    sprintf(send, "M106 S%d", speed);
    prepareStringToSend(send, this->bufsize);
    communicationBool.lock();
    arduinoAccess.lock();
    arduino->writeStr(send);
    do{
        arduino->readUntil(serialAns, '\n', this->bufsize);
    }while(strstr(serialAns, "ok") == NULL);
    arduino->readUntil(serialAns, '\n', this->bufsize);
    if(strstr(serialAns, "Fan")!=NULL){
        arduinoAccess.unlock();
        communicationBool.unlock();
        return true;
    }
    arduinoAccess.unlock();
    communicationBool.unlock();
    return false;
}
Example #4
0
bool Repetier::setFlowRate(int percentage)
{
    char send[this->bufsize], serialAns[this->bufsize];
    sprintf(send, "M221 S%d", percentage);
    prepareStringToSend(send, this->bufsize);
    communicationBool.lock();
    arduinoAccess.lock();
    arduino->writeStr(send);
    usleep(WAIT_TIME);
    do{
        arduino->readUntil(serialAns, '\n', this->bufsize);
    }while(strstr(serialAns, "ok") == NULL);
    arduino->readUntil(serialAns, '\n', this->bufsize);
    if(strstr(serialAns, "Flow") != NULL){
        arduinoAccess.unlock();
        communicationBool.unlock();
        return true;
    }
    arduinoAccess.unlock();
    communicationBool.unlock();
    return false;
}
Example #5
0
void Repetier::printJob() throw (std::string){
    unsigned long read = 0;
    char *send = NULL, serialAns[bufsize * 2], *logtxt = NULL, currentPos[10], currentTemp[10], *tempTxt;
    sprintf(currentPos, "M114");
    sprintf(currentTemp, "M105");
    prepareStringToSend(currentPos, 9);
    prepareStringToSend(currentTemp, 9);
    communicationBool.lock();
    isPrintingRunning = true;
    communicationBool.unlock();
    while(!this->LGCode->hasFQueueEnded()){
        communicationBool.lock();
        if(terminate == true){
            isPrintingRunning = false;
            communicationBool.unlock();
            return;
        }
        communicationBool.unlock();
        send = (char*)this->LGCode->returnInfo();
        if(send[0] == ';'){
            read++;
            continue;
        }
        arduinoAccess.lock();
        if(read % 200 == 0){
            arduino->writeStr("M117 Job Running\n\r");
            do{
                arduino->readUntil(serialAns, '\n', this->bufsize * 2);
            }while(strstr(serialAns, "ok") == NULL);
        }
        arduino->writeStr(send);
#ifdef WAIT_TIME
        usleep(WAIT_TIME);
#endif
        do{
            arduino->readUntil(serialAns, '\n', this->bufsize * 2);
        }while(strstr(serialAns, "ok") == NULL);
        if(logout){
            restoreSentString(send, bufsize);
            prepareStringToReceive(serialAns, bufsize);
            logtxt = (char*)malloc((50 + bufsize +(2 * bufsize)) * sizeof(char));
            sprintf(logtxt, "GCode SLOC %ld (%s) Ans: %s", (read + 1), send, serialAns);
            try{
                this->log->insertInfo(logtxt);
            }catch (std::string exc){
                throw exc;
            }
        }
        if(read % 5 == 0){
            arduino->writeStr(currentPos);
#ifdef WAIT_TIME
            usleep(WAIT_TIME);
#endif
            do{
                arduino->readUntil(serialAns, '\n', this->bufsize * 2);
            }while(strstr(serialAns, "X:") == NULL);
            if(isCommaDecimalMark == true){
                pointDecimalMarkToComma(serialAns, this->bufsize * 2);
            }
            //prepareStringToReceive(serialAns, this->bufsize * 2);
            sscanf(serialAns, "X:%lf Y:%lf Z:%lf E:%lf\r\n", &currentX, &currentY, &currentZ, &currentE);
            arduino->writeStr(currentTemp);
#ifdef WAIT_TIME
            usleep(WAIT_TIME);
#endif
            do{
                arduino->readUntil(serialAns, '\n', this->bufsize * 2);
            }while(strstr(serialAns, "T:") == NULL);
            prepareStringToReceive(serialAns, this->bufsize * 2);
            if(isCommaDecimalMark == true){
                pointDecimalMarkToComma(serialAns, this->bufsize * 2);
            }
            if(this->nExtruders == 1){
                sscanf(serialAns, "T:%lf ", &this->currentExtrTemp[0]);
                tempTxt = strstr(serialAns, "B:");
                sscanf(tempTxt, "B:%lf ", &this->currentBedTemp);
            }else{
                char format[8];
                tempTxt = strstr(serialAns, "B:");
                sscanf(tempTxt, "B:%lf ", &this->currentBedTemp);
                for(int i = 0; i < this->nExtruders; i++){
                    sprintf(format, "T%d:", i);
                    tempTxt = strstr(serialAns, format);
                    sprintf(format, "T%d:%%lf ", i);
                    sscanf(tempTxt, format, &this->currentExtrTemp[i]);
                }
            }
        }
        read++;
        arduinoAccess.unlock();
    }
    arduinoAccess.lock();
    arduino->writeStr(currentTemp);
#ifdef WAIT_TIME
    usleep(WAIT_TIME);
#endif
    do{
        arduino->readUntil(serialAns, '\n', this->bufsize * 2);
    }while(strstr(serialAns, "T:") == NULL);
    if(isCommaDecimalMark == true){
        pointDecimalMarkToComma(serialAns, this->bufsize * 2);
    }
    arduinoAccess.unlock();
    prepareStringToReceive(serialAns, this->bufsize * 2);
    tempTxt = strstr(serialAns, "B:");
    sscanf(tempTxt, "B:%lf /%d ", &this->currentBedTemp, &this->tempBed);
    if(this->nExtruders == 1){
        sscanf(serialAns, "T:%lf /%d ", &this->currentExtrTemp[0], &this->tempExtr[0]);
    }else{
        char format[16];
        for(int i = 0; i < this->nExtruders; i++){
            sprintf(format, "T%d:", i);
            tempTxt = strstr(serialAns, format);
            sprintf(format, "T%d:%%lf /%%d ", i);
            sscanf(serialAns, format, &this->currentExtrTemp[i], &this->tempExtr[i]);
        }
    }
    communicationBool.lock();
    isPrintingRunning = false;
    communicationBool.unlock();
}
Example #6
0
bool Repetier::setExtrTemp(int extrNo, int temp) throw (std::string){
    char serialAns[bufsize], send[bufsize];
    int tempExt;
    if(extrNo < this->nExtruders){
        if(this->tempExtr[extrNo] == temp){
            return false;
        }
        sprintf(send, "M104 S%d T%d", temp, extrNo);
        prepareStringToSend(send, this->bufsize);
        if(isCommaDecimalMark == true){
            commaDecimalMarkToPoint(send, this->bufsize);
        }
        communicationBool.lock();
        arduinoAccess.lock();
        arduino->writeStr(send);
        do{
            arduino->readUntil(serialAns, '\n', this->bufsize);
            //test = strstr(serialAns, "TargetExtr");
        }while(serialAns[0] != 'T');
        prepareStringToReceive(serialAns, this->bufsize);
        if(isCommaDecimalMark == true){
            pointDecimalMarkToComma(serialAns, this->bufsize);
        }
        sprintf(send, "TargetExtr%d:%%d", extrNo);
        if(sscanf(serialAns, send, &tempExt) != 0){
            if(tempExt == temp){
                this->tempExtr[extrNo] = tempExt;
                if(logout){
                    //this->log->insertInfo(logtxt);
                    char *logtxt = (char*)malloc(101 * sizeof(char));
                    sprintf(logtxt, "Extruder temperature %d changed to %d oC.", extrNo, this->tempExtr[extrNo]);
                    try{
                        this->log->insertInfo(logtxt);
                    }catch(std:: string e){
                        throw e;
                    }
                }
                arduinoAccess.unlock();
                communicationBool.unlock();
                return true;
            }else{
                if(logout){
                    //this->log->insertInfo(logtxt);
                    char *logtxt = (char*)malloc(101 * sizeof(char));
                    sprintf(logtxt, "Attempted to change temperature of extruder %d to %d oC.", extrNo, temp);
                    try{
                        this->log->insertInfo(logtxt);
                    }catch(std:: string e){
                        throw e;
                    }
                }
                arduinoAccess.unlock();
                communicationBool.unlock();
                return false;
            }
        }
    }
    arduinoAccess.unlock();
    communicationBool.unlock();
    std::string exc = "Repetier: Invalid extruder number.";
    throw exc;
}