Esempio n. 1
0
 /// <summary>
 /// 数据接收
 /// </summary>
 /// <param name="handler"></param>
 internal void onDataReceived(DtuMsg buffer)
 {
     if (this.handler != null)
     {
         this.handler.OnDataReceived(buffer);
     }
 }
Esempio n. 2
0
        /// <summary>
        /// 接收数据
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        static void server_ReceiveData(object sender, ZYBEventArgs e)
        {
            string     dtuid = e.DTU.ID;
            Connection c     = (Connection)_connectPool[dtuid];

            c.RefreshTime = e.DTU.RefreshTime;
            DtuMsg m = EventToMsg(e);

            m.IsWorking = true;
            c.onDataReceived(m); // passthrough
        }
Esempio n. 3
0
        private static DtuMsg EventToMsg(ZYBEventArgs e)
        {
            DtuMsg m = new DtuMsg
            {
                DtuId       = e.DTU.ID,
                IsOnline    = e.DTU.IsOnline,
                Logintime   = e.DTU.LoginTime,
                Refreshtime = e.DTU.RefreshTime,
                Databuffer  = e.DTU.DataByte
            };

            return(m);
        }
Esempio n. 4
0
 public void DoWork()
 {
     this.c1 = ServerManager.GetConnection(this.dtuid);
     // sync.
     byte[] toSend = System.Text.Encoding.UTF8.GetBytes(string.Format("Hello from {0}", this.name));
     Console.Write("[{0}]: synchronized sending...", this.name);
     if (this.c1 != null && this.c1.IsAvaliable())
     {
         DtuMsg received = this.c1.Ssend(toSend, 2);
         Console.WriteLine(" Received: {0}", received == null ? "null" : System.Text.Encoding.Default.GetString(received.Databuffer));
     }
     else
     {
         Console.WriteLine("DTU Not Ready");
     }
 }
Esempio n. 5
0
        /// <summary>
        /// Connect, 注册服务.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        static void server_ClientConnect(object sender, ZYBEventArgs e)
        {
            Connection c = registerConnection(e.DTU.ID, e.DTU.IP, e.DTU.PhoneNumber);

            c.IsOnline    = e.DTU.IsOnline;
            c.PhoneNumber = e.DTU.PhoneNumber;
            c.LoginTime   = e.DTU.LoginTime;
            c.RefreshTime = e.DTU.RefreshTime;
            c.SetReady(true);
            DtuMsg m = EventToMsg(e);

            m.IsWorking = false;
            c.onDataReceived(m);
            fireConnectionStatusChanged(c, WorkingStatus.NA, WorkingStatus.IDLE);
            Console.WriteLine(string.Format("Connection online: {0},{1}({2}) on {3}", c.DtuID, c.IP, c.PhoneNumber, c.LoginTime));
        }
Esempio n. 6
0
        static void server_ClientClose(object sender, ZYBEventArgs e)
        {
            string dtuId = e.DTU.ID;

            if (!_connectPool.Contains(dtuId))
            {
                // DTU Not registered? system error.
                //log.Fatal(string.Format("System error, DTU '{0}' Not registered!!!", dtuId));
                return;
            }
            var    c = (Connection)_connectPool[dtuId];
            DtuMsg m = EventToMsg(e);

            m.IsWorking = false;
            c.onDataReceived(m);
            c.SetReady(false);
            fireConnectionStatusChanged(c, WorkingStatus.IDLE, WorkingStatus.NA);
            Console.WriteLine("Client closed.");
        }
Esempio n. 7
0
 public void OnDataReceived(DtuMsg buffer)
 {
     Console.WriteLine("Received: {0}", buffer.DtuId);
 }
Esempio n. 8
0
 public void OnDataReceived(DtuMsg msg)
 {
     log.Debug("Data received in MessageWorker");
     this.dataReceived = true;
     this.receivedMsg  = msg;
 }