コード例 #1
0
ファイル: Repetier.cpp プロジェクト: tcanabrava/Br-Print3D
double Repetier::getExtruderTemp(unsigned int extrNo) throw (std::string){
    char send[this->bufsize], serialAns[this->bufsize * 2], *tempTxt = NULL, format[8];
    if(extrNo >= this->nExtruders){
        std::string exc = "Repetier: Invalid extruder number.";
        throw exc;
    }
    if(this->isPrintingRunning == false){
        sprintf(send, "M105\n\r");
        arduinoAccess.lock();
        arduino->writeStr(send);
        do{
            arduino->readUntil(serialAns, '\n', this->bufsize * 2);
        }while(strstr(serialAns, "T:") == NULL);
        if(isCommaDecimalMark == true){
            pointDecimalMarkToComma(serialAns, this->bufsize  * 2);
        }
        prepareStringToReceive(serialAns, this->bufsize);
        if(this->nExtruders == 1){
            sscanf(serialAns, "T:%lf ", &this->currentExtrTemp[extrNo]);
        }else{
            sprintf(format, "T%d:", extrNo);
            tempTxt = strstr(serialAns, format);
            sprintf(format, "T%d:%%lf ", extrNo);
            sscanf(tempTxt, format, &this->currentExtrTemp[extrNo]);
        }
        arduinoAccess.unlock();
    }
    return this->currentExtrTemp[extrNo];
}
コード例 #2
0
ファイル: Repetier.cpp プロジェクト: fuinha/brprint3d
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;
}
コード例 #3
0
ファイル: Repetier.cpp プロジェクト: tcanabrava/Br-Print3D
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();
}
コード例 #4
0
ファイル: Repetier.cpp プロジェクト: tcanabrava/Br-Print3D
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;
}
コード例 #5
0
ファイル: Repetier.cpp プロジェクト: tcanabrava/Br-Print3D
Repetier::Repetier(int baudrate, std::string serialport, int buffersize, double maxX, double maxY, double maxZ, bool resetWhenConnect, const bool isCommaDecimalMark) throw (std::string){
    char serialAns[buffersize * 2], send[buffersize], *vet;
    unsigned int pos;
    this->isCommaDecimalMark = isCommaDecimalMark;
    printThread = nullptr;
    isPrintingRunning = false;
    terminate = false;
    bufsize = buffersize;
    this->maxX = maxX;
    this->maxY = maxY;
    this->maxZ = maxZ;
    try{
        arduino = new ASerial(serialport, baudrate); //Try to open serial port.
    }catch (std::string exc){
        throw exc;  //If not possible, throw exception.
    }
    do{
        arduino->readUntil(serialAns, '\n', this->bufsize);
    }while(strstr(serialAns, "wait") == NULL); //Wait for the Arduino to be ready.
    if(resetWhenConnect == true){ //If user asks to reset Arduino…
        sprintf(send, "M112\n\r"); //Send reset code.
        arduino->writeStr(send);
        do{
            arduino->readUntil(serialAns, '\n', this->bufsize);
        }while(strstr(serialAns, "wait") == NULL); //Wait for the Arduino to be ready.
    }
    sprintf(send, "M115\n\r"); //Asks for printer capabilities string.
    arduino->writeStr(send);
    do{
        arduino->readUntil(serialAns, '\n', this->bufsize * 2);
    }while(strstr(serialAns, "FIRMWARE") == NULL); //Waits until answer is received
    vet = strstr(serialAns, "EXTRUDER_COUNT:"); //Searchs for extruder count
    if(vet != NULL){
        pos = strlen("EXTRUDER_COUNT:");
        if(vet[pos] < '0' || vet[pos] > '9'){
            delete arduino;
            std::string exc = "Repetier: Format error when acquiring number of extruders.";
            throw exc;
        }
        switch (vet[pos]){ //Adds extruder number to the object
            case '1':
                this->nExtruders = 1;
                break;
            case '2':
                this->nExtruders = 2;
                break;
            case '3':
                this->nExtruders = 3;
                break;
            case '4':
                this->nExtruders = 4;
                break;
            case '5':
                this->nExtruders = 5;
                break;
            case '6':
                this->nExtruders = 6;
                break;
            default:
                delete arduino;
                std::string exc = "Repetier: This class supports printers with 6 extruders max.";
                throw exc;
        }
    }else{
        delete arduino;
        std::string exc = "Repetier: Could not get the number of extruders.";
        throw exc;
    }
    this->tempExtr = (int*)malloc(this->nExtruders * sizeof(int)); //Initialize the vector with the extruders target temperatures
    if(tempExtr == NULL){
        delete arduino;
        std::string exc = "Repetier: Could not initialize Target Extruder Tempetarute vector.";
        throw exc;
    }
    currentExtrTemp = (double*)malloc(this->nExtruders * sizeof(double)); //Initialize the vector with the extruders temperature
    if(currentExtrTemp == NULL){
        delete arduino;
        free(tempExtr);
        std::string exc = "Repetier: Could not initilize Current Extruder Temperature vector.";
        throw exc;
    }
    sprintf(send, "M105\n\r"); //Ask for current temperatures
    arduino->writeStr(send);
    do{
        arduino->readUntil(serialAns, '\n', this->bufsize * 2);
    }while(strstr(serialAns, "T:") == NULL); //Wait for answer…
    if(this->nExtruders == 1){ //Read extruders temperature
        sscanf(serialAns, "T:%lf /%d ", &this->currentExtrTemp[0], &this->tempExtr[0]);
    }else{
        char format[8];
        for(int i = 0; i < this->nExtruders; i++){
            sprintf(format, "T%d:", i);
            vet = strstr(serialAns, format);
            sprintf(format, "T%d:%%lf /%%d ", i);
            sscanf(vet, format, &currentExtrTemp[i], &tempExtr[i]);
        }
    }
    vet = strstr(serialAns, "B:"); //Looks for bed temperature.
    sscanf(vet, "B:%lf /%d ", &currentBedTemp, &tempBed);
    sprintf(send, "M114\n\r"); //Asks for current position
    arduino->writeStr(send);
    do{
        arduino->readUntil(serialAns, '\n', this->bufsize);
    }while(strstr(serialAns, "X:") == NULL); //Wait for answers…
    prepareStringToReceive(serialAns, this->bufsize);
    sscanf(serialAns, "X:%lf Y:%lf Z:%lf E:%lf", &currentX, &currentY, &currentZ, &currentE); //Set positions…
    this->GCode = NULL;
    this->log = nullptr;
    this->LGCode = nullptr;
    this->logout = nullptr;
    do{
        arduino->readUntil(serialAns, '\n', this->bufsize);
    }while(strstr(serialAns, "wait") == NULL); //Wait for Arduino to be idle.
}