예제 #1
0
        public CNCState BuildCopy()
        {
            Dictionary <int, IToolState> newToolStates = new Dictionary <int, IToolState>();

            foreach (var item in toolStates)
            {
                if (item.Value is SpindleState ss)
                {
                    newToolStates.Add(item.Key, ss.BuildCopy());
                }
                else if (item.Value is BinaryState bs)
                {
                    newToolStates.Add(item.Key, bs.BuildCopy());
                }
                else if (item.Value == null)
                {
                    newToolStates.Add(item.Key, null);
                }
                else
                {
                    throw new ArgumentOutOfRangeException("Invalid state");
                }
            }
            return(new CNCState(config,
                                AxisState.BuildCopy(),
                                DrillingState.BuildCopy(),
                                SyncToolState.BuildCopy(),
                                newToolStates,
                                VarsState));
        }
예제 #2
0
 private CNCState(MachineParameters config,
                  AxisState axisState,
                  DrillingState drillingState,
                  SyncToolState syncToolState,
                  IReadOnlyDictionary <int, IToolState> ts,
                  VarsState vs)
 {
     AxisState     = axisState;
     toolStates    = ts.ToDictionary(entry => entry.Key, entry => entry.Value);
     DrillingState = drillingState;
     SyncToolState = syncToolState;
     VarsState     = vs;
     this.config   = config;
 }
예제 #3
0
 public CNCState(MachineParameters config)
 {
     AxisState = new AxisState
     {
         Feed = config.fastfeed / 60m,
     };
     DrillingState = new DrillingState();
     SyncToolState = new SyncToolState();
     toolStates    = new Dictionary <int, IToolState>();
     VarsState     = new VarsState();
     foreach (var item in config.tools)
     {
         int id     = item.Key;
         var driver = item.Value;
         if (driver is N700E_Tool)
         {
             toolStates[id] = new SpindleState();
         }
         else if (driver is GPIO_Tool)
         {
             toolStates[id] = new BinaryState();
         }
         else if (driver is RawModbus_Tool)
         {
             toolStates[id] = new BinaryState();
         }
         else if (driver is Dummy_Tool)
         {
             toolStates[id] = null;
         }
         else
         {
             throw new ArgumentOutOfRangeException();
         }
     }
 }