private synchronized void checkForReply() { mm_replyTimer.stop(); if (!mm_rtnFlag) { if (mm_numTry >= mm_numTries) { // Hard failure if (m_replyFailType != CRYO_UNRESPONSIVE) { if (m_port == TEMPCONTROLLER) { // SDM FIXME if(m_cryoPanel!= null) m_cryoPanel.txtrFault.setText("Temp Controller is // not responding"); } else { DataFileManager.writeMsgLog( "Cryomon is not responding after " + mm_numTries + " retries", debug); // System.out.println("Cryomon is not responding after "+mm_numTries+" retries"); // SDM FIXME if(m_cryoPanel!= null) m_cryoPanel.txtrFault.setText("CryoBay is not // responding"); // SDM FIXME m_cryoPanel.writeInfo("\nCryobay is not responding"); } m_replyFailType = CRYO_UNRESPONSIVE; } processReply(mm_rtnMsg, false); } else { // Try again // Messages.postDebug(" ... " + m_port + " resending command to Cryobay" + m_command); mm_numTry++; // DataFileManager.writeMsgLog("Sender retry:" + mm_numTry, debug); // if(debug) // System.out.println("Sender: "+m_command+" retry:" + mm_numTry); send(m_command); mm_replyTimer.start(); } } else { // Got the reply // mm_asListener.newMessage(mm_rtnMsg); if (m_replyFailType != CRYO_OK) { if (m_port == TEMPCONTROLLER) { // Messages.postInfo("Temp Controller connection OK"); if (m_cryoPanel != null) // m_cryoPanel.txtInfo.append("Temp Controller connection OK\n"); m_cryoPanel.writeInfo("\nTemp Controller connection OK"); } else { // Messages.postInfo("Cryogen Monitor connection OK"); if (m_cryoPanel != null) // m_cryoPanel.txtInfo.append("CryoBay connection OK\n"); m_cryoPanel.writeInfo("\nCryogen Monitor connection OK\n"); } m_replyFailType = CRYO_OK; } processReply(mm_rtnMsg, mm_rtnFlag); } }
/** * 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."); } } } }
/** * This method is called whenever a new entry is written to the data file. * * @param line is a text string containing fill data information */ protected void writeDataToFile(String line) { ArrayList<DataObject> array = DataFileManager.readFillData(); DataObject next = new DataObject(line); array.add(next); DataFileManager.writeFillData(array); }