/// <summary> /// Create a new path with a starting path. New elements /// can be added with <CODE>add</CODE>. /// </summary> /// <param name="adapter"> where the 1-Wire path is based </param> /// <param name="currentPath"> starting value of this 1-Wire path /// </param> /// <seealso cref= #add(OneWireContainer, int) add </seealso> public OWPath(DSPortAdapter adapter, OWPath currentOWPath) { this.adapter = adapter; elements = new List <OWPathElement>(2); copy(currentOWPath); }
/// <summary> /// Search for all devices on the provided adapter and return /// a vector /// </summary> /// <param name="adapter"> valid 1-Wire adapter /// </param> /// <returns> Vector or OneWireContainers </returns> public static List <OneWireContainer> findAllDevices(DSPortAdapter adapter) { List <OneWireContainer> owd_vect = new List <OneWireContainer>(3); OneWireContainer owd; try { // clear any previous search restrictions adapter.setSearchAllDevices(); adapter.targetAllFamilies(); adapter.Speed = DSPortAdapter.SPEED_REGULAR; // enumerate through all the 1-Wire devices and collect them in a vector for (IEnumerator owd_enum = adapter.AllDeviceContainers; owd_enum.MoveNext();) { owd = (OneWireContainer)owd_enum.Current; owd_vect.Add(owd); // set owd to max possible speed with available adapter, allow fall back if (adapter.canOverdrive() && (owd.MaxSpeed == DSPortAdapter.SPEED_OVERDRIVE)) { owd.setSpeed(owd.MaxSpeed, true); } } } catch (Exception e) { Debug.WriteLine(e); } return(owd_vect); }
//-------- //-------- Constructor //-------- /// <summary> /// Create a 1-Wire Network Watcher /// </summary> /// <param name="adapter"> for 1-Wire Network to monitor </param> public OWNetWatch1(DSPortAdapter adapter) { // create vector to keep track of temperature watches watchers = new List <BackgroundTaskRegistration>(); // create a network monitor nm = new NetworkDeviceMonitor(adapter); // add this to the event listers nm.addDeviceMonitorEventListener(this); var localSettings = ApplicationData.Current.LocalSettings; if (!localSettings.Containers.ContainsKey("AppSettings")) { _container = localSettings.CreateContainer("AppSettings", ApplicationDataCreateDisposition.Always); } else { _container = localSettings.Containers["AppSettings"]; } // start the monitor var t = Task.Run(() => { nm.run(); }); }
// // The Run method is the entry point of a background task. // public void Run(IBackgroundTaskInstance taskInstance) { //TODO var settings = ApplicationData.Current.LocalSettings; //TODO _tc = (TemperatureContainer)settings.Values["TemperatureContainer"]; //TODO _path = (OWPath)settings.Values["OWPath"]; if ((_tc == null) || (_path == null)) { Debugger.Break(); return; } // extract out the address and adapter _owc = (OneWireContainer)_tc; _address = _owc.AddressAsString; _adapter = _owc.Adapter; // // Associate a cancellation handler with the background task. // taskInstance.Canceled += new BackgroundTaskCanceledEventHandler(OnCanceled); // // Get the deferral object from the task instance, and take a reference to the taskInstance; // _deferral = taskInstance.GetDeferral(); _taskInstance = taskInstance; _periodicTimer = ThreadPoolTimer.CreatePeriodicTimer(new TimerElapsedHandler(PeriodicTimerCallback), TimeSpan.FromSeconds(2)); }
/// <summary> Provides this container with the adapter object used to access this device and /// the address of the iButton or 1-Wire device. /// /// </summary> /// <param name="sourceAdapter"> adapter object required to communicate with /// this iButton /// </param> /// <param name="newAddress"> address of this 1-Wire device /// </param> /// <seealso cref="com.dalsemi.onewire.utils.Address"> /// </seealso> public override void setupContainer(DSPortAdapter sourceAdapter, System.String newAddress) { base.setupContainer(sourceAdapter, newAddress); // initialize the memory banks initMem(); }
/// <summary> /// Notify the listeners of the exception /// </summary> /// <param name="ex"> The exception that occurred. </param> private void fireException(DSPortAdapter adapter, Exception ex) { for (int i = 0; i < listeners.Count; i++) { ((DeviceMonitorEventListener)listeners[i]).networkException(new DeviceMonitorException(this, adapter, ex)); } }
/// <summary> /// Creates a new <code>OneWireContainer</code> for communication with a DS28E04. /// </summary> /// <param name="sourceAdapter"> adapter object required to communicate with /// this 1-Wire device </param> /// <param name="newAddress"> address of this DS28E04 /// </param> /// <seealso cref= #OneWireContainer1C() </seealso> /// <seealso cref= #OneWireContainer1C(com.dalsemi.onewire.adapter.DSPortAdapter,byte[]) OneWireContainer1C(DSPortAdapter,byte[]) </seealso> /// <seealso cref= #OneWireContainer1C(com.dalsemi.onewire.adapter.DSPortAdapter,long) OneWireContainer1C(DSPortAdapter,long) </seealso> public OneWireContainer1C(DSPortAdapter sourceAdapter, string newAddress) : base(sourceAdapter, newAddress) { initmem(); for (int i = 0; i < FF.Length; i++) { FF[i] = unchecked ((byte)0x0FF); } }
/// <summary> /// Notify the listeners of the departure event /// </summary> /// <param name="address"> Vector of Long objects representing the address of /// departed devices. </param> protected internal virtual void fireDepartureEvent(DSPortAdapter adapter, List <long> address) { DeviceMonitorEvent dme = new DeviceMonitorEvent(DeviceMonitorEvent.DEPARTURE, this, adapter, address); for (int i = 0; i < listeners.Count; i++) { DeviceMonitorEventListener listener = (DeviceMonitorEventListener)listeners[i]; listener.deviceDeparture(dme); } }
/// <summary> /// Notify the listeners of the arrival event /// </summary> /// <param name="address"> Vector of Long objects representing the address of new /// arrivals. </param> protected internal virtual void fireArrivalEvent(DSPortAdapter adapter, List <long> address) { DeviceMonitorEvent dme = new DeviceMonitorEvent(DeviceMonitorEvent.ARRIVAL, this, adapter, address); for (int i = 0; i < listeners.Count; i++) { DeviceMonitorEventListener listener = (DeviceMonitorEventListener)listeners[i]; listener.deviceArrival(dme); } }
/// <summary> /// Creates a new DeviceMonitor event with the specified characteristics. /// </summary> /// <param name="eventType"> The type of event (ARRIVAL | DEPARTURE) </param> /// <param name="source"> The monitor which generated the event </param> /// <param name="adapter"> The DSPortAdapter the monitor was using </param> /// <param name="addresses"> Vector of addresses for devices </param> internal DeviceMonitorEvent(int eventType, AbstractDeviceMonitor source, DSPortAdapter adapter, List <long> addresses) { if (eventType != ARRIVAL && eventType != DEPARTURE) { throw new System.ArgumentException("Invalid event type: " + eventType); } this.eventType = eventType; this.monitor = source; this.adapter = adapter; this.vDeviceAddress = addresses; }
/// <summary> /// <P>Modifies this SHA iButton so that it refers to another 1963S. /// If this object already has an appropriate instance of OneWireContainer, /// that instance is updated with the new address.</P> /// </summary> /// <param name="adapter"> The adapter that the device can be found on. </param> /// <param name="address"> The address of the 1-Wire device /// </param> /// <returns> <code>true</code> if a valid account service file exists on /// this <code>OneWireContainer18</code>. /// </returns> /// <exception cref="OneWireIOException"> on a 1-Wire communication error such as /// reading an incorrect CRC from a 1-Wire device. This could be /// caused by a physical interruption in the 1-Wire Network due to /// shorts or a newly arriving 1-Wire device issuing a 'presence pulse'. </exception> /// <exception cref="OneWireException"> on a communication or setup error with the 1-Wire /// adapter </exception> public override bool setiButtonUser(DSPortAdapter adapter, byte[] address) { lock (this) { if (this.ibc33 == null) { this.ibc33 = new OneWireContainer33(); } this.ibc33.setupContainer(adapter, address); return(setiButton33(this.ibc33)); } }
public void RunInterface(string pluginName) { osae.AddToLog("Loading (0.2.4)...", true); osae.AddToLog("Current Environment Version: " + Environment.Version.Major.ToString(), true); if (Environment.Version.Major >= 4) { string folder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Windows), @"Microsoft.NET\Framework64\v2.0.50727"); if (!Directory.Exists(folder)) { folder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Windows), @"Microsoft.NET\Framework\v2.0.50727"); } osae.AddToLog("vjsnativ.dll path: " + folder, false); folder = Path.GetFullPath(folder); LoadLibrary(Path.Combine(folder, "vjsnativ.dll")); } pName = pluginName; string adapterProp = osae.GetObjectPropertyValue(pName, "Adapter").Value; string port = osae.GetObjectPropertyValue(pName, "Port").Value; uom = osae.GetObjectPropertyValue(pName, "Unit of Measure").Value; osae.AddToLog("adapterProp: " + adapterProp, false); osae.AddToLog("port: " + port, false); osae.AddToLog("uom: " + uom, false); try { adapter = OneWireAccessProvider.getAdapter(adapterProp, "COM" + port); } catch (Exception ex) { osae.AddToLog("Failed to GetAdapter - " + ex.Message + " - " + ex.InnerException.Message, true); } if (adapter.adapterDetected()) { osae.AddToLog("Adapter Detected", true); adapter.setSearchAllDevices(); Clock = new System.Threading.Timer(poll, null, 0, 10000); if (restarting) { restarting = false; } } else { osae.AddToLog("Adapter(" + adapterProp + ") not found on port " + port, true); } }
/// <summary> /// Sets the OWPath for the tagged device. An /// OWPath is a description of how to /// physically get to a 1-Wire device through a /// set of nested 1-Wire switches. /// </summary> /// <param name="adapter"> </param> /// <param name="Branches"> </param> public virtual void setOWPath(DSPortAdapter adapter, List <TaggedDevice> Branches) { OWPath = new OWPath(adapter); TaggedDevice TDevice; for (int i = 0; i < Branches.Count; i++) { TDevice = Branches[i]; OWPath.add(TDevice.DeviceContainer, TDevice.Channel); } }
/// <summary> Memory bank constructor. Requires reference to the OneWireContainer /// this memory bank resides on. /// </summary> public MemoryBankSHAEE(OneWireContainer33 ibutton, MemoryBankScratchSHAEE scratch) { // keep reference to ibutton where memory bank is ib = ibutton; scratchpad = scratch; // keep reference to adapter that button is on adapter = ib.Adapter; // indicate speed has not been set doSetSpeed = true; }
/// <summary> /// Construct the tag parser. /// </summary> /// <param name="adapter"> What port adapter will serve the devices created. </param> public TAGParser(DSPortAdapter adapter) { handler = new TAGHandler(); try { handler.Adapter = adapter; } catch (System.Exception e) { Debug.WriteLine(e); } }
/// <summary> /// Main for the OWNetWatch Demo /// </summary> /// <param name="args"> command line arguments </param> public static void Main1(string[] args) { int delay; try { // get the default adapter DSPortAdapter adapter = OneWireAccessProvider.DefaultAdapter; Debug.WriteLine(""); Debug.WriteLine("Adapter: " + adapter.AdapterName + " Port: " + adapter.PortName); Debug.WriteLine(""); // clear any previous search restrictions adapter.setSearchAllDevices(); adapter.targetAllFamilies(); adapter.Speed = DSPortAdapter.SPEED_REGULAR; // create the watcher with this adapter OWNetWatch1 nw = new OWNetWatch1(adapter); // sleep for the specified time if (args.Length >= 1) { delay = Int32.Parse(args[0]); } else { delay = 20000; } Debug.WriteLine("Monitor run for: " + delay + "ms"); Thread.Sleep(delay); // clean up Debug.WriteLine("Done with monitor run, now cleanup threads"); nw.killNetWatch(); // free port used by adapter adapter.freePort(); } catch (Exception e) { Debug.WriteLine(e); } return; }
public override void RunInterface(string pluginName) { pName = pluginName; Log = new General.OSAELog(pName); Log.Info("Current Environment Version: " + Environment.Version.Major.ToString()); if (Environment.Version.Major >= 4) { string folder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Windows), @"Microsoft.NET\Framework64\v2.0.50727"); if (!Directory.Exists(folder)) { folder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Windows), @"Microsoft.NET\Framework\v2.0.50727"); } Log.Debug("vjsnativ.dll path: " + folder); folder = Path.GetFullPath(folder); LoadLibrary(Path.Combine(folder, "vjsnativ.dll")); } string adapterProp = OSAEObjectPropertyManager.GetObjectPropertyValue(pName, "Adapter").Value; string port = OSAEObjectPropertyManager.GetObjectPropertyValue(pName, "Port").Value; uom = OSAEObjectPropertyManager.GetObjectPropertyValue(pName, "Unit of Measure").Value; Log.Debug("adapterProp: " + adapterProp + ", port: " + port + ", uom: " + uom); try { adapter = OneWireAccessProvider.getAdapter(adapterProp, "COM" + port); } catch (Exception ex) { Log.Error("Failed to GetAdapter ", ex); } if (adapter.adapterDetected()) { Log.Info("Adapter Detected"); adapter.setSearchAllDevices(); Clock = new System.Threading.Timer(poll, null, 0, 10000); if (restarting) { restarting = false; } } else { Log.Info("Adapter(" + adapterProp + ") not found on port " + port); } }
/// <summary> Provides this container with the adapter object used to access this device and /// the address of the iButton or 1-Wire device. /// /// </summary> /// <param name="sourceAdapter"> adapter object required to communicate with /// this iButton /// </param> /// <param name="newAddress"> address of this 1-Wire device /// </param> /// <seealso cref="com.dalsemi.onewire.utils.Address"> /// </seealso> public virtual void setupContainer(DSPortAdapter sourceAdapter, System.String newAddress) { // get a reference to the source adapter (will need this to communicate) adapter = sourceAdapter; // set the Address lock (this) { address = com.dalsemi.onewire.utils.Address.toByteArray(newAddress); addressCopy = new byte[8]; } // set desired speed to be SPEED_REGULAR by default with no fallback speed = DSPortAdapter.SPEED_REGULAR; speedFallBackOK = false; }
/// <summary> /// Returns the OneWireContainer object of the device with the given address. /// </summary> /// <param name="adapter"> The DSPortAdapter that the device is connected to. </param> /// <param name="address"> a Long object representing the address of the device </param> /// <returns> The specific OneWireContainer object of the device </returns> public static OneWireContainer getDeviceContainer(DSPortAdapter adapter, long longAddress) { lock (deviceContainerHash) { if (!deviceContainerHash.ContainsKey(longAddress)) { var o = adapter.getDeviceContainer(longAddress); putDeviceContainer(longAddress, o); return(o); } else { return(deviceContainerHash[longAddress]); } } }
public override void RunInterface(string pluginName) { this.Log.Info("Loading (0.2.4)..."); this.Log.Info("Current Environment Version: " + Environment.Version.Major.ToString()); if (Environment.Version.Major >= 4) { string folder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Windows), @"Microsoft.NET\Framework64\v2.0.50727"); if (!Directory.Exists(folder)) folder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Windows), @"Microsoft.NET\Framework\v2.0.50727"); this.Log.Debug("vjsnativ.dll path: " + folder); folder = Path.GetFullPath(folder); LoadLibrary(Path.Combine(folder, "vjsnativ.dll")); } pName = pluginName; string adapterProp = OSAEObjectPropertyManager.GetObjectPropertyValue(pName, "Adapter").Value; string port = OSAEObjectPropertyManager.GetObjectPropertyValue(pName, "Port").Value; uom = OSAEObjectPropertyManager.GetObjectPropertyValue(pName, "Unit of Measure").Value; this.Log.Debug("adapterProp: " + adapterProp); this.Log.Debug("port: " + port); this.Log.Debug("uom: " + uom); try { adapter = OneWireAccessProvider.getAdapter(adapterProp, "COM" + port); } catch (Exception ex) { this.Log.Error("Failed to GetAdapter ", ex); } if (adapter.adapterDetected()) { this.Log.Info("Adapter Detected"); adapter.setSearchAllDevices(); Clock = new System.Threading.Timer(poll, null, 0, 10000); if (restarting) { restarting = false; } } else this.Log.Info("Adapter(" + adapterProp + ") not found on port " + port); }
public StartMissionForm(DSPortAdapter adapter, OneWireContainer41 owc41) { this.adapter = adapter; this.owc41 = owc41; // // Required for Windows Form Designer support // InitializeComponent(); // // TODO: Add any constructor code after InitializeComponent call // temperatureResolution.SelectedIndex = 0; humidityResolution.SelectedIndex = 0; if (owc41 == null) { this.Text += " on all DS1922s"; this.humidityGroupBox.Text = "Data"; } else { this.humidityGroupBox.Text = owc41.getMissionLabel(OneWireContainer41.DATA_CHANNEL); this.Text += " on device: " + owc41.AddressAsString; } if (this.humidityGroupBox.Text.Equals("Humidity")) { this.enableHumiditySampling.Text = "Enable Humidity Sampling"; this.enableHumdHighAlarm.Text = "Enable High Alarm (%RH)"; this.enableHumdLowAlarm.Text = "Enable Low Alarm (%RH)"; } else { this.enableHumiditySampling.Text = "Enable Sampling"; this.enableHumdHighAlarm.Text = "Enable High Alarm"; this.enableHumdLowAlarm.Text = "Enable Low Alarm"; } if (owc41 != null && (owc41.Name.Equals("DS1922T") || owc41.Name.Equals("DS1922L") || owc41.Name.Equals("DS1922E"))) { this.humidityGroupBox.Enabled = false; this.enableHumiditySampling.Checked = false; } }
//-------- //-------- Setup and adapter methods //-------- /// <summary> Provides this container with the adapter object used to access this device and /// the address of the iButton or 1-Wire device. /// /// </summary> /// <param name="sourceAdapter"> adapter object required to communicate with /// this iButton /// </param> /// <param name="newAddress"> address of this 1-Wire device /// </param> /// <seealso cref="com.dalsemi.onewire.utils.Address"> /// </seealso> public virtual void setupContainer(DSPortAdapter sourceAdapter, byte[] newAddress) { // get a reference to the source adapter (will need this to communicate) adapter = sourceAdapter; // set the Address lock (this) { address = new byte[8]; addressCopy = new byte[8]; Array.Copy(newAddress, 0, address, 0, 8); } // set desired speed to be SPEED_REGULAR by default with no fallback speed = DSPortAdapter.SPEED_REGULAR; speedFallBackOK = false; }
/// <summary> /// <P>Modifies this SHA iButton so that it refers to another 1963S. /// If this object already has an appropriate instance of OneWireContainer, /// that instance is updated with the new address.</P> /// </summary> /// <param name="adapter"> The adapter that the device can be found on. </param> /// <param name="address"> The address of the 1-Wire device /// </param> /// <returns> <code>true</code> if a valid account service file exists on /// this <code>OneWireContainer18</code>. /// </returns> /// <exception cref="OneWireIOException"> on a 1-Wire communication error such as /// reading an incorrect CRC from a 1-Wire device. This could be /// caused by a physical interruption in the 1-Wire Network due to /// shorts or a newly arriving 1-Wire device issuing a 'presence pulse'. </exception> /// <exception cref="OneWireException"> on a communication or setup error with the 1-Wire /// adapter </exception> public override bool setiButtonUser(DSPortAdapter adapter, byte[] address) { lock (this) { if (this.ibc == null) { this.ibc = new OneWireContainer18(); } this.ibc.setupContainer(adapter, address); if (this.forceOverdrive) { this.ibc.setSpeed(DSPortAdapter.SPEED_OVERDRIVE, false); } return(setiButton18(this.ibc)); } }
/// <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(); }); }
public OWWatch1(DSPortAdapter adapter) { // create the watcher with this adapter dm = new DeviceMonitor(adapter); // add this to the event listers try { dm.addDeviceMonitorEventListener(this); } catch (Exception) { } // start the monitor var t = Task.Run(() => { dm.run(); }); }
/// <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> Create a container with the provided adapter instance /// and the address of the iButton or 1-Wire device.<p> /// /// This is one of the methods to construct a container. The other is /// through creating a OneWireContainer with NO parameters. /// /// </summary> /// <param name="sourceAdapter"> adapter instance used to communicate with /// this 1-Wire device /// </param> /// <param name="newAddress"> {@link com.dalsemi.onewire.utils.Address Address} /// of this 1-Wire device /// /// </param> /// <seealso cref="OneWireContainer1D() OneWireContainer1D"> /// </seealso> /// <seealso cref="com.dalsemi.onewire.utils.Address utils.Address"> /// </seealso> public OneWireContainer1D(DSPortAdapter sourceAdapter, System.String newAddress) : base(sourceAdapter, newAddress) { }
/// <summary> Create a container with the provided adapter instance /// and the address of the iButton or 1-Wire device.<p> /// /// This is one of the methods to construct a container. The other is /// through creating a OneWireContainer with NO parameters. /// /// </summary> /// <param name="sourceAdapter"> adapter instance used to communicate with /// this iButton /// </param> /// <param name="newAddress"> {@link com.dalsemi.onewire.utils.Address Address} /// of this 1-Wire device /// /// </param> /// <seealso cref="OneWireContainer1D() OneWireContainer1D"> /// </seealso> /// <seealso cref="com.dalsemi.onewire.utils.Address utils.Address"> /// </seealso> public OneWireContainer1D(DSPortAdapter sourceAdapter, byte[] newAddress) : base(sourceAdapter, newAddress) { }
public override void Shutdown() { logging.AddToLog("Running shutdown logic", true); adapter.freePort(); adapter = null; }
/// <summary> /// Creates an object for the device with the supplied address connected /// to the supplied port adapter. </summary> /// <param name="adapter"> The adapter serving the actuator. </param> /// <param name="netAddress"> The 1-Wire network address of the actuator. </param> public Switch(DSPortAdapter adapter, string netAddress) : base(adapter, netAddress) { ActuatorSelections = new List <string>(); }
/// <summary> /// Main for 1-Wire File Shell (OWFish) /// </summary> public static void Main1(string[] args) { List <OneWireContainer> owd_vect = new List <OneWireContainer>(5); OneWireContainer[] owd = null; DSPortAdapter adapter = null; int selection, len; long start_time, end_time; Stopwatch stopWatch = new Stopwatch(); FileStream fos; Stream fis; // FileDescriptor fd; OWFileOutputStream owfos; OWFileInputStream owfis; OWFileDescriptor owfd; OWFile owfile, new_owfile; byte[] block = new byte[32]; Debug.WriteLine(""); Debug.WriteLine("1-Wire File Shell (OWFish): Version 0.00"); Debug.WriteLine(""); // load the simulated console input stream Stream stream = loadResourceFile("OWFish.input.txt"); dis = new StreamReader(stream); stopWatch.Start(); try { // get the default adapter adapter = OneWireAccessProvider.DefaultAdapter; // adapter driver info Debug.WriteLine("========================================================================="); Debug.WriteLine("== Adapter Name: " + adapter.AdapterName); Debug.WriteLine("== Adapter Port description: " + adapter.PortTypeDescription); Debug.WriteLine("== Adapter Version: " + adapter.AdapterVersion); Debug.WriteLine("== Adapter support overdrive: " + adapter.canOverdrive()); Debug.WriteLine("== Adapter support hyperdrive: " + adapter.canHyperdrive()); Debug.WriteLine("== Adapter support EPROM programming: " + adapter.canProgram()); Debug.WriteLine("== Adapter support power: " + adapter.canDeliverPower()); Debug.WriteLine("== Adapter support smart power: " + adapter.canDeliverSmartPower()); Debug.WriteLine("== Adapter Class Version: " + adapter.ClassVersion); // get exclusive use of adapter adapter.beginExclusive(true); // loop to do menu selection = MAIN_SELECT_DEVICE; do { start_time = 0; try { switch (selection) { case MAIN_SELECT_DEVICE: // find all parts owd_vect = findAllDevices(adapter); // select a device owd = selectDevice(owd_vect); // check for quite if (owd == null) { selection = MAIN_QUIT; } else { // display device info Debug.WriteLine(""); Debug.WriteLine(" Device(s) selected: "); printDeviceInfo(owd, false); } break; case MAIN_FORMAT: if (menuSelect(verifyMenu) == VERIFY_YES) { // start time of operation start_time = stopWatch.ElapsedMilliseconds; // create a 1-Wire file at root owfile = new OWFile(owd, ""); // format Filesystem owfile.format(); // get 1-Wire File descriptor to flush to device owfd = owfile.FD; syncFileDescriptor(owfd); // close the 1-Wire file to release owfile.close(); } break; case MAIN_LIST: Debug.Write("Enter the directory to list on (/ for root): "); // get the directory and create a file on it owfile = new OWFile(owd, getString(1)); Debug.WriteLine(""); // start time of operation start_time = stopWatch.ElapsedMilliseconds; // list the files without recursion listDir(owfile, 1, false); // close the 1-Wire file to release owfile.close(); break; case MAIN_RLIST: // start time of operation start_time = stopWatch.ElapsedMilliseconds; // get the directory and create a file on it owfile = new OWFile(owd, ""); Debug.WriteLine(""); // recursive list listDir(owfile, 1, true); // close the 1-Wire file to release owfile.close(); break; case MAIN_MKDIR: Debug.Write("Enter the directory to create (from root): "); // get the directory and create a file on it owfile = new OWFile(owd, getString(1)); // start time of operation start_time = stopWatch.ElapsedMilliseconds; // make the directories if (owfile.mkdirs()) { Debug.WriteLine("Success!"); } else { Debug.WriteLine("-----------------------------------------------"); Debug.WriteLine("Could not create directories, out of memory or invalid directory/file"); Debug.WriteLine("-----------------------------------------------"); } // get 1-Wire File descriptor to flush to device owfd = owfile.FD; syncFileDescriptor(owfd); // close the 1-Wire file to release owfile.close(); break; case MAIN_COPYTO: // system SOURCE file Debug.Write("Enter the path/file of the SOURCE file on the system: "); //TODO fis = new FileStream(getString(1), FileMode.Open, FileAccess.Read); fis = loadResourceFile(getString(1)); // 1-Wire DESTINATION file Debug.Write("Enter the path/file of the DESTINATION on 1-Wire device: "); owfos = new OWFileOutputStream(owd, getString(1)); // start time of operation start_time = stopWatch.ElapsedMilliseconds; // loop to copy block from SOURCE to DESTINATION do { len = fis.Read(block, 0, block.Length); if (len > 0) { owfos.write(block, 0, len); } } while (len > 0); // get 1-Wire File descriptor to flush to device owfd = owfos.FD; syncFileDescriptor(owfd); // close the files owfos.Close(); fis.Dispose(); break; case MAIN_COPYFROM: // 1-Wire SOURCE file Debug.Write("Enter the path/file of the SOURCE file on 1-Wire device: "); owfis = new OWFileInputStream(owd, getString(1)); // system DESTINATION file Debug.Write("Enter the path/file of the DESTINATION on system: "); StorageFolder localFolder = ApplicationData.Current.LocalFolder; string outp = localFolder.Path + "\\" + getString(1); fos = new FileStream(outp, FileMode.Create, FileAccess.Write); // start time of operation start_time = stopWatch.ElapsedMilliseconds; // loop to copy block from SOURCE to DESTINATION do { len = owfis.read(block); if (len > 0) { fos.Write(block, 0, len); } } while (len > 0); // get 1-Wire File descriptor to flush to device fos.Flush(); // close the files owfis.close(); fos.Dispose(); break; case MAIN_CAT: // 1-Wire file Debug.Write("Enter the path/file of the file to display: "); owfis = new OWFileInputStream(owd, getString(1)); // start time of operation start_time = stopWatch.ElapsedMilliseconds; Debug.WriteLine(""); Debug.WriteLine("---FILE START---"); // loop to read and display file do { len = owfis.read(block); if (len > 0) { Debug.Write(System.Text.Encoding.UTF8.GetString(block)); com.dalsemi.onewire.debug.Debug.debug("file cat", block, 0, len); } } while (len > 0); Debug.WriteLine(""); Debug.WriteLine("---FILE END---"); // close the file owfis.close(); break; case MAIN_DELETE: Debug.Write("Enter the directory/file delete: "); // get the directory and create a file on it owfile = new OWFile(owd, getString(1)); Debug.WriteLine(""); // start time of operation start_time = stopWatch.ElapsedMilliseconds; // delete the directory/file if (owfile.delete()) { Debug.WriteLine("Success!"); } else { Debug.WriteLine("-----------------------------------------------"); Debug.WriteLine("Could not delete, if it is a directory make sure it is empty"); Debug.WriteLine("-----------------------------------------------"); } // get 1-Wire File descriptor to flush to device owfd = owfile.FD; syncFileDescriptor(owfd); // close the 1-Wire file to release owfile.close(); break; case MAIN_RENAME: Debug.Write("Enter the OLD directory/file name: "); // get the directory and create a file on it owfile = new OWFile(owd, getString(1)); Debug.WriteLine(""); Debug.Write("Enter the NEW directory/file name: "); // get the directory and create a file on it new_owfile = new OWFile(owd, getString(1)); Debug.WriteLine(""); // start time of operation start_time = stopWatch.ElapsedMilliseconds; // rename the directory/file if (owfile.renameTo(new_owfile)) { Debug.WriteLine("Success!"); } else { Debug.WriteLine("-----------------------------------------------"); Debug.WriteLine("Could not rename, make sure parents of new directory exist"); Debug.WriteLine("-----------------------------------------------"); } // get 1-Wire File descriptor to flush to device owfd = owfile.FD; syncFileDescriptor(owfd); // close the 1-Wire file to release owfile.close(); new_owfile.close(); break; case MAIN_DETAILS: Debug.Write("Enter the directory/file to view details: "); // get the directory and create a file on it owfile = new OWFile(owd, getString(1)); Debug.WriteLine(""); // start time of operation start_time = stopWatch.ElapsedMilliseconds; // show the file details showDetails(owfile); // close the 1-Wire file to release owfile.close(); break; case MAIN_FREEMEM: // start time of operation start_time = stopWatch.ElapsedMilliseconds; // create a 1-Wire file at root owfile = new OWFile(owd, ""); // get free memory Debug.WriteLine(""); Debug.WriteLine(" free memory: " + owfile.FreeMemory + " (bytes)"); // get the devices participating owd = owfile.OneWireContainers; Debug.WriteLine(""); Debug.WriteLine(" Filesystem consists of: "); printDeviceInfo(owd, true); // close the 1-Wire file to release owfile.close(); break; } ; } catch (IOException e) { Debug.WriteLine(""); Debug.WriteLine("-----------------------------------------------"); Debug.WriteLine(e); Debug.WriteLine("-----------------------------------------------"); } end_time = stopWatch.ElapsedMilliseconds; Debug.WriteLine(""); if (start_time > 0) { Debug.WriteLine((end_time - start_time) + "ms"); } Debug.WriteLine(""); if (selection != MAIN_QUIT) { selection = menuSelect(mainMenu); } Debug.WriteLine(""); } while (selection != MAIN_QUIT); } catch (Exception e) { Debug.WriteLine(e); } finally { if (adapter != null) { // end exclusive use of adapter adapter.endExclusive(); // free the port used by the adapter Debug.WriteLine("Releasing adapter port"); try { adapter.freePort(); } catch (OneWireException e) { Debug.WriteLine(e); } } } Debug.WriteLine(""); return; }
public override void Shutdown() { this.Log.Info("Running shutdown logic"); adapter.freePort(); adapter = null; }
public void Shutdown() { osae.AddToLog("Running shutdown logic", true); adapter.freePort(); adapter = null; }