function PrinterState_runGcode($gcodes, $rewrite = TRUE, $need_return = FALSE, &$return_data = '') { global $CFG; $arcontrol_fullpath = $CFG->config['arcontrol_c']; $tmpfile_fullpath = $CFG->config['temp'] . '_runGcode.gcode'; $output = array(); $command = ''; $ret_val = 0; if ($need_return && is_array($gcodes)) { foreach ($gcodes as $gcode) { $command = $arcontrol_fullpath . ' "' . $gcode . '"'; //TO_DO some gcode will not be responsed directly when using simulator 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 (count($output)) { // $return_data .= $output[0] . "\n"; // } // else { // $return_data .= "\n"; // } } foreach ($output as $line) { $return_data .= $line . "\n"; } } else { if (!$need_return && !is_array($gcodes)) { $fp = fopen($tmpfile_fullpath, 'w'); if ($fp) { fwrite($fp, $gcodes); fclose($fp); } return PrinterState_runGcodeFile($tmpfile_fullpath, $rewrite); } else { return FALSE; } } return TRUE; }
public function gcodefile() { $cr = 0; $gcode = NULL; $mode = ''; $rewrite = TRUE; $this->load->helper('printerstate'); $mode = $this->input->post('mode'); if ($mode == 'verbatim') { $rewrite = FALSE; } if ($_SERVER['REQUEST_METHOD'] == 'POST') { $upload_config = array('upload_path' => $this->config->item('temp'), 'allowed_types' => '*', 'overwrite' => TRUE, 'remove_spaces' => TRUE, 'encrypt_name' => TRUE); $this->load->library('upload', $upload_config); if ($this->upload->do_upload('f')) { $gcode = $this->upload->data(); $cr = PrinterState_runGcodeFile($gcode['full_path'], $rewrite); if ($cr == TRUE) { $cr = ERROR_OK; } else { $cr = ERROR_INTERNAL; } } else { // treat error - missing gcode file $cr = ERROR_MISS_PRM; } $this->_return_cr($cr); } else { //TODO change load view into parser? $this->load->view('template/rest/gcodefile_form'); } return; }
public function gcodefile() { $cr = 0; $gcode = NULL; $mode = ''; $rewrite = TRUE; $this->load->library('parser'); $this->load->helper('printerstate'); $mode = $this->input->post('mode'); if ($mode == 'verbatim') { $rewrite = FALSE; } if ($_SERVER['REQUEST_METHOD'] == 'POST') { $upload_config = array('upload_path' => $this->config->item('temp'), 'allowed_types' => '*', 'overwrite' => TRUE, 'remove_spaces' => TRUE, 'encrypt_name' => TRUE); $this->load->library('upload', $upload_config); if ($this->upload->do_upload('f')) { $gcode = $this->upload->data(); $cr = PrinterState_runGcodeFile($gcode['full_path'], $rewrite); if ($cr == TRUE) { $this->_parseBaseTemplate('Advanced user', $this->parser->parse('advanceduser/confirm', array(), TRUE)); } else { $this->_display_controlIndex('Internal error'); } } else { $this->_display_controlIndex('Missing file'); } } else { $this->output->set_header('Location: /'); } return; }