Пример #1
0
        public void WriteAsyn(MvLoggerEventArgs ea)
        {
            this.msgQueue.Enqueue(ea);

            lock (this)
            {
                if (this.Task != null)
                {
                    if (this.Task.IsEnd())
                    {
                        using (var obj = this.Task)
                            obj.Cancel();
                    }
                    else
                    {
                        return;
                    }
                }

                this.Task = MvCancelTask.RunLoop(() =>
                {
                    MvSpinWait.SpinUntil(() => this.msgQueue.Count > 0);

                    MvLoggerEventArgs eaLog;
                    if (!this.msgQueue.TryDequeue(out eaLog))
                    {
                        return(true);
                    }
                    this.WriteSyn(eaLog);
                    return(true);
                });
            }
        }
Пример #2
0
        public int SetValue(int ch, int value)
        {
            //需等連線完成
            if (!MvSpinWait.SpinUntil(() => this.TcpClient.IsRemoteConnected, 5000))
            {
                return(-1);
            }


            if (value > 999)
            {
                throw new MvException("Light value can not set over 999");
            }
            if (value < 0)
            {
                throw new MvException("Light value can not set under zero");
            }

            var cmdType = "W12";
            var cmd     = "";

            switch (this.Model)
            {
            case MvEnumLeimacModel.IWDV_100S_24:
                cmd = string.Format("{0}{1:0000}", cmdType, value);
                break;

            case MvEnumLeimacModel.IWDV_600M2_24:
                cmd = string.Format("{0}{1:00}{2:0000}", cmdType, ch, value);
                break;

            case MvEnumLeimacModel.IDGB_50M2PG_12_TP:
            case MvEnumLeimacModel.IDGB_50M4PG_24_TP:
                cmdType = "W11";
                cmd     = string.Format("{0}{1:00}{2:0000}", cmdType, ch, value);
                break;

            default: throw new MvException("No assign Model.");
            }


            this.TcpClient.WriteMsg(cmd);



            return(0);
        }
Пример #3
0
        public int[] GetValues()
        {
            //需等連線完成
            if (!MvSpinWait.SpinUntil(() => this.TcpClient.IsRemoteConnected, 5000))
            {
                return(null);
            }


            var cmdType = "R12";
            var cmd     = "";

            switch (this.Model)
            {
            case MvEnumLeimacModel.IWDV_100S_24:
                cmd = string.Format("{0}0000", cmdType);
                break;

            case MvEnumLeimacModel.IWDV_600M2_24:
                cmd = string.Format("{0}0000", cmdType);
                break;

            case MvEnumLeimacModel.IDGB_50M2PG_12_TP:
            case MvEnumLeimacModel.IDGB_50M4PG_24_TP:
                cmdType = "R11";
                cmd     = string.Format("{0}0000", cmdType);
                break;

            default: throw new MvException("No assign Model.");
            }



            this.LastSend = DateTime.Now;
            this.TcpClient.WriteMsg(cmd);

            if (!MvSpinWait.SpinUntil(() => this.LastReceive > this.LastSend, 1000))
            {
                return(null);
            }
            return(this.Values);
        }