コード例 #1
0
        void trySend(ledSendInfo sendInfo)
        {
            var tryCount = 0;

            while (tryCount < 3)
            {
                if (LEDSender.R_DEVICE_READY == this.SendLEDMessage(sendInfo))
                {
                    break;
                }
                Thread.Sleep(100);
                tryCount++;
            }
        }
コード例 #2
0
 int SendLEDMessage(ledSendInfo sendInfo)
 {
     return(this.SendLEDMessage(sendInfo.ip, ushort.Parse(sendInfo.port), sendInfo.colorMode, sendInfo.deviceAddr, sendInfo.position, sendInfo.text, sendInfo.isFlash));
 }
コード例 #3
0
        void client_OnMessage(QueueMessage.Message message)
        {
            switch (message.GetType().Name)
            {
            case MessageName.CallMessage:
            {
                var msg = message as CallMessage;
                if (msg.IsLEDMessage)
                {
                    var win = this.listLedWin.Find(m => m.WindowNumber == msg.WindowNo);
                    if (win != null)
                    {
                        var ctl = this.listLedControl.Find(m => m.ID == win.ControllerID);
                        if (ctl != null)
                        {
                            if (!callDic.ContainsKey(win.WindowNumber))
                            {
                                callDic.TryAdd(win.WindowNumber, DateTime.Now);
                            }
                            //频繁呼叫直接取消
                            else if (DateTime.Now - callDic[win.WindowNumber] < callSpan)
                            {
                                return;
                            }
                            Task.Factory.StartNew(arg =>
                                {
                                    var sendInfo = arg as ledSendInfo;
                                    //LED闪烁
                                    sendInfo.isFlash = true;
                                    this.trySend(sendInfo);
                                    Thread.Sleep(3000);
                                    sendInfo.isFlash = false;
                                    this.trySend(sendInfo);
                                }, new ledSendInfo()
                                {
                                    ip         = ctl.IP,
                                    port       = ctl.Port,
                                    colorMode  = fullColorList.Contains(win.WindowNumber) ? 4 : 3,
                                    deviceAddr = ctl.DeviceAddress,
                                    position   = win.Position,
                                    text       = win.DisplayText.Replace("{Number}", msg.TicketNo)
                                });
                            callDic.AddOrUpdate(win.WindowNumber, DateTime.Now, (k, v) =>
                                {
                                    return(DateTime.Now);
                                });
                        }
                    }
                }
            }
            break;

            case MessageName.RateMessage:
            {
                var msg = message as RateMessage;
                var win = this.listLedWin.Find(m => m.WindowNumber == msg.WindowNo);
                if (win != null)
                {
                    var ctl = this.listLedControl.Find(m => m.ID == win.ControllerID);
                    if (ctl != null)
                    {
                        Task.Factory.StartNew(arg =>
                            {
                                this.trySend(arg as ledSendInfo);
                            }, new ledSendInfo()
                            {
                                ip         = ctl.IP,
                                port       = ctl.Port,
                                colorMode  = fullColorList.Contains(win.WindowNumber) ? 4 : 3,
                                deviceAddr = ctl.DeviceAddress,
                                position   = win.Position,
                                text       = this.resumeText
                            });
                    }
                }
            }
            break;

            case MessageName.OperateMessage:
            {
                var msg = message as OperateMessage;
                var win = this.listLedWin.Find(m => m.WindowNumber == msg.WindowNo);
                if (win != null)
                {
                    var ctl = this.listLedControl.Find(m => m.ID == win.ControllerID);
                    if (ctl != null)
                    {
                        var sendInfo = new ledSendInfo()
                        {
                            ip         = ctl.IP,
                            port       = ctl.Port,
                            colorMode  = fullColorList.Contains(win.WindowNumber) ? 4 : 3,
                            deviceAddr = ctl.DeviceAddress,
                            position   = win.Position
                        };
                        if (msg.Operate == Operate.Pause)
                        {
                            sendInfo.text = this.pauseText;
                        }
                        else if (msg.Operate == Operate.Reset)
                        {
                            sendInfo.text = this.resumeText;
                        }
                        Task.Factory.StartNew(arg =>
                            {
                                this.trySend(arg as ledSendInfo);
                            }, sendInfo);
                    }
                }
            }
            break;
            }
            this.txtSoundMesInfo.Invoke(new Action(() =>
            {
                this.messageIndicator1.SetState(StateType.Success, "收到消息:" + message.ToString());
                this.txtSoundMesInfo.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "\r\n" + message.ToString() + "。\r\n");
                LogService.Info(message.ToString());
            }));
        }