Ejemplo n.º 1
0
        public void Add(ICommunicationCommand cmd)
        {
            ElementModel emodel = null;

            if (cmd is GeneralWriteCommand)
            {
                GeneralWriteCommand gwcmd = (GeneralWriteCommand)cmd;
                Write(gwcmd.RefElements_A);
                Write(gwcmd.RefElements_B);
            }
            if (cmd is IntrasegmentWriteCommand)
            {
            }
            if (cmd is ForceCancelCommand)
            {
                ForceCancelCommand fccmd = (ForceCancelCommand)cmd;
                emodel = fccmd.RefElement;
                if (fccmd.IsAll)
                {
                    foreach (ElementModel _emodel in dict.Values)
                    {
                        Unlock(_emodel);
                    }
                    smodel.SManager.UnlockAll();
                }
                else
                {
                    Unlock(emodel);
                }
            }
        }
Ejemplo n.º 2
0
 private void Execute(ICommunicationCommand cmd)
 {
     if (cmd.IsSuccess)
     {
         cmd.UpdataValues();
     }
 }
Ejemplo n.º 3
0
 public void Add(ICommunicationCommand cmd)
 {
     if (cmd is GeneralReadCommand ||
         cmd is IntrasegmentReadCommand)
     {
         throw new NotSupportedException("Unsupported operation : directly add a read command.");
     }
     if (cmd is GeneralWriteCommand ||
         cmd is IntrasegmentWriteCommand ||
         cmd is ForceCancelCommand)
     {
         if (_Thread_IsActive)
         {
             if (H_Command == MonitorManager_CommunicationCommandHandle.NULL)
             {
                 H_Command      = MonitorManager_CommunicationCommandHandle.ADD;
                 O_Command      = cmd;
                 _Thread_Active = false;
             }
         }
         else
         {
             _Add(cmd);
         }
     }
 }
Ejemplo n.º 4
0
        public void Handle(IMoniValueModel mvmodel, ElementValueModifyEventArgs e)
        {
            ElementModel element = (ElementModel)mvmodel;

            element.ShowType = e.VarType;
            byte bvalue = 0;
            ICommunicationCommand command = null;

            switch (e.Type)
            {
            case ElementValueModifyEventType.ForceON:
                bvalue           = 0x01;
                element.SetValue = "ON";
                Force(element, bvalue);
                break;

            case ElementValueModifyEventType.ForceOFF:
                bvalue           = 0x00;
                element.SetValue = "OFF";
                Force(element, bvalue);
                break;

            case ElementValueModifyEventType.ForceCancel:
                element.SetValue = String.Empty;
                command          = new ForceCancelCommand(false, element);
                Add(command);
                break;

            case ElementValueModifyEventType.AllCancel:
                element.SetValue = String.Empty;
                command          = new ForceCancelCommand(true, element);
                Add(command);
                break;

            case ElementValueModifyEventType.WriteOFF:
                bvalue           = 0x00;
                element.SetValue = "OFF";
                Write(element, bvalue);
                break;

            case ElementValueModifyEventType.WriteON:
                bvalue           = 0x01;
                element.SetValue = "ON";
                Write(element, bvalue);
                break;

            case ElementValueModifyEventType.Write:
                element.SetValue = e.Value;
                Write(element, element.SetValue);
                break;
            }
        }
Ejemplo n.º 5
0
 public int Write(ICommunicationCommand cmd)
 {
     try
     {
         byte[] data = cmd.GetBytes();
         port.Write(data, 0, data.Length);
     }
     catch (Exception)
     {
         return(1);
     }
     return(0);
 }
Ejemplo n.º 6
0
        public int Read(ICommunicationCommand cmd)
        {
            ErrorCode ec = ErrorCode.None;

            byte[] tempdata = new byte[4096];
            byte[] data     = new byte[cmd.RecvDataLen];
            int    bytesRead;

            try
            {
                ec = reader.Read(tempdata, 100, out bytesRead);
                if (AssertCommand(cmd))
                {
                    for (int i = 0; i < bytesRead; i++)
                    {
                        data[readBuffercount++] = tempdata[i];
                    }
                }
                else
                {
                    int cnt = bytesRead / CommunicationDataDefine.USB_MAX_READ_LEN;
                    int res = bytesRead % CommunicationDataDefine.USB_MAX_READ_LEN;
                    for (int i = 0; i < cnt; i++)
                    {
                        for (int j = 2; j < CommunicationDataDefine.USB_MAX_READ_LEN; j++)
                        {
                            data[readBuffercount++] = tempdata[j + CommunicationDataDefine.USB_MAX_READ_LEN * i];
                        }
                    }
                    for (int i = 2; i < res; i++)
                    {
                        data[readBuffercount++] = tempdata[i + CommunicationDataDefine.USB_MAX_READ_LEN * cnt];
                    }
                }
                if (ec != ErrorCode.None)
                {
                    return(1);
                }
            }
            catch (Exception)
            {
                return(1);
            }
            if (readBuffercount != cmd.RecvDataLen)
            {
                return(1);
            }
            cmd.RetData     = data;
            readBuffercount = 0;
            return(0);
        }
Ejemplo n.º 7
0
        public int Write(ICommunicationCommand cmd)
        {
            ErrorCode ec = ErrorCode.None;
            int       bytesWritten;

            try
            {
                ec = writer.Write(cmd.GetBytes(), 2000, out bytesWritten);
                if (ec != ErrorCode.None)
                {
                    return(1);
                }
            }
            catch (Exception)
            {
                return(1);
            }
            return(0);
        }
Ejemplo n.º 8
0
 public int Read(ICommunicationCommand cmd)
 {
     try
     {
         int count = port.Read(readbuffer, readbuffercount, 4096 - readbuffercount);
         readbuffercount += count;
         byte[] data = new byte[readbuffercount];
         for (int i = 0; i < readbuffercount; i++)
         {
             data[i] = readbuffer[i];
         }
         cmd.RetData = data;
     }
     catch (Exception e)
     {
         return(1);
     }
     if (!cmd.IsComplete)
     {
         return(1);
     }
     readbuffercount = 0;
     return(0);
 }
Ejemplo n.º 9
0
        static private bool Handle(ICommunicationCommand cmd, int waittime = 10)
        {
            bool hassend  = false;
            bool hasrecv  = false;
            int  sendtime = 0;
            int  recvtime = 0;

            while (sendtime < 5)
            {
                if (commanager.Write(cmd) == 0)
                {
                    hassend = true;
                    break;
                }
                sendtime++;
            }
            if (!hassend)
            {
                return(false);
            }
            Thread.Sleep(waittime);
            if (cmd.RecvDataLen == 0)
            {
                return(true);
            }
            while (true)
            {
                if (commanager.Read(cmd) == 0)
                {
                    hasrecv = true;
                    break;
                }
                recvtime++;
            }
            return(hasrecv && cmd.IsComplete && cmd.IsSuccess);
        }
Ejemplo n.º 10
0
        public void Handle(IMoniValueModel mvmodel, ElementValueModifyEventArgs e)
        {
            if (mvmodel is SimuMoniValueModel)
            {
                SimuMoniValueModel smvmodel = (SimuMoniValueModel)mvmodel;
                switch (e.Type)
                {
                case ElementValueModifyEventType.ForceON:
                case ElementValueModifyEventType.ForceOFF:
                    smvmodel.Lock(e.Value, e.VarType);
                    break;

                case ElementValueModifyEventType.WriteON:
                case ElementValueModifyEventType.WriteOFF:
                case ElementValueModifyEventType.Write:
                    smvmodel.Write(e.Value, e.VarType);
                    break;

                case ElementValueModifyEventType.ForceCancel:
                    smvmodel.Unlock();
                    break;

                case ElementValueModifyEventType.AllCancel:
                    smvmodel.UnlockAll();
                    break;
                }
            }
            if (mvmodel is ElementModel)
            {
                ElementModel          element = (ElementModel)mvmodel;
                ICommunicationCommand command = null;
                switch (e.Type)
                {
                case ElementValueModifyEventType.ForceON:
                    element.SetValue = "ON";
                    Lock(element);
                    break;

                case ElementValueModifyEventType.ForceOFF:
                    element.SetValue = "OFF";
                    Lock(element);
                    break;

                case ElementValueModifyEventType.ForceCancel:
                    element.SetValue = String.Empty;
                    command          = new ForceCancelCommand(false, element);
                    Add(command);
                    break;

                case ElementValueModifyEventType.AllCancel:
                    element.SetValue = String.Empty;
                    command          = new ForceCancelCommand(true, element);
                    Add(command);
                    break;

                case ElementValueModifyEventType.WriteOFF:
                    element.SetValue = "OFF";
                    Write(element);
                    break;

                case ElementValueModifyEventType.WriteON:
                    element.SetValue = "ON";
                    Write(element);
                    break;

                case ElementValueModifyEventType.Write:
                    element.SetValue = e.Value;
                    Write(element);
                    break;
                }
            }
        }
Ejemplo n.º 11
0
 public void Remove(ICommunicationCommand cmd)
 {
 }
Ejemplo n.º 12
0
 private bool AssertCommand(ICommunicationCommand cmd)
 {
     return(cmd is IntrasegmentWriteCommand || cmd is GeneralWriteCommand ||
            cmd is ForceCancelCommand);
 }
Ejemplo n.º 13
0
 private bool Recv(ICommunicationCommand cmd)
 {
     return(CManager.Read(cmd) == 0);
 }
Ejemplo n.º 14
0
 private bool Send(ICommunicationCommand cmd)
 {
     return(CManager.Write(cmd) == 0);
 }
Ejemplo n.º 15
0
 private void _Remove(ICommunicationCommand cmd)
 {
     throw new NotSupportedException("Unsupported operation : directly remove a command.");
 }
Ejemplo n.º 16
0
 private void _Add(ICommunicationCommand cmd)
 {
     WriteCommands.Enqueue(cmd);
 }