コード例 #1
0
ファイル: printer_helper.php プロジェクト: Jaesin/zim-web
function Printer_printFromFile($gcode_path, $model_id, $time_estimation, $need_prime = TRUE, $exchange_extruder = FALSE, $array_filament = array(), $array_temper = array())
{
    global $CFG;
    $command = '';
    $output = array();
    $temper_json = array();
    $ret_val = 0;
    $stats_info = array();
    $CI =& get_instance();
    $CI->load->helper(array('printerstate', 'errorcode', 'corestatus', 'printerlog', 'detectos'));
    // check if we have no file
    if (!file_exists($gcode_path)) {
        return ERROR_INTERNAL;
    }
    // only check if we are in printing when we are not called stopping printing
    // 	if ($stop_printing == FALSE) {
    // check if in printing
    $ret_val = PrinterState_checkInPrint();
    if ($ret_val == TRUE) {
        // 			return ERROR_IN_PRINT;
        PrinterLog_logMessage('already in printing', __FILE__, __LINE__);
        return ERROR_BUSY_PRINTER;
    }
    // 	}
    // check extruder number
    if ($CI->config->item('nb_extruder') < 2) {
        $tmp_array = array();
        $command = $CFG->config['gcanalyser'] . $gcode_path;
        exec($command, $output, $ret_val);
        if ($ret_val != ERROR_NORMAL_RC_OK) {
            PrinterLog_logError('gcanalyser error', __FILE__, __LINE__);
            return ERROR_INTERNAL;
        }
        $tmp_array = json_decode($output[0], TRUE);
        if ($tmp_array['N'] > $CI->config->item('nb_extruder')) {
            PrinterLog_logMessage('no enough extruder', __FILE__, __LINE__);
            return ERROR_INTERNAL;
        }
    }
    // check if having enough filament
    $ret_val = PrinterState_checkFilaments($array_filament);
    if ($ret_val != ERROR_OK) {
        return $ret_val;
    }
    if ($time_estimation == 0) {
        $ret_val = Printer__getEstimation($array_filament, $time_estimation);
        if ($ret_val != TRUE) {
            PrinterLog_logError('system can not get estimation time');
            return ERROR_INTERNAL;
        }
    }
    // prepare subprinting gcode files and scripts
    $ret_val = Printer_preparePrint($model_id, $need_prime);
    if ($ret_val != ERROR_OK) {
        return $ret_val;
    }
    // 	if ($stop_printing == FALSE) {
    if ($CFG->config['simulator']) {
        // just set temperature for simulation
        PrinterState_setExtruder('r');
        PrinterState_setTemperature(210);
        PrinterState_setExtruder('l');
        PrinterState_setTemperature(200);
        PrinterState_setExtruder('r');
    }
    // change status json file
    foreach ($array_temper as $abb_filament => $tmp_temper) {
        if ($abb_filament != 'b' && (!array_key_exists($abb_filament, $array_filament) || $array_filament[$abb_filament] <= 0)) {
            $temper_json[$abb_filament] = NULL;
        } else {
            $temper_json[$abb_filament] = $array_temper[$abb_filament];
        }
    }
    $ret_val = CoreStatus_setInPrinting($model_id, $time_estimation, $exchange_extruder, $temper_json);
    // 	}
    // 	else {
    // 		$ret_val = CoreStatus_setInCanceling();
    // 	}
    if ($ret_val == FALSE) {
        return ERROR_INTERNAL;
    }
    // stats info
    $stats_info[PRINTERLOG_STATS_MODEL] = $model_id;
    foreach ($temper_json as $abb_filament => $tmp_temper) {
        if (isset($tmp_temper)) {
            $json_cartridge = array();
            $arrkey_type = PRINTERLOG_STATS_FILA_TYPE_R;
            $arrkey_color = PRINTERLOG_STATS_FILA_COLOR_R;
            if ($abb_filament == 'l') {
                $arrkey_type = PRINTERLOG_STATS_FILA_TYPE_L;
                $arrkey_color = PRINTERLOG_STATS_FILA_COLOR_L;
            }
            if (ERROR_OK == PrinterState_getCartridgeAsArray($json_cartridge, $abb_filament)) {
                $stats_info[$arrkey_type] = $json_cartridge[PRINTERSTATE_TITLE_MATERIAL];
                $stats_info[$arrkey_color] = $json_cartridge[PRINTERSTATE_TITLE_COLOR];
            }
        }
    }
    PrinterLog_statsPrint(PRINTERLOG_STATS_ACTION_START, $stats_info);
    // pass gcode to printer
    //	if (!PrinterState_beforeFileCommand()) {
    //		return ERROR_INTERNAL;
    //	}
    // use different command for priming
    if ($need_prime == FALSE) {
        $command = PrinterState_getPrintCommand($array_filament, TRUE, TRUE) . $gcode_path;
    } else {
        $command = PrinterState_getPrintCommand($array_filament) . $gcode_path;
    }
    // 		exec($command, $output, $ret_val);
    // 		if ($ret_val != ERROR_NORMAL_RC_OK) {
    // 			return ERROR_INTERNAL;
    // 		}
    if ($CFG->config['simulator'] && DectectOS_checkWindows()) {
        pclose(popen($command, 'r'));
        // only for windows arcontrol client
        PrinterLog_logArduino($command);
    } else {
        // 		exec($command, $output, $ret_val);
        pclose(popen($command . ' > ' . PRINTERSTATE_FILE_PRINTLOG . ' &', 'r'));
        // 		if (!PrinterState_filterOutput($output)) {
        // 			PrinterLog_logError('filter arduino output error', __FILE__, __LINE__);
        // 			return ERROR_INTERNAL;
        // 		}
        // 		if ($ret_val != ERROR_NORMAL_RC_OK) {
        // 			return $ret_val;
        // 		}
        // 		PrinterLog_logArduino($command, $output);
        PrinterLog_logArduino($command);
    }
    //	if (!PrinterState_afterFileCommand()) {
    //		return ERROR_INTERNAL;
    //	}
    return ERROR_OK;
}
コード例 #2
0
ファイル: rest.php プロジェクト: Jaesin/zim-web
 function __construct()
 {
     parent::__construct();
     $this->load->helper(array('form', 'url', 'json', 'errorcode', 'corestatus'));
     $status_current = '';
     if (CoreStatus_checkInInitialization() || CoreStatus_checkInConnection() || CoreStatus_checkInUSB()) {
         // let no block REST web service go for setting network
         if (CoreStatus_checkCallNoBlockRESTInConnection()) {
             return;
         }
         // we haven't finished initialization or connection yet
         $this->_exitWithError500(ERROR_BUSY_PRINTER . ' ' . t(MyERRMSG(ERROR_BUSY_PRINTER)), ERROR_BUSY_PRINTER);
     } else {
         if (!CoreStatus_checkInIdle($status_current)) {
             // check if the status is changed
             $ret_val = 0;
             $this->load->helper('printerstate');
             switch ($status_current) {
                 case CORESTATUS_VALUE_SLICE:
                     if (CoreStatus_checkCallNoBlockRESTInSlice()) {
                         // do not block some special REST for action in slicing
                         return;
                     }
                     $ret_val = PrinterState_checkBusyStatus($status_current);
                     if ($ret_val == FALSE) {
                         // still in slicing
                         break;
                     } else {
                         if ($status_current == CORESTATUS_VALUE_IDLE) {
                             // encounted some errors
                             break;
                         } else {
                             // CORESTATUS_VALUE_PRINT
                             $this->load->helper('printerlog');
                             PrinterLog_logMessage('call rest when we are in slicing, but finished really', __FILE__, __LINE__);
                         }
                     }
                     // we treat canceling as printing
                 // we treat canceling as printing
                 case CORESTATUS_VALUE_PRINT:
                     // do not block some special REST for action in printing
                     if (CoreStatus_checkCallNoBlockRESTInPrint()) {
                         return;
                     }
                 case CORESTATUS_VALUE_CANCEL:
                     //TODO test here for canceling
                     $ret_val = PrinterState_checkInPrint();
                     if ($ret_val == FALSE) {
                         $ret_val = CoreStatus_setInIdle();
                         if ($ret_val == TRUE) {
                             $this->load->helper('printerlog');
                             PrinterLog_logDebug('set idle when calling REST', __FILE__, __LINE__);
                             return;
                             // continue to generate if we are now in idle
                         }
                         $this->load->helper('printerlog');
                         PrinterLog_logError('can not set status in idle', __FILE__, __LINE__);
                     }
                     break;
                 default:
                     $ret_val = PrinterState_checkBusyStatus($status_current);
                     if ($ret_val == TRUE) {
                         $this->load->helper('printerlog');
                         PrinterLog_logDebug('set idle when calling REST', __FILE__, __LINE__);
                         return;
                         // status has changed to idle
                     }
                     break;
             }
             // do not block some special REST
             if (CoreStatus_checkCallNoBlockREST()) {
                 return;
             }
             // return that printer is busy
             $this->_exitWithError500(ERROR_BUSY_PRINTER . ' ' . t(MyERRMSG(ERROR_BUSY_PRINTER)), ERROR_BUSY_PRINTER);
         }
     }
 }
コード例 #3
0
function PrinterState_resumePrinting()
{
    global $CFG;
    $arcontrol_fullpath = $CFG->config['arcontrol_c'];
    $output = array();
    $command = '';
    $ret_val = 0;
    // check if we are in printing
    $ret_val = PrinterState_checkInPrint();
    if ($ret_val == TRUE) {
        // send stop gcode
        $command = $arcontrol_fullpath . PRINTERSTATE_RESUME_PRINT;
        exec($command, $output, $ret_val);
        if (!PrinterState_filterOutput($output, $command)) {
            PrinterLog_logError('filter arduino output error', __FILE__, __LINE__);
            return ERROR_INTERNAL;
        }
        PrinterLog_logArduino($command, $output);
        if ($ret_val != ERROR_NORMAL_RC_OK) {
            return ERROR_INTERNAL;
        }
    } else {
        PrinterLog_logMessage('we are not in printing when calling resume printing', __FILE__, __LINE__);
        return ERROR_NO_PRINT;
    }
    return ERROR_OK;
}