コード例 #1
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="cp"></param>
 internal static void ClearBind(CommuniPort cp)
 {
     if (cp.Station != null)
     {
         Unbind(cp.Station, cp);
     }
 }
コード例 #2
0
ファイル: CommuniPortState.cs プロジェクト: hkiaipc/c2
        public CommuniPortState(CommuniPort cp)
        {
            if (cp == null)
                throw new ArgumentNullException("cp");
            this._communiPort = cp;

            this.DT = DateTime.Now;
        }
コード例 #3
0
ファイル: HardwareManager.cs プロジェクト: hkiaipc/yh
 /// <summary>
 /// ����communiPort����Station, ���Ҳ�������null
 /// </summary>
 /// <param name="communiPort"></param>
 /// <returns></returns>
 public Station FindStation(CommuniPort communiPort)
 {
     foreach (Station st in this.Stations)
     {
         if (communiPort.Match(st.CommuniType))
         {
             return st;
         }
     }
     return null;
 }
コード例 #4
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="stations"></param>
        /// <param name="cp"></param>
        internal static bool Bind(StationCollection stations, CommuniPort cp)
        {
            if (stations == null)
                throw new ArgumentNullException("stations");

            if (cp == null)
                throw new ArgumentNullException("cp");

            if (cp is SocketCommuniPort)
            {
                return Bind(stations, cp as SocketCommuniPort);
            }
            return false;
        }
コード例 #5
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="st"></param>
        /// <param name="cp"></param>
        internal static void Unbind(Station st, CommuniPort cp)
        {
            if (st == null)
                throw new ArgumentNullException("st");
            if (cp == null)
                throw new ArgumentNullException("cp");

            if (st.CommuniPort == null && cp.Station == null)
                return;

            Debug.Assert(
                st.CommuniPort != null &&
                cp.Station != null &&
                st.CommuniPort == cp &&
                cp.Station == st,
                "Unbind(Station, CommuniPort) assert fail");

            st.CommuniPort = null;
            cp.Station = null;
        }
コード例 #6
0
ファイル: TaskManager.cs プロジェクト: hkiaipc/c2
        /// <summary>
        /// 
        /// </summary>
        /// <param name="checkedTasks"></param>
        /// <param name="task"></param>
        /// <param name="cp"></param>
        private bool ExecuteTask(Task task, CommuniPort cp)
        {
            // TODO: 2011-04-19
            // 1. executing task event before send bytes ?
            // 2. user define send bytes
            //
            // 2010-09-15
            //
            //OnExecuting(task);
            if (CommuniSoft.IsUseUISynchronizationContext)
            {
                CommuniSoft.UISynchronizationContext.Post(
                    this.ExecutingCallback,
                    task);
            }
            else
            {
                OnExecuting(task);
            }

            byte[] bytes = task.GetSendBytes();
            bool writeSuccess = cp.Write(bytes);

            if (writeSuccess)
            {
                // log send bytes: station - devicetype - bytes
                //
                LogSend(task, bytes);
                cp.Occupy(this.Timeout);
                task.LastExecute = DateTime.Now;
            }
            return writeSuccess;
        }
コード例 #7
0
ファイル: Events.cs プロジェクト: hkiaipc/c2
        /// <summary>
        /// 
        /// </summary>
        /// <param name="fromCommuniPort"></param>
        /// <param name="pr"></param>
        public FDEventArgs(CommuniPort fromCommuniPort, string deviceType, string operaName, ParseResult pr)
        {
            if (fromCommuniPort == null)
                throw new ArgumentNullException("fromCommuniPort");

            //if (opera == null)
                //throw new ArgumentNullException("opera");

            if (pr == null)
                throw new ArgumentNullException("pr");

            this._from = fromCommuniPort;
            this._pr = pr;
            this._deviceType = deviceType;
            this._operaName = operaName;
        }
コード例 #8
0
ファイル: Events.cs プロジェクト: hkiaipc/c2
        public CommuniPortReceivedEventArgs(CommuniPort cp, byte[] bytes)
        {
            if (cp == null)
                throw new ArgumentNullException("cp");
            this._communiPort = cp;

            this._receivedBytes = bytes;
        }
コード例 #9
0
ファイル: CommuniPortManager.cs プロジェクト: hkiaipc/c2
 /// <summary>
 /// 
 /// </summary>
 private void UnreginsterEvents( CommuniPort cp)
 {
     SocketCommuniPort sckcp = cp as SocketCommuniPort;
     sckcp.ClosedEvent -= new EventHandler(sckcp_ClosedEvent);
     sckcp.ReceivedEvent -= new EventHandler(sckcp_ReceivedEvent);
 }
コード例 #10
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="st"></param>
        /// <param name="cp"></param>
        private static bool Bind(Station st, CommuniPort cp)
        {
            if (st == null)
                throw new ArgumentNullException("st");
            if (cp == null)
                throw new ArgumentNullException("cp");

            Debug.Assert(st.CommuniPort == null &&
                cp.Station == null,
                "Bind fail, st.CommuniPort or cp.Station not null");

            //Unbind(st, cp);
            st.CommuniPort = cp;
            cp.Station = st;
            return true;
        }
コード例 #11
0
ファイル: CommuniPortManager.cs プロジェクト: hkiaipc/c2
 /// <summary>
 /// 
 /// </summary>
 private void RegisterEvents( CommuniPort cp )
 {
     SocketCommuniPort sckcp = cp as SocketCommuniPort;
     if (sckcp != null)
     {
         sckcp.ClosedEvent += new EventHandler(sckcp_ClosedEvent);
         sckcp.ReceivedEvent += new EventHandler(sckcp_ReceivedEvent);
     }
 }
コード例 #12
0
ファイル: CommuniPortManager.cs プロジェクト: hkiaipc/c2
 /// <summary>
 /// 
 /// </summary>
 /// <param name="cp"></param>
 private void OnCollectionChanged( ChangedType changedType, CommuniPort cp)
 {
     if (this.CollectionChanged != null)
     {
         CollectionChangedEventHandler temp = this.CollectionChanged;
         CollectionChangedEventArgs e = new CollectionChangedEventArgs(
             //ChangedType.Add,
             changedType,
             cp);
         temp(this, e);
     }
 }
コード例 #13
0
ファイル: CommuniPortManager.cs プロジェクト: hkiaipc/c2
 /// <summary>
 /// ɾ���������Ѿ����ڵģ���ͬԶ�̵�ַ��SocketCommuniPort
 /// </summary>
 /// <param name="cp"></param>
 private void BeforeAdd(CommuniPort cp)
 {
     // TODO: allow same ip address option
     //
     if (cp is SocketCommuniPort)
     {
         SocketCommuniPort scp = cp as SocketCommuniPort;
         for (int i = this.CommuniPorts.Count - 1; i >= 0; i--)
         {
             CommuniPort cp2 = this.CommuniPorts[i];
             if (cp2 is SocketCommuniPort)
             {
                 SocketCommuniPort scp2 = cp2 as SocketCommuniPort;
                 IPEndPoint ipep = scp.RemoteEndPoint as IPEndPoint;
                 IPEndPoint ipep2 = scp2.RemoteEndPoint as IPEndPoint;
                 if (ipep.Address.Equals(ipep2.Address))
                 {
                     Remove(cp2);
                 }
             }
         }
     }
 }
コード例 #14
0
ファイル: CommuniPortManager.cs プロジェクト: hkiaipc/c2
 /// <summary>
 /// 
 /// </summary>
 /// <param name="cp"></param>
 public bool Remove(CommuniPort cp)
 {
     if (this.CommuniPorts.Remove(cp))
     {
         UnreginsterEvents(cp);
         OnCollectionChanged(ChangedType.Remove, cp);
         return true;
     }
     return false;
 }
コード例 #15
0
ファイル: CommuniPortManager.cs プロジェクト: hkiaipc/c2
 /// <summary>
 /// 
 /// </summary>
 /// <param name="cp"></param>
 public void Add(CommuniPort cp)
 {
     BeforeAdd(cp);
     this.CommuniPorts.Add(cp);
     RegisterEvents(cp);
     OnCollectionChanged( ChangedType.Add, cp);
 }