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; }
function PrinterState_runGcodeFile($gcode_path, $rewrite = TRUE) { global $CFG; $command = ''; $CI =& get_instance(); $CI->load->helper(array('detectos', 'printer')); // if (!PrinterState_beforeFileCommand()) { // return ERROR_INTERNAL; // } if ($rewrite == TRUE) { Printer_preparePrint(PRINTER_VALUE_MID_API_CALL); } $command = PrinterState_getPrintCommand(array(), $rewrite) . $gcode_path; // we can't check return output if ($CFG->config['simulator'] && DectectOS_checkWindows()) { pclose(popen($command, 'r')); // only for windows arcontrol client PrinterLog_logArduino($command); } else { pclose(popen($command . ' > ' . PRINTERSTATE_FILE_PRINTLOG . ' &', 'r')); PrinterLog_logArduino($command); // 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; // } } // if (!PrinterState_afterFileCommand()) { // return ERROR_INTERNAL; // } return TRUE; }