protected void writeDataToFile(Date date, String heLevel, String n2Level, int errors) { SimpleDateFormat fmt = new SimpleDateFormat("yy:MM:dd:HH:mm"); String time = fmt.format(date); if (prev_read != null && last_read.getTime() != prev_read.getTime()) errors |= HE_NEW_READ; writeDataToFile(time + "," + heLevel + "," + n2Level + "," + errors + "\n"); m_cryoPanel.updateUI(); }
public boolean getReadLogFlag() { if (m_cryoPanel == null) return false; return m_cryoPanel.getReadLogFlag(); }
/** * This method is called whenever a status message is received from the Cryogen Monitor. * * @param iWhat An integer coding what the value is for (status=152). * @param iValue Is true. */ protected void processStatus(String iWhat, boolean iValue) { StringTokenizer toker, dateToker; String elem, elem2; int errors = 0; String time = " "; String heLevel = "000"; String n2Level = "000"; // System.out.println("received:"+iWhat); iWhat = iWhat.replace("Connected to E5025", ""); if (!iValue) { if (m_cryoPanel != null) { m_cryoPanel.cryomonNotCommunicating(); } return; } // String key = new String(iWhat); if (iWhat == null) return; if (m_cryoPanel != null) m_cryoPanel.writeAdvanced("Received: " + iWhat + "\n"); toker = new StringTokenizer(iWhat, ","); if (iWhat.endsWith("Z*")) { // m_statusPoller.clrDataCount(); } else if (iWhat.endsWith("NH*")) { // m_statusPoller.clrDataCount(); } else if (iWhat.endsWith("EH*")) { if (m_cryoPanel != null) { // String msg=iWhat.replace("Connected", ""); m_cryoPanel.setErrors(iWhat); } } else if (iWhat.endsWith(" t*")) { // String s=iWhat.replace("Connected",""); Date date = getDate(iWhat); last_date = date; if (m_cryoPanel != null) m_cryoPanel.setTime(iWhat); } else if (iWhat.startsWith("V")) { if (m_cryoPanel != null) { String msg = iWhat.replace("*", ""); // System.out.println("CryoSocketControl version: " + msg); DataFileManager.setFirmwareVersion(msg); } } else if (iWhat.startsWith("Date")) { m_cryoPanel.writeAdvanced("Reading Log: " + iWhat + "\n"); // open file & read rest of lines into file String logFile = m_cryoPanel.getLogFile(); try { m_write2Log = true; pause(true); // System.out.println("Opening log file " + logFile); FileWriter outLog = new FileWriter(logFile, false); // open file and do not append data // System.out.println("Writing log file " + logFile); outLog.write(iWhat + "\n"); outLog.flush(); } catch (Exception e) { // System.out.println("Could not write log file."); } } else if (iWhat.endsWith("W*")) { if (m_cryoPanel != null) { errors = 0; heLevel = "000"; n2Level = "000"; while (toker.hasMoreTokens()) { elem = toker.nextToken(); if (elem.startsWith("E5") || elem.startsWith("E6")) { if (m_cryoPanel != null) DataFileManager.setMonitorType(elem); } else if (elem.startsWith("ND")) { elem = elem.substring(2, 5); m_cryoPanel.writeAdvanced("N2 level: " + elem + "\n"); n2Level = elem; } else if (elem.startsWith("HL")) { elem = elem.substring(2, 6); try { int HL = Integer.parseInt(elem); DataFileManager.HL = HL; m_cryoPanel.writeAdvanced("HL level: " + HL + "\n"); } catch (Exception e) { System.out.println("Input format error in HL"); } } else if (elem.startsWith("SA")) { errors = Integer.parseInt(elem.substring(2)); } else if (elem.startsWith("SB")) { int sb = Integer.parseInt(elem.substring(2)); errors += sb << 8; // m_cryoPanel.setStatus(errors); } else if (elem.startsWith("P1D")) { elem2 = toker.nextToken(); // get P2D for second probe if (elem.substring(8, 12).startsWith("+")) { elem = elem.substring(9, 12); } else { elem = elem.substring(8, 12); } if (elem2.substring(8, 12).startsWith("+")) { elem2 = elem2.substring(9, 12); } else { elem2 = elem2.substring(8, 12); } m_cryoPanel.writeAdvanced("He levelP1: " + elem + " levelP2: " + elem2 + "\n"); if (elem.startsWith("#") && elem2.startsWith("#")) // no probes enabled heLevel = "000"; else if (elem.startsWith("#")) heLevel = elem2; else if (elem2.startsWith("#")) heLevel = elem; else { // both probes enabled heLevel = elem; try { int v1 = Integer.parseInt(elem); int v2 = Integer.parseInt(elem2); int max_val = v1 > v2 ? v1 : v2; DecimalFormat myFormatter = new DecimalFormat("000"); String output = myFormatter.format(max_val); // System.out.println("He1:"+elem+" He2:"+elem2+" ave:"+output); heLevel = output; } catch (Exception e) { System.out.println("Input format error in He level"); } } } else if (elem.startsWith("t")) { time = elem.replace("t", ""); dateToker = new StringTokenizer(time, " "); if (dateToker.hasMoreTokens()) { prev_read = last_read; last_read = getDate(time); } } } if (last_date != null) { writeDataToFile(last_date, heLevel, n2Level, errors); } } } else if (m_write2Log) { if (iWhat.startsWith("*")) { // close file m_cryoPanel.popupMsg("Log File", "Cryogen Monitor log written", false); m_cryoPanel.writeAdvanced("Reading Log Done.\n"); m_write2Log = false; pause(false); m_cryoPanel.setReadLogFlag(false); } else { String logFile = m_cryoPanel.getLogFile(); try { FileWriter outLog = new FileWriter(logFile, true); // open file and append data outLog.write(iWhat + "\n"); outLog.flush(); } catch (Exception e) { // System.out.println("Could not write log file."); } } } }