Exemple #1
0
            /// <summary>
            /// Open the underlying PortType associated with an ActivePort and prepare it for communications.
            /// </summary>
            /// <param name="name">ActivePort name</param>
            public static void Open(string name)
            {
                if (string.IsNullOrEmpty(name))
                {
                    throw new ArgumentNullException("name", "A valid ActivePort name must be provided.");
                }
                if (!manager.activePorts.ContainsKey(name))
                {
                    throw new InvalidOperationException("An ActivePort must first be created.");
                }
                if (manager.activePorts[name].State != PortState.Created)
                {
                    throw new InvalidOperationException("The port cannot be opened. It is not in the Created state.");
                }

                if (manager.activePorts[name].State == PortState.Created)
                {
                    qf4net.QF.Instance.Publish(new PortEvent(QFSignal.PortOpen, name));
                    ActivePort aPort = manager.activePorts[name];
                    while ((!aPort.IsInState(aPort.m_StateFaulted)) && (!aPort.IsInState(aPort.m_StateOpened)))
                    {
                        System.Threading.Thread.Sleep(1);
                    }

                    if (!aPort.IsInState(aPort.m_StateOpened))
                    {
                        throw new InvalidOperationException("The ActivePort '" + name + "' could not be opened. Please check the log for details.");
                    }
                }
            }
Exemple #2
0
            /// <summary>
            /// Creates an ActivePort within the TQF using an existing Port device
            /// </summary>
            /// <param name="port">An existing Port device</param>
            public static void Create(IPort port)
            {
                if (port == null)
                {
                    throw new ArgumentNullException("port", "A valid port must be provided.");
                }
                if ((string.IsNullOrEmpty(port.Name) || manager.activePorts.ContainsKey(port.Name)))
                {
                    throw new ArgumentNullException("port.Name", "An ActivePort must have a valid, unique name.");
                }

                manager.activePorts.Add(port.Name, new ActivePort(port));
                manager.activePorts[port.Name].Start(manager.priority++);

                ActivePort aPort = manager.activePorts[port.Name];

                while ((!aPort.IsInState(aPort.m_StateFaulted)) && (!aPort.IsInState(aPort.m_StateCreated)))
                {
                    System.Threading.Thread.Sleep(1);
                }
            }
Exemple #3
0
            /// <summary>
            /// Close the underlying PortType associated with an ActivePort and teardown communications.
            /// </summary>
            /// <param name="name">ActivePort name</param>
            public static void Close(string name)
            {
                if (string.IsNullOrEmpty(name))
                {
                    throw new ArgumentNullException("name", "A valid ActivePort name must be provided.");
                }
                if (!manager.activePorts.ContainsKey(name))
                {
                    throw new InvalidOperationException("An ActivePort must first be created.");
                }

                qf4net.QF.Instance.Publish(new PortEvent(QFSignal.PortClose, name));

                ActivePort aPort = manager.activePorts[name];

                while ((!aPort.IsInState(aPort.m_StateFaulted)) && (!aPort.IsInState(aPort.m_StateClosed)))
                {
                    System.Threading.Thread.Sleep(1);
                }
                manager.activePorts[name].Dispose();
                manager.activePorts.Remove(name);
            }