Example #1
0
 /// <summary> Removes a <code>OneWireContainer</code> from the list of containers that
 /// this adapter object will find.
 ///
 /// </summary>
 /// <param name="c">represents a 1-Wire device that this adapter should no longer
 /// report as found by a search
 /// </param>
 public virtual void  removeContainer(OneWireContainer c)
 {
     lock (containers.SyncRoot)
     {
         containers.Remove(c);
     }
 }
Example #2
0
 /// <summary> Adds a <code>OneWireContainer</code> to the list of containers that
 /// this adapter object will find.
 ///
 /// </summary>
 /// <param name="c">represents a 1-Wire device that this adapter will report from a search
 /// </param>
 public virtual void  addContainer(OneWireContainer c)
 {
     lock (containers.SyncRoot)
     {
         containers.Add(c);
     }
 }
Example #3
0
        /// <summary> Copies the 'current' 1-Wire device address being used by the adapter into
        /// the array.  This address is the last iButton or 1-Wire device found
        /// in a search (findNextDevice()...).
        /// This method copies into a user generated array to allow the
        /// reuse of the buffer.  When searching many iButtons on the one
        /// wire network, this will reduce the memory burn rate.
        ///
        /// </summary>
        /// <param name="address">An array to be filled with the current iButton address.
        /// </param>
        /// <seealso cref="com.dalsemi.onewire.utils.Address">
        /// </seealso>
        public override void  getAddress(byte[] address)
        {
            OneWireContainer temp = (OneWireContainer)containers[containers_index - 1];

            if (temp != null)
            {
                Array.Copy(temp.Address, 0, address, 0, 8);
            }
        }
Example #4
0
 /// <summary> Verifies that the iButton or 1-Wire device specified is present on
 /// the 1-Wire Network. This does not affect the 'current' device
 /// state information used in searches (findNextDevice...).
 ///
 /// </summary>
 /// <param name="address"> device address to verify is present
 ///
 /// </param>
 /// <returns>  <code>true</code> if device is present, else
 /// <code>false</code>.
 ///
 /// </returns>
 /// <seealso cref="com.dalsemi.onewire.utils.Address">
 /// </seealso>
 public override bool isPresent(long address)
 {
     lock (containers.SyncRoot)
     {
         for (int i = 0; i < containers.Count; i++)
         {
             OneWireContainer temp = (OneWireContainer)containers[i];
             long             addr = temp.AddressAsLong;
             if (addr == address)
             {
                 return(true);
             }
         }
     }
     return(false);
 }
Example #5
0
 /// <summary> Create a new 1-Wire path element.
 ///
 /// </summary>
 /// <param name="owcInstance">device that is the path element. Must implement
 /// SwitchContainer.
 /// </param>
 /// <param name="channelNumber">channel number of the 1-Wire path
 /// </param>
 public OWPathElement(OneWireContainer owcInstance, int channelNumber)
 {
     owc     = owcInstance;
     channel = channelNumber;
 }
        private static void PollSensors()
        {
            com.dalsemi.onewire.container.OneWireContainer owd = default(com.dalsemi.onewire.container.OneWireContainer);
            object state = null;

            com.dalsemi.onewire.container.TemperatureContainer tc       = default(com.dalsemi.onewire.container.TemperatureContainer);
            com.dalsemi.onewire.adapter.DSPortAdapter          oAdapter = null;
            bool bFound1w = false;

            for (int i = 0; i < 16; i++)
            {
                try
                {
                    //Logger.Log(Logger.LOGLEVEL_INFO, "Looking for 1 wire on USB" + i.ToString());

                    oAdapter = null;
                    try { oAdapter = com.dalsemi.onewire.OneWireAccessProvider.getAdapter("{DS9490}", "USB" + i.ToString()); }
                    catch (Exception ex)
                    {
                        string msg = ex.Message;
                        //Logger.Log(Logger.LOGLEVEL_INFO, "USB" + i.ToString() + " " + msg);
                    }

                    if (oAdapter != null)
                    {
                        bFound1w = true;
                        Logger.Log(Logger.LOGLEVEL_INFO, "Found 1 wire on USB" + i.ToString());
                        //java.util.Enumeration owd_enum = default(java.util.Enumeration);

                        // get exclusive use of 1-Wire network
                        oAdapter.beginExclusive(true);

                        // clear any previous search restrictions
                        oAdapter.setSearchAllDevices();
                        oAdapter.targetAllFamilies();
                        oAdapter.setSpeed(com.dalsemi.onewire.adapter.DSPortAdapter.SPEED_REGULAR);
                        //                        oAdapter.setSpeed(com.dalsemi.onewire.adapter.DSPortAdapter.SPEED_HYPERDRIVE);

                        // Get all device containers
                        //oAdapter.getAllDeviceContainers();

                        var owd_enum = getEnumerator(oAdapter);
                        //Logger.Log(Logger.LOGLEVEL_INFO, "Enumerating devices connected to adapter " + oAdapter.getAdapterName());

                        // enumerate through all the 1-Wire devices found (with Java-style enumeration)
                        while (owd_enum.hasMoreElements())
                        {
                            try
                            {
                                // retrieve OneWireContainer
                                owd = (com.dalsemi.onewire.container.OneWireContainer)owd_enum.nextElement();
                                // check to see if 1-Wire device supports temperatures, if so get address and temp.
                                if (owd is com.dalsemi.onewire.container.TemperatureContainer)
                                {
                                    // cast the OneWireContainer to TemperatureContainer
                                    tc = (com.dalsemi.onewire.container.TemperatureContainer)owd;
                                    // read the device
                                    state = tc.readDevice();
                                    // extract the temperature from previous read
                                    tc.doTemperatureConvert((sbyte[])state);
                                    SetValue(owd.getAddressAsString(), (int)tc.getTemperature((sbyte[])state));
                                }
                                else
                                {
                                    Logger.Log(Logger.LOGLEVEL_WARNING, "Non-thermometer device found");
                                }
                            }
                            catch (Exception ex)
                            {
                                string sError = "USB" + i.ToString() + " ";
                                try
                                {
                                    sError += owd.getAddressAsString() + " ";
                                }
                                catch (Exception ex2)
                                {
                                    sError += "NO ID: " + ex2.Message + " ";
                                }
                                sError += ex.ToString();

                                Logger.Log(Logger.LOGLEVEL_ERROR, sError);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    Logger.Log(Logger.LOGLEVEL_ERROR, "USB" + i.ToString() + " " + ex.ToString());
                }
                finally
                {
                    try
                    {
                        if (oAdapter != null)
                        {
                            // end exclusive use of 1-Wire net adapter
                            oAdapter.freePort();
                            oAdapter.endExclusive();
                        }
                    }
                    catch (Exception ex) { }
                }
            }
            if (!bFound1w)
            {
                Logger.Log(Logger.LOGLEVEL_INFO, "No 1 wire USB found");
            }
        }
Example #7
0
 /// <summary> Add a 1-Wire path element to this 1-Wire path.
 ///
 /// </summary>
 /// <param name="owc">1-Wire device switch
 /// </param>
 /// <param name="channel">of device that represents this 1-Wire path element
 ///
 /// </param>
 /// <seealso cref="copy(OWPath) copy">
 /// </seealso>
 public virtual void  add(OneWireContainer owc, int channel)
 {
     elements.Add(new OWPathElement(owc, channel));
 }