Exemplo n.º 1
0
        void Timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            System.Timers.Timer t = (System.Timers.Timer)sender;
            t.Enabled = false;
            IDictionaryEnumerator enumerator = this.Sokcets.GetEnumerator();

            Config.SocketCItem item = null;
            while (enumerator.MoveNext())
            {
                Bp.Socket.Client socket = enumerator.Value as Bp.Socket.Client;
                item = (Config.SocketCItem)socket.DeviceType;
                if (item.Timer == t)
                {
                    if (!item.IsConnected)
                    {
                        socket.DoStart();
                    }
                    break;
                }
            }
            if (!item.IsConnected)
            {
                t.Enabled = true;
            }
        }
Exemplo n.º 2
0
        void item_PropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            //重连
            if (e.PropertyName == "IsConnected")
            {
                Config.SocketCItem item = (Config.SocketCItem)sender;

                if (!item.IsConnected)
                {
                    item.Timer.Enabled = false;
                    item.Timer.Enabled = true;
                }
                else
                {
                    item.Timer.Enabled = false;

                    if (item.SocketDevice == Common.SocketDevice.MES)
                    {
                    }
                }
            }
            else
            {
            }
        }
Exemplo n.º 3
0
        private void dgvClient_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                if (e.RowIndex >= 0)
                {
                    //当前网络客户端
                    Config.SocketCItem sck = (Config.SocketCItem) this.dgvClient.CurrentRow.DataBoundItem;

                    switch (dgvClient.Columns[e.ColumnIndex].Name)
                    {
                    case "btnDelete":
                        //删除
                        if (MessageBox.Show("是否删除该项设备?    ", "删除提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes)
                        {
                            return;
                        }
                        Config.ConfigManager.Instance.ConfigSocketC.SocketCItems.Remove(sck);
                        break;

                    case "btnSendClient":
                        //发送
                        Config.SocketCItem item = (Config.SocketCItem) this.dgvClient.CurrentRow.DataBoundItem;
                        Logic.SocketCHandle.Instance.SocketSend(item.SocketDevice, item.BuffSend);
                        break;

                    default:
                        break;
                    }
                }
            }
            catch
            {
            }
        }
Exemplo n.º 4
0
 /// <summary>
 /// socket客户端回调,虚函数,机台重写业务
 /// </summary>
 /// <param name="device"></param>
 /// <param name="socket"></param>
 /// <param name="dataB"></param>
 /// <param name="dataS"></param>
 public virtual void SocketCReceive(Config.SocketCItem device, System.Net.Sockets.Socket socket, byte[] dataB, string dataS)
 {
     //业务
     LogHandle.Instance.WriteRunLog(device.MachineID, device.SocketDevice.ToString(), "收到:{0},Client", dataS);
     //若抛出ABB业务
     if (device.SocketDevice.ToString().Contains("ABB"))
     {
     }
 }
Exemplo n.º 5
0
 /// <summary>
 /// Socket客户端发送,byte[],返回string
 /// </summary>
 /// <param name="device">设备配置</param>
 /// <param name="dataS">byte[]</param>
 public string SocketCSendReturn(Common.SocketDevice device, byte[] data)
 {
     lock (this.lock_send_socketc_byte)
     {
         Config.SocketCItem socket = SocketCHandle.Instance.GetConfig(device);
         //暂存包编号
         socket.Value = "";
         socket.Reset.Reset();
         SocketCHandle.Instance.SocketSend(device, data);
         socket.Reset.WaitOne(500);
         return(socket.Value.ToString());
     }
 }
Exemplo n.º 6
0
        void socket_PropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            if (e.PropertyName == "IsConnected")
            {
                Bp.Socket.Client client = (Bp.Socket.Client)sender;

                Config.SocketCItem item = (Config.SocketCItem)client.DeviceType;
                item.IsConnected = client.IsConnected;
                if (!item.IsConnected)
                {
                    item.Timer.Enabled = true;
                }
            }
        }
Exemplo n.º 7
0
 /// <summary>
 /// Socket客户端发送,string,返回string
 /// </summary>
 /// <param name="device"></param>
 /// <param name="data"></param>
 /// <returns></returns>
 public string SocketCSendReturn(Common.SocketDevice device, string data)
 {
     lock (this.lock_send_socketc_string)
     {
         Config.SocketCItem socket = SocketCHandle.Instance.GetConfig(device);
         //暂存包编号
         socket.Value = "";
         socket.Reset.Reset();
         SocketCHandle.Instance.SocketSend(device, data);
         if (socket.OutTime < 500)
         {
             socket.Reset.WaitOne(500);
         }
         else
         {
             socket.Reset.WaitOne(socket.OutTime);
         }
         return(socket.Value.ToString());
     }
 }
Exemplo n.º 8
0
        /// <summary>
        /// 停止
        /// </summary>
        public override void DoStop()
        {
            try
            {
                IDictionaryEnumerator enumerator = this.Sokcets.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    Bp.Socket.Client socket = enumerator.Value as Bp.Socket.Client;

                    Config.SocketCItem item = (Config.SocketCItem)socket.DeviceType;
                    item.PropertyChanged -= new PropertyChangedEventHandler(item_PropertyChanged);

                    socket.DoStop();
                }
            }
            catch (Exception ex)
            {
                throw new StopException(this.ToString(), ex.ToString());
            }
        }
Exemplo n.º 9
0
 private void dgvClient_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
 {
     try
     {
         if (this.dgvClient.Columns[e.ColumnIndex].Name.Equals("isConnected"))
         {
             //int i = e.ColumnIndex;
             Config.SocketCItem sck = (Config.SocketCItem) this.dgvClient.Rows[e.RowIndex].DataBoundItem;
             if (sck == null)
             {
                 e.Value = this.imageList1.Images[3];
             }
             else
             {
                 e.Value = (sck.IsConnected == true) ? this.imageList1.Images[1] : this.imageList1.Images[2];
             }
         }
     }
     catch
     { }
 }
Exemplo n.º 10
0
        /// <summary>
        /// 启动
        /// </summary>
        public override void DoStart()
        {
            try
            {
                IDictionaryEnumerator enumerator = this.Sokcets.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    Bp.Socket.Client socket = enumerator.Value as Bp.Socket.Client;
                    socket.DoStart();

                    if (!socket.IsConnected)
                    {
                        Config.SocketCItem item = (Config.SocketCItem)socket.DeviceType;
                        item.Timer.Enabled = true;
                    }
                }
            }
            catch (Exception ex)
            {
                throw new StartException(this.ToString(), ex.ToString());
            }
        }
Exemplo n.º 11
0
        /// <summary>
        /// Socket接收
        /// </summary>
        /// <param name="device">设备配置</param>
        /// <param name="dataB"></param>
        /// <param name="dataS"></param>
        public void SocketReceive(Config.SocketCItem device, System.Net.Sockets.Socket socket, byte[] dataB, string dataS)
        {
            try
            {
                device.BuffReceive = dataS;
                switch (device.SocketDevice)
                {
                case Common.SocketDevice.MES:

                    break;

                default:
                    //business business = SystemHandle.Instance.GetMachineKylin(device.MachineID);
                    //   if (business != null)
                    //       business.SocketCReceive(device, socket, dataB, dataS);
                    break;
                }
            }
            catch (Exception ex)
            {
                Log.LogWriter.WriteException(ex);
            }
        }
Exemplo n.º 12
0
 /// <summary>
 /// socket客户端接收
 /// </summary>
 /// <param name="device"></param>
 /// <param name="socket"></param>
 /// <param name="dataB"></param>
 /// <param name="dataS"></param>
 public override void SocketCReceive(Config.SocketCItem device, System.Net.Sockets.Socket socket, byte[] dataB, string dataS)
 {
     base.SocketCReceive(device, socket, dataB, dataS);
 }