Exemplo n.º 1
0
    /// <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 ArrayList findAllDevices(DSPortAdapter adapter)
    {
        ArrayList        owd_vect = new ArrayList(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 (System.Collections.IEnumerator owd_enum = adapter.AllDeviceContainers; owd_enum.MoveNext();)
            {
                owd = (OneWireContainer)owd_enum.Current;
                owd_vect.Add(owd);
            }
        }
        catch (Exception e)
        {
            Console.WriteLine(e);
        }

        return(owd_vect);
    }
Exemplo n.º 2
0
        /// <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     = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(2));

            copy(currentOWPath);
        }
Exemplo n.º 3
0
        /// <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, System.String newAddress) : base(sourceAdapter, newAddress)
        {
            initmem();

            for (int i = 0; i < FF.Length; i++)
            {
                FF[i] = (byte)SupportClass.Identity(0x0FF);
            }
        }
Exemplo n.º 4
0
    /// <summary>
    /// Method main
    ///
    /// </summary>
    /// <param name="args">
    ///  </param>
    public static void Main1(string[] args)
    {
        OneWireContainer owd;

        try
        {
            // get the default adapter
            DSPortAdapter adapter = OneWireAccessProvider.DefaultAdapter;

            Debug.WriteLine("");
            Debug.WriteLine("Adapter: " + adapter.AdapterName + " Port: " + adapter.PortName);
            Debug.WriteLine("");

            // get exclusive use of adapter
            adapter.beginExclusive(true);

            // clear any previous search restrictions
            adapter.setSearchAllDevices();
            adapter.targetAllFamilies();
            adapter.Speed = DSPortAdapter.SPEED_REGULAR;

            // enumerate through all the 1-Wire devices found
            for (System.Collections.IEnumerator owd_enum = adapter.AllDeviceContainers; owd_enum.MoveNext();)
            {
                owd = (OneWireContainer)owd_enum.Current;

                Debug.WriteLine(owd.AddressAsString);
            }

            // end exclusive use of adapter
            adapter.endExclusive();

            // free port used by adapter
            adapter.freePort();
        }
        catch (Exception e)
        {
            Debug.WriteLine(e);
        }

        return;
    }
Exemplo n.º 5
0
 /// <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="OneWireContainer0A() OneWireContainer0A">
 /// </seealso>
 /// <seealso cref="com.dalsemi.onewire.utils.Address utils.Address">
 /// </seealso>
 public OneWireContainer0A(DSPortAdapter sourceAdapter, System.String newAddress) : base(sourceAdapter, newAddress)
 {
 }
Exemplo n.º 6
0
 /// <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="OneWireContainer0A() OneWireContainer0A">
 /// </seealso>
 /// <seealso cref="com.dalsemi.onewire.utils.Address utils.Address">
 /// </seealso>
 public OneWireContainer0A(DSPortAdapter sourceAdapter, byte[] newAddress) : base(sourceAdapter, newAddress)
 {
 }
Exemplo n.º 7
0
 /// <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="OneWireContainer1A() OneWireContainer1A">
 /// </seealso>
 /// <seealso cref="com.dalsemi.onewire.utils.Address utils.Address">
 /// </seealso>
 public OneWireContainer1A(DSPortAdapter sourceAdapter, long newAddress) : base(sourceAdapter, newAddress)
 {
 }
        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");
            }
        }
Exemplo n.º 9
0
 protected OneWireDevice(string id, com.dalsemi.onewire.adapter.DSPortAdapter device_adapter)
 {
     owd_id = id;
     owd_name = id;
     adapter = device_adapter;
 }
Exemplo n.º 10
0
 public void setAdapter(com.dalsemi.onewire.adapter.DSPortAdapter new_adapter)
 {
     adapter = new_adapter;
 }
Exemplo n.º 11
0
 public Tree(com.dalsemi.onewire.adapter.DSPortAdapter tree_adapter)
 {
     adapter = tree_adapter;
 }
Exemplo n.º 12
0
    /// <summary>
    /// Method main, that provides the dialog box prompts to create the
    /// 1-Wire XML tag.
    /// </summary>
    /// <param name="args"> command line arguments </param>
    public static void Main(string[] args)
    {
        OneWireContainer tag_owd;
        DSPortAdapter    adapter = null;
        ArrayList        owd_vect = new ArrayList(5);
        bool             get_min = false, get_max = false, get_channel = false, get_init = false, get_scale = false;
        string           file_type, label, tag_type, method_type = null, cluster;
        string           min = null, max = null, channel = null, init = null, scale = null;

        // connect now message
        JOptionPane.showMessageDialog(null, "Connect the 1-Wire device to Tag onto the Default 1-Wire port", "1-Wire Tag Creator", JOptionPane.INFORMATION_MESSAGE);

        try
        {
            // get the default adapter
            adapter = OneWireAccessProvider.DefaultAdapter;

            // get exclusive use of adapter
            adapter.beginExclusive(true);

            // find all parts
            owd_vect = findAllDevices(adapter);

            // select a device
            tag_owd = selectDevice(owd_vect, "Select the 1-Wire Device to Tag");

            // enter the label for this devcie
            label = JOptionPane.showInputDialog(null, "Enter a human readable label for this device: ", "1-Wire tag Creator", JOptionPane.INFORMATION_MESSAGE);
            if (string.ReferenceEquals(label, null))
            {
                throw new InterruptedException("Aborted");
            }

            // enter the cluster for this devcie
            cluster = JOptionPane.showInputDialog(null, "Enter a cluster where this device will reside: ", "1-Wire tag Creator", JOptionPane.INFORMATION_MESSAGE);
            if (string.ReferenceEquals(cluster, null))
            {
                throw new InterruptedException("Aborted");
            }

            // select the type of device
            string[] tag_types = new string[] { "sensor", "actuator", "branch" };
            tag_type = (string)JOptionPane.showInputDialog(null, "Select the Tag Type", "1-Wire tag Creator", JOptionPane.INFORMATION_MESSAGE, null, tag_types, tag_types[0]);
            if (string.ReferenceEquals(tag_type, null))
            {
                throw new InterruptedException("Aborted");
            }

            // check if branch selected
            if (string.ReferenceEquals(tag_type, "branch"))
            {
                get_init    = true;
                get_channel = true;
            }
            // sensor
            else if (string.ReferenceEquals(tag_type, "sensor"))
            {
                string[] sensor_types = new string[] { "Contact", "Humidity", "Event", "Thermal" };
                method_type = (string)JOptionPane.showInputDialog(null, "Select the Sensor Type", "1-Wire tag Creator", JOptionPane.INFORMATION_MESSAGE, null, sensor_types, sensor_types[0]);
                if (string.ReferenceEquals(method_type, null))
                {
                    throw new InterruptedException("Aborted");
                }

                // contact
                if (string.ReferenceEquals(method_type, "Contact"))
                {
                    get_min = true;
                    get_max = true;
                }
                // Event
                else if (string.ReferenceEquals(method_type, "Event"))
                {
                    get_channel = true;
                    get_max     = true;
                }
            }
            // actuator
            else
            {
                string[] actuator_types = new string[] { "Switch", "D2A" };
                method_type = (string)JOptionPane.showInputDialog(null, "Select the Actuator Type", "1-Wire tag Creator", JOptionPane.INFORMATION_MESSAGE, null, actuator_types, actuator_types[0]);
                if (string.ReferenceEquals(method_type, null))
                {
                    throw new InterruptedException("Aborted");
                }

                get_channel = true;
                get_init    = true;
                get_min     = true;
                get_max     = true;
            }

            // enter the tags required
            if (get_min)
            {
                min = JOptionPane.showInputDialog(null, "Enter the 'min' value: ", "1-Wire tag Creator", JOptionPane.INFORMATION_MESSAGE);
            }
            if (string.ReferenceEquals(min, null))
            {
                get_min = false;
            }

            if (get_max)
            {
                max = JOptionPane.showInputDialog(null, "Enter the 'max' value: ", "1-Wire tag Creator", JOptionPane.INFORMATION_MESSAGE);
            }
            if (string.ReferenceEquals(max, null))
            {
                get_max = false;
            }

            if (get_channel)
            {
                channel = JOptionPane.showInputDialog(null, "Enter the 'channel' value: ", "1-Wire tag Creator", JOptionPane.INFORMATION_MESSAGE);
            }
            if (string.ReferenceEquals(channel, null))
            {
                get_channel = false;
            }

            if (get_init)
            {
                init = JOptionPane.showInputDialog(null, "Enter the 'init' value: ", "1-Wire tag Creator", JOptionPane.INFORMATION_MESSAGE);
            }
            if (string.ReferenceEquals(init, null))
            {
                get_init = false;
            }

            if (get_scale)
            {
                scale = JOptionPane.showInputDialog(null, "Enter the 'scale' value: ", "1-Wire tag Creator", JOptionPane.INFORMATION_MESSAGE);
            }
            if (string.ReferenceEquals(scale, null))
            {
                get_scale = false;
            }

            // build the XML file
            ArrayList xml = new ArrayList(5);
            xml.Add("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
            xml.Add("<cluster name=\"" + cluster + "\">");
            xml.Add(" <" + tag_type + " addr=\"" + tag_owd.AddressAsString + "\" type=\"" + method_type + "\">");
            xml.Add("  <label>" + label + "</label>");
            if (get_max)
            {
                xml.Add("  <max>" + max + "</max>");
            }
            if (get_min)
            {
                xml.Add("  <min>" + min + "</min>");
            }
            if (get_channel)
            {
                xml.Add("  <channel>" + channel + "</channel>");
            }
            if (get_init)
            {
                xml.Add("  <init>" + init + "</init>");
            }
            if (get_scale)
            {
                xml.Add("  <scale>" + scale + "</scale>");
            }
            xml.Add(" </" + tag_type + ">");
            xml.Add("</cluster>");

            // display the XML file
            JList list = new JList(xml.ToArray());
            if (MessageBox.Show(null, list, "Is this correct?", MessageBoxButtons.YesNo) != DialogResult.Yes)
            {
                throw new InterruptedException("Aborted");
            }

            // loop until file written
            bool file_written = false;
            do
            {
                // Check if doing desktop or 1-Wire file
                string[] file_types = new string[] { "Desktop File", "1-Wire File" };
                file_type = (string)JOptionPane.showInputDialog(null, "Select where to put this XML 1-Wire Tag file", "1-Wire tag Creator", JOptionPane.INFORMATION_MESSAGE, null, file_types, file_types[0]);
                if (string.ReferenceEquals(file_type, null))
                {
                    throw new InterruptedException("Aborted");
                }

                // save to a PC file
                if (string.ReferenceEquals(file_type, "Desktop File"))
                {
                    JFileChooser chooser   = new JFileChooser();
                    int          returnVal = chooser.showSaveDialog(null);
                    if (returnVal == JFileChooser.APPROVE_OPTION)
                    {
                        try
                        {
                            PrintWriter writer = new PrintWriter(new System.IO.FileStream(chooser.SelectedFile.CanonicalPath, true));
                            for (int i = 0; i < xml.Count; i++)
                            {
                                writer.println(xml[i]);
                            }
                            writer.flush();
                            writer.close();
                            JOptionPane.showMessageDialog(null, "XML File saved to: " + chooser.SelectedFile.CanonicalPath, "1-Wire Tag Creator", JOptionPane.INFORMATION_MESSAGE);
                            file_written = true;
                        }
                        catch (FileNotFoundException e)
                        {
                            Console.WriteLine(e);
                            JOptionPane.showMessageDialog(null, "ERROR saving XML File: " + chooser.SelectedFile.CanonicalPath, "1-Wire Tag Creator", JOptionPane.WARNING_MESSAGE);
                        }
                    }
                }
                // 1-Wire file
                else
                {
                    // search parts again in case the target device was just connected
                    owd_vect = findAllDevices(adapter);

                    // select the 1-Wire device to save the file to
                    tag_owd = selectDevice(owd_vect, "Select the 1-Wire Device to place XML Tag");

                    // attempt to write to the filesystem of this device
                    try
                    {
                        PrintWriter writer = new PrintWriter(new OWFileOutputStream(tag_owd, "TAGX.0"));
                        for (int i = 0; i < xml.Count; i++)
                        {
                            writer.println(xml[i]);
                        }
                        writer.flush();
                        writer.close();
                        JOptionPane.showMessageDialog(null, "XML File saved to: " + tag_owd.AddressAsString + "\\TAGX.000", "1-Wire Tag Creator", JOptionPane.INFORMATION_MESSAGE);
                        file_written = true;
                    }
                    catch (OWFileNotFoundException e)
                    {
                        Console.WriteLine(e);
                        JOptionPane.showMessageDialog(null, "ERROR saving XML File: " + tag_owd.AddressAsString + "\\TAGX.000", "1-Wire Tag Creator", JOptionPane.WARNING_MESSAGE);
                    }
                }

                // check if file not written
                if (!file_written)
                {
                    if (MessageBox.Show(null, "Try to save file again?", "1-Wire Tag Creator", MessageBoxButtons.OKCancel) != DialogResult.OK)
                    {
                        throw new InterruptedException("Aborted");
                    }
                }
            } while (!file_written);
        }
        catch (Exception e)
        {
            Console.WriteLine(e);
        }
        finally
        {
            if (adapter != null)
            {
                // end exclusive use of adapter
                adapter.endExclusive();

                // free the port used by the adapter
                Console.WriteLine("Releasing adapter port");
                try
                {
                    adapter.freePort();
                }
                catch (OneWireException e)
                {
                    Console.WriteLine(e);
                }
            }
        }

        Environment.Exit(0);
    }
Exemplo n.º 13
0
 /// <summary>
 /// Create a container with the provided adapter instance
 /// and the address of the iButton or 1-Wire device.<para>
 ///
 /// This is one of the methods to construct a container.  The other is
 /// through creating a OneWireContainer with NO parameters.
 ///
 /// </para>
 /// </summary>
 /// <param name="sourceAdapter">     adapter instance used to communicate with
 /// this 1-Wire device </param>
 /// <param name="newAddress">        <seealso cref="com.dalsemi.onewire.utils.Address Address"/>
 ///                            of this 1-Wire device
 /// </param>
 /// <seealso cref= #OneWireContainer27() OneWireContainer27 </seealso>
 /// <seealso cref= com.dalsemi.onewire.utils.Address utils.Address </seealso>
 public OneWireContainer27(DSPortAdapter sourceAdapter, string newAddress) : base(sourceAdapter, newAddress)
 {
 }