Exemplo n.º 1
0
        public static void UT()
        {
            switchQueue = new SwitchContainer <TestData>(firstQueue, secondQueue);

            int getCount = 5;

            Thread[] tGetData = new Thread[getCount];
            for (int indexGet = 0; indexGet < getCount; ++indexGet)
            {
                tGetData[indexGet] = new Thread(GetData);
                tGetData[indexGet].IsBackground = true;
                tGetData[indexGet].Name         = "GetData#" + indexGet;
            }

            Thread tInsertData = new Thread(InsertData);

            tInsertData.IsBackground = true;
            tInsertData.Name         = "InsertData";

            tInsertData.Start();
            for (int indexGet = 0; indexGet < getCount; ++indexGet)
            {
                tGetData[indexGet].Start();
            }

            Console.ReadKey();
        }
Exemplo n.º 2
0
        // Selections for the Switch actuator:
        // element 0 -> Means "disconnected" or "open circuit" (init = 0) and is
        //              associated with the "min" message.
        // element 1 -> Means "connect" or "close the circuit", (init = 1) and is
        //              associated with the "max" message.

        /// <summary>
        /// Initializes the actuator </summary>
        /// <param name="Init"> The initialization string.
        /// </param>
        /// <exception cref="OneWireException">
        ///  </exception>
        public virtual void initActuator()
        {
            SwitchContainer switchcontainer = DeviceContainer as SwitchContainer;

            // initialize the ActuatorSelections Vector
            ActuatorSelections.Add(Min); // for switch, use min and max
            ActuatorSelections.Add(Max);
            // Now, initialize the switch to the desired condition.
            // This condition is in the <init> tag and, of course, the
            // <channel> tag is also needed to know which channel to
            // to open or close.
            int channelValue;
            int switchStateIntValue = 0;
            int initValue           = Int32.Parse(Init);

            channelValue = Channel;

            byte[] state        = switchcontainer.readDevice();
            bool   switch_state = switchcontainer.getLatchState(channelValue, state);

            if (switch_state)
            {
                switchStateIntValue = 1;
            }
            else
            {
                switchStateIntValue = 0;
            }
            if (initValue != switchStateIntValue)
            {
                // set the switch's state to the value specified in XML file
                switchcontainer.setLatchState(channelValue, !switch_state, false, state);
                switchcontainer.writeDevice(state);
            }
        }
        protected override void UpdateState()
        {
            Action = incompatible.Value ? () => { } : (Action)Active.Toggle;

            if (incompatible.Value)
            {
                Colour4 backgroundColour     = ColourProvider.Background5;
                Colour4 textBackgroundColour = ColourProvider.Background4;

                Content.TransformTo(nameof(BorderColour), ColourInfo.GradientVertical(backgroundColour, textBackgroundColour), TRANSITION_DURATION, Easing.OutQuint);
                Background.FadeColour(backgroundColour, TRANSITION_DURATION, Easing.OutQuint);

                SwitchContainer.ResizeWidthTo(IDLE_SWITCH_WIDTH, TRANSITION_DURATION, Easing.OutQuint);
                SwitchContainer.FadeColour(Colour4.Gray, TRANSITION_DURATION, Easing.OutQuint);
                MainContentContainer.TransformTo(nameof(Padding), new MarginPadding
                {
                    Left  = IDLE_SWITCH_WIDTH,
                    Right = CORNER_RADIUS
                }, TRANSITION_DURATION, Easing.OutQuint);

                TextBackground.FadeColour(textBackgroundColour, TRANSITION_DURATION, Easing.OutQuint);
                TextFlow.FadeColour(Colour4.White.Opacity(0.5f), TRANSITION_DURATION, Easing.OutQuint);
                return;
            }

            SwitchContainer.FadeColour(Colour4.White, TRANSITION_DURATION, Easing.OutQuint);
            base.UpdateState();
        }
Exemplo n.º 4
0
    /// <summary>
    /// Display information about the Switch device
    /// </summary>
    /// <param name="owd"> OneWireContainer device </param>
    internal static void printSwitchInfo(SwitchContainer swd)
    {
        try
        {
            byte[] state = swd.readDevice();

            Debug.WriteLine("");
            Debug.WriteLine("-----------------------------------------------------------------------");
            Debug.WriteLine("| Number of channels: " + swd.getNumberChannels(state));
            Debug.WriteLine("| Is high-side switch: " + swd.HighSideSwitch);
            Debug.WriteLine("| Has Activity Sensing: " + swd.hasActivitySensing());
            Debug.WriteLine("| Has Level Sensing: " + swd.hasLevelSensing());
            Debug.WriteLine("| Has Smart-on: " + swd.hasSmartOn());
            Debug.WriteLine("| Only 1 channel on at a time: " + swd.onlySingleChannelOn());
            Debug.WriteLine("");

            Debug.Write("    Channel          ");
            for (int ch = 0; ch < swd.getNumberChannels(state); ch++)
            {
                Debug.Write(ch + "      ");
            }
            Debug.WriteLine("");

            Debug.WriteLine("    -----------------------------------");

            Debug.Write("    Latch State      ");
            for (int ch = 0; ch < swd.getNumberChannels(state); ch++)
            {
                Debug.Write(((swd.getLatchState(ch, state) == true) ? "ON     " : "OFF    "));
            }
            Debug.WriteLine("");

            if (swd.hasLevelSensing())
            {
                Debug.Write("    Sensed Level     ");
                for (int ch = 0; ch < swd.getNumberChannels(state); ch++)
                {
                    Debug.Write(((swd.getLevel(ch, state) == true) ? "HIGH   " : "LOW    "));
                }
                Debug.WriteLine("");
            }

            if (swd.hasActivitySensing())
            {
                Debug.Write("    Sensed Activity  ");
                for (int ch = 0; ch < swd.getNumberChannels(state); ch++)
                {
                    Debug.Write(((swd.getSensedActivity(ch, state) == true) ? "SET    " : "CLEAR  "));
                }
                Debug.WriteLine("");
            }
        }
        catch (OneWireIOException e)
        {
            Debug.WriteLine(e);
        }
    }
Exemplo n.º 5
0
        public static SwitchContainer ParseSwitchContainer(byte[] data)
        {
            using (var reader = new BinaryReader(new MemoryStream(data)))
            {
                var switchContainer = new SwitchContainer(data.Length);
                switchContainer.Id                     = reader.ReadUInt32();
                switchContainer.Properties             = reader.ReadAudioProperties();
                switchContainer.SwitchType             = (SwitchType)reader.ReadByte();
                switchContainer.GroupId                = reader.ReadUInt32();
                switchContainer.DefaultSwitchOrStateId = reader.ReadUInt32();
                switchContainer.Mode                   = (PlayMode)reader.ReadByte();
                switchContainer.AssignedChildCount     = reader.ReadUInt32();
                switchContainer.AssignedChildIds       = new uint[switchContainer.AssignedChildCount];
                for (var i = 0; i < switchContainer.AssignedChildCount; i++)
                {
                    switchContainer.AssignedChildIds[i] = reader.ReadUInt32();
                }
                switchContainer.SwitchOrStateCount = reader.ReadUInt32();
                switchContainer.SwitchOrStates     = new SwitchOrState[switchContainer.SwitchOrStateCount];
                for (var i = 0; i < switchContainer.SwitchOrStateCount; i++)
                {
                    SwitchOrState switchOrState = default;
                    switchOrState.Id = reader.ReadUInt32();
                    switchOrState.AssignedChildCount = reader.ReadUInt32();
                    switchOrState.AssignedChildIds   = new uint[switchOrState.AssignedChildCount];
                    for (var j = 0; j < switchOrState.AssignedChildCount; j++)
                    {
                        switchOrState.AssignedChildIds[j] = reader.ReadUInt32();
                    }
                    switchContainer.SwitchOrStates[i] = switchOrState;
                }
                switchContainer.ChildCount = reader.ReadUInt32();
                switchContainer.Children   = new SwitchChild[switchContainer.ChildCount];
                for (var i = 0; i < switchContainer.ChildCount; i++)
                {
                    SwitchChild switchChild = default;
                    switchChild.Id              = reader.ReadUInt32();
                    switchChild.Behavior        = (PlayBehavior)reader.ReadByte();
                    switchChild.Unknown         = reader.ReadByte();
                    switchChild.FadeOut         = reader.ReadUInt32();
                    switchChild.FadeIn          = reader.ReadUInt32();
                    switchContainer.Children[i] = switchChild;
                }

                return(switchContainer);
            }
        }
Exemplo n.º 6
0
        public static void UTDataWorker()
        {
            switchQueue = new SwitchContainer<TestData>(firstQueue, secondQueue);
            dataWorker = new ThreadPoolDataDispatcher<TestData>(10,switchQueue);

            dataWorker.OnDataIn += new Action<TestData>(dataWorker_OnDataIn);

            Thread tInsertData = new Thread(InsertDataForWorker);
            tInsertData.IsBackground = true;
            tInsertData.Name = "InsertDataForWorker";
            tInsertData.Start();

            dataWorker.Start( true );

            Console.ReadKey();

            dataWorker.Stop();
        }
Exemplo n.º 7
0
        public static void UTDataWorker()
        {
            switchQueue = new SwitchContainer <TestData>(firstQueue, secondQueue);
            dataWorker  = new ThreadPoolDataDispatcher <TestData>(10, switchQueue);

            dataWorker.OnDataIn += new Action <TestData>(dataWorker_OnDataIn);

            Thread tInsertData = new Thread(InsertDataForWorker);

            tInsertData.IsBackground = true;
            tInsertData.Name         = "InsertDataForWorker";
            tInsertData.Start();

            dataWorker.Start(true);

            Console.ReadKey();

            dataWorker.Stop();
        }
Exemplo n.º 8
0
            private IClipContainer CreateContainer(string containerId, SampleContainerChildType childType)
            {
                switch (childType)
                {
                case SampleContainerChildType.Random:
                {
                    RandomContainer randomContainer = new RandomContainer();
                    randomContainer.id = containerId;
                    return(randomContainer);
                }

                case SampleContainerChildType.Choice:
                {
                    SwitchContainer switchContainer = new SwitchContainer();
                    switchContainer.id = containerId;
                    return(switchContainer);
                }

                case SampleContainerChildType.Start:
                case SampleContainerChildType.Loop:
                case SampleContainerChildType.Stop:
                {
                    LoopContainer loopContainer = new LoopContainer();
                    loopContainer.id = containerId;
                    return(loopContainer);
                }

                case SampleContainerChildType.None:
                {
                    RandomContainer randomContainer = new RandomContainer();
                    randomContainer.id = containerId;
                    return(randomContainer);
                }

                default:
                    throw new InvalidOperationException();
                }
            }
Exemplo n.º 9
0
        public static void UT()
        {
            switchQueue = new SwitchContainer<TestData>(firstQueue,secondQueue);

            int getCount = 5;
            Thread[] tGetData = new Thread[getCount];
            for( int indexGet = 0; indexGet < getCount; ++indexGet )
            {
                tGetData[indexGet] = new Thread(GetData);
                tGetData[indexGet].IsBackground = true;
                tGetData[indexGet].Name = "GetData#"+indexGet;
            }

            Thread tInsertData = new Thread(InsertData);
            tInsertData.IsBackground = true;
            tInsertData.Name = "InsertData";

            tInsertData.Start();
            for (int indexGet = 0; indexGet < getCount; ++indexGet)
                tGetData[indexGet].Start();

            Console.ReadKey();
        }
        /// <summary>
        /// Performs a search of the 1-Wire network, with branch searching
        /// </summary>
        /// <param name="arrivals"> A vector of Long objects, represent new arrival addresses. </param>
        /// <param name="departures"> A vector of Long objects, represent departed addresses. </param>
        public override void search(List <long> arrivals, List <long> departures)
        {
            lock (sync_flag)
            {
                try
                {
                    // aquire the adapter
                    adapter.beginExclusive(true);

                    // setup the search
                    adapter.setSearchAllDevices();
                    adapter.targetAllFamilies();
                    adapter.Speed = DSPortAdapter.SPEED_REGULAR;

                    // close any opened branches
                    for (int j = 0; j < paths.Count; j++)
                    {
                        try
                        {
                            ((OWPath)paths[j]).close();
                        }
                        catch (System.Exception)
                        {
                            ;
                        }
                    }

                    // search through all of the paths
                    for (int i = 0; i < paths.Count; i++)
                    {
                        // set searches to not use reset
                        adapter.setNoResetSearch();

                        // find the first device on this branch
                        bool   search_result = false;
                        OWPath path          = (OWPath)paths[i];
                        try
                        {
                            // try to open the current path
                            path.open();
                        }
                        catch (System.Exception)
                        {
                            // if opening the path failed, continue on to the next path
                            continue;
                        }

                        search_result = adapter.findFirstDevice();

                        // loop while devices found
                        while (search_result)
                        {
                            // get the 1-Wire address
                            long longAddress = adapter.AddressAsLong;
                            // check if the device allready exists in our hashtable
                            if (!deviceAddressHash.ContainsKey(longAddress))
                            {
                                OneWireContainer owc = getDeviceContainer(adapter, longAddress);
                                // check to see if it's a switch and if we are supposed
                                // to automatically search down branches
                                if (this.branchAutoSearching && (owc is SwitchContainer))
                                {
                                    SwitchContainer sc    = (SwitchContainer)owc;
                                    byte[]          state = sc.readDevice();
                                    for (int j = 0; j < sc.getNumberChannels(state); j++)
                                    {
                                        OWPath tmp = new OWPath(adapter, path);
                                        tmp.add(owc, j);
                                        if (!paths.Contains(tmp))
                                        {
                                            paths.Add(tmp);
                                        }
                                    }
                                }

                                lock (devicePathHash)
                                {
                                    devicePathHash[longAddress] = path;
                                }
                                if (arrivals != null)
                                {
                                    arrivals.Add(longAddress);
                                }
                            }
                            // check if the existing device moved
                            else if (!path.Equals(devicePathHash[longAddress]))
                            {
                                lock (devicePathHash)
                                {
                                    devicePathHash[longAddress] = path;
                                }
                                if (departures != null)
                                {
                                    departures.Add(longAddress);
                                }
                                if (arrivals != null)
                                {
                                    arrivals.Add(longAddress);
                                }
                            }

                            // update count
                            deviceAddressHash[longAddress] = max_state_count;

                            // find the next device on this branch
                            path.open();
                            search_result = adapter.findNextDevice();
                        }
                    }
                }
                finally
                {
                    adapter.endExclusive();
                }

                // remove any devices that have not been seen
                foreach (var address in deviceAddressHash.Keys.Where(kv => deviceAddressHash[kv] <= 0).ToList())
                {
                    // device entry is stale, should be removed
                    deviceAddressHash.Remove(address);
                    if (departures != null)
                    {
                        departures.Add(address);
                    }
                }

                foreach (var address in deviceAddressHash.Keys.Where(kv => deviceAddressHash[kv] > 0).ToList())
                {
                    // device entry isn't stale, it stays
                    deviceAddressHash[address] -= 1;
                }

                // fire notification events
                if (departures != null && departures.Count > 0)
                {
                    fireDepartureEvent(adapter, departures);
                }
                if (arrivals != null && arrivals.Count > 0)
                {
                    fireArrivalEvent(adapter, arrivals);
                }
            }
        }
 protected override void UpdateState()
 {
     base.UpdateState();
     SwitchContainer.FadeColour(incompatible.Value ? Colour4.Gray : Colour4.White, TRANSITION_DURATION, Easing.OutQuint);
 }
Exemplo n.º 12
0
        public HIRCObject(BNK mainBnk, BinaryReader br)
        {
            Bnk = mainBnk;
            if (!hircError.errorOccured)
            {
                int type = br.ReadByte();
                LastPos = br.BaseStream.Position;
                switch (type)
                {
                case 1:
                    SettingsObject = new Settings(br, type);
                    break;

                case 2:
                    SoundSFXObject = new SoundSFX(this, br, type);
                    break;

                case 3:
                    EventAction = new EventAction(this, br, type);
                    break;

                case 4:
                    Event = new Event(this, br, type);
                    break;

                case 5:
                    RandomContainer = new RandomContainer(this, br, type);
                    break;

                case 6:
                    SwitchContainer = new SwitchContainer(this, br, type);
                    break;

                case 7:
                    ActorMixer = new ActorMixer(this, br, type);
                    break;

                case 8:
                    AudioBus = new AudioBus(this, br, type);
                    break;

                case 9:
                    BlendContainer = new BlendContainer(this, br, type);
                    break;

                case 10:
                    MusicSegment = new MusicSegment(this, br, type);
                    break;

                case 11:
                    MusicTrack = new MusicTrack(this, br, type);
                    break;

                case 12:
                    MusicSwitchContainer = new MusicSwitchContainer(this, br, type);
                    break;

                case 13:
                    MusicSequence = new MusicSequence(this, br, type);
                    break;

                case 14:
                    Attenuation = new Attenuation(br, type);
                    break;

                case 16:
                    FeedbackBus = new FeedbackBus(this, br, type);
                    break;

                case 17:
                    FeedbackNode = new FeedbackNode(this, br, type);
                    break;

                case 18:
                    FxShareSet = new FxShareSet(this, br, type);
                    break;

                case 19:
                    FxCustom = new FxCustom(this, br, type);
                    break;

                case 20:
                    AuxiliaryBus = new AuxiliaryBus(this, br, type);
                    break;

                case 21:
                    LFO = new LFO(br, type);
                    break;

                case 22:
                    Envelope = new Envelope(br, type);
                    break;

                default:
                    int length = br.ReadInt32();
                    br.BaseStream.Position -= 5;
                    Data = br.ReadBytes(length + 5);
                    System.Windows.MessageBox.Show("Detected unkown HIRC Object type at: " + (LastPos - 1).ToString("X"), "Toolkit");
                    break;
                }
            }
        }
Exemplo n.º 13
0
        public int GetLength()
        {
            int length = 5;

            if (SettingsObject != null)
            {
                length += SettingsObject.GetLength();
            }
            else if (SoundSFXObject != null)
            {
                length += SoundSFXObject.GetLength();
            }
            else if (EventAction != null)
            {
                length += EventAction.GetLength();
            }
            else if (Event != null)
            {
                length += Event.GetLength();
            }
            else if (RandomContainer != null)
            {
                length += RandomContainer.GetLength();
            }
            else if (SwitchContainer != null)
            {
                length += SwitchContainer.GetLength();
            }
            else if (ActorMixer != null)
            {
                length += ActorMixer.GetLength();
            }
            else if (AudioBus != null)
            {
                length += AudioBus.GetLength();
            }
            else if (BlendContainer != null)
            {
                length += BlendContainer.GetLength();
            }
            else if (MusicSegment != null)
            {
                length += MusicSegment.GetLength();
            }
            else if (MusicTrack != null)
            {
                length += MusicTrack.GetLength();
            }
            else if (MusicSwitchContainer != null)
            {
                length += MusicSwitchContainer.GetLength();
            }
            else if (MusicSequence != null)
            {
                length += MusicSequence.GetLength();
            }
            else if (Attenuation != null)
            {
                length += Attenuation.GetLength();
            }
            else if (FeedbackNode != null)
            {
                length += FeedbackNode.GetLength();
            }
            else if (FxShareSet != null)
            {
                length += FxShareSet.GetLength();
            }
            else if (FxCustom != null)
            {
                length += FxCustom.GetLength();
            }
            else if (AuxiliaryBus != null)
            {
                length += AuxiliaryBus.GetLength();
            }
            else if (LFO != null)
            {
                length += LFO.GetLength();
            }
            else if (Envelope != null)
            {
                length += Envelope.GetLength();
            }
            else if (FeedbackBus != null)
            {
                length += FeedbackBus.GetLength();
            }
            else
            {
                if (Data != null)
                {
                    length += Data.Length;
                }
                else
                {
                    length = -1;
                }
            }

            return(length);
        }
Exemplo n.º 14
0
    /// <summary>
    /// Main for 1-Wire Memory utility
    /// </summary>
    public static void Main1(string[] args)
    {
        List <OneWireContainer> owd_vect = new List <OneWireContainer>(5);
        SwitchContainer         sw       = null;
        int           ch;
        bool          done    = false;
        DSPortAdapter adapter = null;

        byte[] state;

        Stream stream = loadResourceFile("Switch.input.txt");

        dis = new StreamReader(stream);

        Debug.WriteLine("");
        Debug.WriteLine("1-Wire Switch utility console application: Version 0.00");
        Debug.WriteLine("");

        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);

            // force first select device
            int main_selection = MAIN_SELECT_DEVICE;

            // loop to do menu
            do
            {
                // Main menu
                switch (main_selection)
                {
                case MAIN_DISPLAY_INFO:
                    // display Switch info
                    printSwitchInfo(sw);
                    break;

                case MAIN_CLEAR_ACTIVITY:
                    sw.clearActivity();
                    state = sw.readDevice();
                    sw.writeDevice(state);
                    // display Switch info
                    printSwitchInfo(sw);
                    break;

                case MAIN_SET_LATCH:
                    state = sw.readDevice();
                    Debug.Write("Enter the channel number: ");
                    ch = getNumber(0, sw.getNumberChannels(state) - 1);
                    if (menuSelect(stateMenu) == STATE_ON)
                    {
                        sw.setLatchState(ch, true, false, state);
                    }
                    else
                    {
                        sw.setLatchState(ch, false, false, state);
                    }
                    sw.writeDevice(state);
                    // display Switch info
                    printSwitchInfo(sw);
                    break;

                case MAIN_SELECT_DEVICE:
                    // find all parts
                    owd_vect = findAllSwitchDevices(adapter);
                    // select a device
                    sw = (SwitchContainer)selectDevice(owd_vect);
                    // display device info
                    printDeviceInfo((OneWireContainer)sw);
                    // display the switch info
                    printSwitchInfo(sw);
                    break;

                case MAIN_QUIT:
                    done = true;
                    break;
                }

                if (!done)
                {
                    main_selection = menuSelect(mainMenu);
                }
            } while (!done);
        }
        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;
    }
Exemplo n.º 15
0
    /// <summary>
    /// Method main
    ///
    /// </summary>
    /// <param name="args">
    /// </param>
    /// <exception cref="OneWireException"> </exception>
    /// <exception cref="OneWireIOException">
    ///  </exception>
    public static void Main1(string[] args)
    {
        bool          usedefault   = false;
        DSPortAdapter access       = null;
        string        adapter_name = null;
        string        port_name    = null;

        if ((args == null) || (args.Length < 1))
        {
            try
            {
                access = OneWireAccessProvider.DefaultAdapter;

                if (access == null)
                {
                    throw new Exception();
                }
            }
            catch (Exception)
            {
                Debug.WriteLine("Couldn't get default adapter!");
                printUsageString();

                return;
            }

            usedefault = true;
        }

        if (!usedefault)
        {
            string[] st = args[0].Split(new char[] { '_' });


            if (st.Length != 2)
            {
                printUsageString();

                return;
            }

            adapter_name = st[0];
            port_name    = st[1];

            Debug.WriteLine("Adapter Name: " + adapter_name);
            Debug.WriteLine("Port Name: " + port_name);
        }

        if (access == null)
        {
            try
            {
                access = OneWireAccessProvider.getAdapter(adapter_name, port_name);
            }
            catch (Exception)
            {
                Debug.WriteLine("That is not a valid adapter/port combination.");

                System.Collections.IEnumerator en = OneWireAccessProvider.enumerateAllAdapters();

                while (en.MoveNext())
                {
                    DSPortAdapter temp = (DSPortAdapter)en.Current;

                    Debug.WriteLine("Adapter: " + temp.AdapterName);

                    System.Collections.IEnumerator f = temp.PortNames;

                    while (f.MoveNext())
                    {
                        Debug.WriteLine("   Port name : " + ((string)f.Current));
                    }
                }

                return;
            }
        }

        access.adapterDetected();
        access.targetAllFamilies();
        access.beginExclusive(true);
        access.reset();
        access.setSearchAllDevices();

        bool next = access.findFirstDevice();

        if (!next)
        {
            Debug.WriteLine("Could not find any iButtons!");

            return;
        }

        while (next)
        {
            OneWireContainer owc = access.DeviceContainer;

            Debug.WriteLine("====================================================");
            Debug.WriteLine("= Found One Wire Device: " + owc.AddressAsString + "          =");
            Debug.WriteLine("====================================================");
            Debug.WriteLine("=");

            bool            isSwitchContainer = false;
            SwitchContainer sc = null;

            try
            {
                sc = (SwitchContainer)owc;
                isSwitchContainer = true;
            }
            catch (InvalidCastException)
            {
                sc = null;
                isSwitchContainer = false;         //just to reiterate
            }

            if (isSwitchContainer)
            {
                Debug.WriteLine("= This device is a " + owc.Name);
                Debug.WriteLine("= Also known as a " + owc.AlternateNames);
                Debug.WriteLine("=");
                Debug.WriteLine("= It is a Switch Container");
                if (sc.hasActivitySensing())
                {
                    sc.clearActivity();
                }

                byte[] state    = sc.readDevice();
                int    channels = sc.getNumberChannels(state);
                bool   activity = sc.hasActivitySensing();
                bool   level    = sc.hasLevelSensing();
                bool   smart    = sc.hasSmartOn();

                Debug.WriteLine("= This device has " + channels + " channel" + (channels > 1 ? "s" : ""));
                Debug.WriteLine("= It " + (activity ? "has" : "does not have") + " activity sensing abilities");
                Debug.WriteLine("= It " + (level ? "has" : "does not have") + " level sensing abilities");
                Debug.WriteLine("= It " + (smart ? "is" : "is not") + " smart-on capable");

                for (int ch = 0; ch < channels; ch++)
                {
                    Debug.WriteLine("======================");
                    Debug.WriteLine("=   Channel " + ch + "        =");
                    Debug.WriteLine("=--------------------=");

                    bool latchstate = sc.getLatchState(ch, state);

                    Debug.WriteLine("= State " + (latchstate ? "ON " : "OFF") + "          =");

                    if (level)
                    {
                        bool sensedLevel = sc.getLevel(ch, state);

                        Debug.WriteLine("= Level " + (sensedLevel ? "HIGH" : "LOW ") + "         =");
                    }

                    if (activity)
                    {
                        bool sensedActivity = sc.getSensedActivity(ch, state);

                        Debug.WriteLine("= Activity " + (sensedActivity ? "YES" : "NO ") + "       =");
                    }

                    Debug.WriteLine("= Toggling switch... =");

                    try
                    {
                        Thread.Sleep(500);
                    }
                    catch (Exception)
                    {
                        /*drain it*/
                    }

                    sc.setLatchState(ch, !latchstate, smart, state);
                    sc.writeDevice(state);

                    state = sc.readDevice();

                    if (latchstate == sc.getLatchState(ch, state))
                    {
                        Debug.WriteLine("= Toggle Failed      =");
                    }
                    else
                    {
                        try
                        {
                            Thread.Sleep(500);
                        }
                        catch (Exception)
                        {
                            /*drain it*/
                        }

                        Debug.WriteLine("= Toggling back...   =");
                        sc.setLatchState(ch, latchstate, smart, state);
                        sc.writeDevice(state);
                    }
                }
            }
            else
            {
                Debug.WriteLine("= This device is not a Switch device.");
                Debug.WriteLine("=");
                Debug.WriteLine("=");
            }

            next = access.findNextDevice();
        }
    }