//-------- //-------- Constructor //-------- /// <summary> /// Constructor a frame to contain the device data /// </summary> public DeviceFrameSensor(TaggedDevice dev, string logFile) : base(dev, logFile) { // construct the super // add to the center panel sensorLabel = new JLabel(" "); sensorLabel.HorizontalAlignment = JLabel.CENTER; sensorLabel.Font = new Font("SansSerif", Font.PLAIN, 20); centerPanel.add(sensorLabel); }
/// <summary> /// Parse the provided XML input stream with the provided parser. /// Gather the new TaggedDevices and OWPaths into the global vectors /// 'taggedDevices' and 'paths'. /// </summary> /// <param name="parser"> parser to parse 1-Wire XML files </param> /// <param name="stream"> XML file stream </param> /// <param name="currentPath"> OWPath that was opened to get to this file </param> /// <param name="autoSpawnFrames"> true if new DeviceFrames are spawned with /// new taggedDevices discovered </param> /// <returns> true an XML file was successfully parsed. </returns> public static bool parseStream(TAGParser parser, Stream stream, OWPath currentPath, bool autoSpawnFrames) { bool rslt = false; OWPath tempPath; Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); try { // parse the file List <TaggedDevice> new_devices = parser.parse(stream); // get the new paths List <OWPath> new_paths = parser.OWPaths; Debug.WriteLine("Success, XML parsed with " + new_devices.Count + " devices " + new_paths.Count + " paths"); // add the new devices to the old list for (int i = 0; i < new_devices.Count; i++) { TaggedDevice current_device = new_devices[i]; // update this devices OWPath depending on where we got it if its OWPath is empty tempPath = current_device.OWPath; if (!tempPath.AllOWPathElements.MoveNext()) { // replace this devices path with the current path tempPath.copy(currentPath); current_device.OWPath = tempPath; } // add the new device to the device list taggedDevices.Add(current_device); } // add the new paths for (int i = 0; i < new_paths.Count; i++) { paths.Add(new_paths[i]); } rslt = true; } catch (Exception e) { Debug.WriteLine("Error: " + e); } stopWatch.Stop(); Debug.WriteLine("Parsed in " + stopWatch.ElapsedMilliseconds + "ms"); return(rslt); }
/// <summary> /// Create an sensor monitor. /// </summary> /// <param name="dev"> Tagged device to monitor </param> /// <param name="logFile"> file name to log to </param> public DeviceMonitorSensor(TaggedDevice dev, string logFile) { // get ref to the contact device sensor = dev; // create the Frame that will display this device sensorFrame = new DeviceFrameSensor(dev, logFile); // init lastPollDelay = 0; currentSecondCount = 0; adapter = sensor.DeviceContainer.Adapter; // start up this service thread var t = Task.Run(() => { this.run(); }); }
//-------- //-------- Constructor //-------- /// <summary> /// Constructor a deviceFrame with additional features for the actuator /// </summary> public DeviceFrameActuator(TaggedDevice dev, string logFile) : base(dev, logFile) { // construct the super // create select panel selectPanel = new JPanel(); selectPanel.AlignmentX = Component.LEFT_ALIGNMENT; selectPanel.Border = BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "Select Actuator State"); // create combo box actuatorCombo = new JComboBox(((TaggedActuator)dev).Selections); Dimension actuatorComboDimension = new Dimension(170, 23); actuatorCombo.PreferredSize = actuatorComboDimension; actuatorCombo.Editable = false; actuatorCombo.AlignmentX = Component.LEFT_ALIGNMENT; actuatorCombo.addActionListener(this); // add combo box to select panel selectPanel.add(actuatorCombo); // add select panel to the center panel centerPanel.add(selectPanel); }
/// <summary> /// Create an actuator monitor. /// </summary> /// <param name="dev"> Tagged device to monitor </param> /// <param name="logFile"> file name to log to </param> public DeviceMonitorActuator(TaggedDevice dev, string logFile) { // get ref to the contact device actuator = dev; // create the Frame that will display this device actuatorFrame = new DeviceFrameActuator(dev, logFile); // hide the read items since this is an actuator actuatorFrame.hideReadItems(); // get adapter ref adapter = actuator.DeviceContainer.Adapter; // init last selection lastSelection = ""; didInit = false; // start up this service thread var t = Task.Run(() => { this.run(); }); }
/// <summary> /// Parse the provided XML input stream with the provided parser. /// Gather the new TaggedDevices and OWPaths into the global vectors /// 'taggedDevices' and 'paths'. /// </summary> /// <param name="parser"> parser to parse 1-Wire XML files </param> /// <param name="stream"> XML file stream </param> /// <param name="currentPath"> OWPath that was opened to get to this file </param> /// <param name="autoSpawnFrames"> true if new DeviceFrames are spawned with /// new taggedDevices discovered </param> /// <returns> true an XML file was successfully parsed. </returns> public static bool parseStream(TAGParser parser, Stream stream, OWPath currentPath, bool autoSpawnFrames) { bool rslt = false; OWPath tempPath; try { // parse the file List <TaggedDevice> new_devices = parser.parse(stream); // get the new paths List <OWPath> new_paths = parser.OWPaths; main_Renamed.Status = "Success, XML parsed with " + new_devices.Count + " devices " + new_paths.Count + " paths"; // add the new devices to the old list for (int i = 0; i < new_devices.Count; i++) { TaggedDevice current_device = (TaggedDevice)new_devices[i]; // update this devices OWPath depending on where we got it if its OWPath is empty tempPath = current_device.OWPath; if (!tempPath.AllOWPathElements.MoveNext()) { // replace this devices path with the current path tempPath.copy(currentPath); current_device.OWPath = tempPath; } // check if spawning frames if (autoSpawnFrames) { if (current_device is TaggedSensor) { main_Renamed.Status = "Spawning Sensor: " + current_device.Label; deviceFrames.Add(new DeviceMonitorSensor(current_device, logFile)); } else if (current_device is TaggedActuator) { main_Renamed.Status = "Spawning Actuator: " + current_device.Label; deviceFrames.Add(new DeviceMonitorActuator(current_device, logFile)); } } // add the new device to the device list taggedDevices.Add(current_device); } // add the new paths for (int i = 0; i < new_paths.Count; i++) { paths.Add(new_paths[i]); } rslt = true; } catch (org.xml.sax.SAXException se) { main_Renamed.Status = "XML error: " + se; } catch (IOException ioe) { main_Renamed.Status = "IO error: " + ioe; } return(rslt); }