/// <summary> /// /// </summary> /// <param name="cp"></param> internal static void ClearBind(CommuniPort cp) { if (cp.Station != null) { Unbind(cp.Station, cp); } }
public CommuniPortState(CommuniPort cp) { if (cp == null) throw new ArgumentNullException("cp"); this._communiPort = cp; this.DT = DateTime.Now; }
/// <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; }
/// <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; }
/// <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; }
/// <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; }
/// <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; }
public CommuniPortReceivedEventArgs(CommuniPort cp, byte[] bytes) { if (cp == null) throw new ArgumentNullException("cp"); this._communiPort = cp; this._receivedBytes = bytes; }
/// <summary> /// /// </summary> private void UnreginsterEvents( CommuniPort cp) { SocketCommuniPort sckcp = cp as SocketCommuniPort; sckcp.ClosedEvent -= new EventHandler(sckcp_ClosedEvent); sckcp.ReceivedEvent -= new EventHandler(sckcp_ReceivedEvent); }
/// <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; }
/// <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); } }
/// <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); } }
/// <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); } } } } }
/// <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; }
/// <summary> /// /// </summary> /// <param name="cp"></param> public void Add(CommuniPort cp) { BeforeAdd(cp); this.CommuniPorts.Add(cp); RegisterEvents(cp); OnCollectionChanged( ChangedType.Add, cp); }