Exemplo n.º 1
0
        ////////////////////////////////////////////////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////////////////////////////////////////////////
        static void DeviceInfo()
        {
            StringBuilder sb = new StringBuilder(200); // Buffer large enough to get back slave parameters

            SoemInterrop.GetDeviceInfo(1, DeviceInfoParam.State, sb);
            SlaveState s = (SlaveState)Convert.ToUInt16(sb.ToString());

            Console.WriteLine("State : " + s.ToString());
        }
Exemplo n.º 2
0
 public File(File parent, string path, string name, bool isMaster, bool isDir, InitialState state, SlaveState slaveState)
 {
     this.parent       = parent;
     this.path         = path.Replace('\\', '/');
     this.name         = name;
     this.isDir        = isDir;
     this.initialState = state;
     this.slaveState   = slaveState;
     this.isMaster     = isMaster;
     this.initialHash  = isDir == false?NGSyncFoldersWindow.TryGetCachedHash(this.path) : string.Empty;
 }
Exemplo n.º 3
0
 public static int SlaveStatetoIco(SlaveState s)
 {
     if (s == SlaveState.Operational)
     {
         return(0);
     }
     if (s == SlaveState.Unknow)
     {
         return(2);
     }
     return(1);
 }
Exemplo n.º 4
0
        public void     Delete()
        {
            InternalNGDebug.InternalLogFormat("Deleting {0} {1}", this.path, this.initialState);

            if (this.isMaster == true)
            {
                this.masterState = MasterState.Deleted;
            }
            else
            {
                this.slaveState = SlaveState.NonExist;
            }

            if (this.initialState == InitialState.New)
            {
                this.parent.children.Remove(this);
            }

            this.InvalidateHeight();
        }
Exemplo n.º 5
0
        private void tmrRefreshState_Tick(object sender, EventArgs e)
        {
            tmrStart.Enabled = false;

            SoemInterrop.RefreshSlavesState();
            foreach (TreeNode tn in devicesTreeView.Nodes)
            {
                EthCATDevice slave = tn.Tag as EthCATDevice;
                SlaveState   s     = slave.State;
                slave.Refresh();
                if (s != slave.State)
                {
                    int img = SlaveStatetoIco(slave.State);
                    tn.ImageIndex = tn.SelectedImageIndex = img;
                    devicesTreeView.Refresh();
                }

                if (tn == devicesTreeView.SelectedNode)
                {
                    propertyGrid.Refresh();
                    propertyInput.Refresh();
                }
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Request slave state transition.
        /// </summary>
        /// <param name="slaveIndex">Slave index.</param>
        /// <param name="slaveState">Slave target state.</param>
        /// <returns>True if transition was successful, false otherwise./returns>
        public bool RequestState(int slaveIndex, SlaveState slaveState)
        {
            UInt16 stateSet = EcHL.RequestState(this.Context, slaveIndex, (UInt16)slaveState);

            return((SlaveState)stateSet == slaveState);
        }
Exemplo n.º 7
0
        private void    Sync(File model, bool force = false)
        {
            Action action = this.ChooseAction(model);

            if (action != Action.Nothing || force == true)
            {
                try
                {
                    this.actionException = null;

                    if (action == Action.Delete)
                    {
                        System.IO.File.Delete(this.path);
                        EditorApplication.delayCall += () => this.parent.children.Remove(this);

                        if (Directory.GetFiles(Path.GetDirectoryName(this.path)).Length == 0)
                        {
                            Directory.Delete(Path.GetDirectoryName(this.path));
                        }

                        InternalNGDebug.InternalLogFormat("Sync \"{0}\": Deleted.", this.path);
                    }
                    else if (action == Action.Create)
                    {
                        Directory.CreateDirectory(Path.GetDirectoryName(this.path));
                        if (System.IO.File.Exists(this.path) == false)
                        {
                            System.IO.File.Copy(model.path, this.path);
                        }
                        else
                        {
                            System.IO.File.WriteAllBytes(this.path, System.IO.File.ReadAllBytes(model.path));
                        }
                        this.initialHash = NGSyncFoldersWindow.TryGetCachedHash(path);
                        this.slaveState  = SlaveState.Exist;

                        InternalNGDebug.InternalLogFormat("Sync \"{0}\": Created.", this.path);
                    }
                    else if (action == Action.Change || force == true)
                    {
                        Directory.CreateDirectory(Path.GetDirectoryName(this.path));
                        System.IO.File.WriteAllBytes(this.path, System.IO.File.ReadAllBytes(model.path));
                        this.initialHash = NGSyncFoldersWindow.TryGetCachedHash(path);

                        InternalNGDebug.InternalLogFormat("Sync \"{0}\": Restored.", this.path);
                    }

                    this.initialState = InitialState.Origin;

                    this.InvalidateHeight();
                }
                catch (Exception ex)
                {
                    this.actionException = ex;
                    if (model != null)
                    {
                        InternalNGDebug.LogException("Syncing file " + this.path + " with " + model.path + " failed. (" + Enum.GetName(typeof(Action), action) + ")", ex);
                    }
                    else
                    {
                        InternalNGDebug.LogException("Syncing file " + this.path + " failed. (" + Enum.GetName(typeof(Action), action) + ")", ex);
                    }
                }
            }
        }
Exemplo n.º 8
0
        public File     Generate(string path)
        {
            this.InvalidateHeight();

            if (this.path == path)
            {
                string hash = NGSyncFoldersWindow.TryGetCachedHash(path);

                if (this.isMaster == true)
                {
                    if (hash == this.initialHash)
                    {
                        this.masterState = MasterState.Same;
                    }
                    else
                    {
                        this.masterState = MasterState.Altered;
                    }
                }
                else
                {
                    this.initialHash = hash;
                    this.slaveState  = SlaveState.Exist;
                }

                this.targetHash = hash;

                return(this);
            }

            string oldPath = path.Substring(0, this.path.Length + 1);

            string[] newPath = path.Substring(this.path.Length + 1).Split(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar);
            File     parent  = this;

            path = this.path;

            for (int i = 0; i < newPath.Length; i++)
            {
                oldPath = Path.Combine(oldPath, newPath[i]);
                path    = Path.Combine(path, newPath[i]);

                File child = null;

                for (int j = 0; j < parent.children.Count; j++)
                {
                    if (parent.children[j].path == path)
                    {
                        child = parent.children[j];
                        break;
                    }
                }

                if (child == null)
                {
                    InternalNGDebug.InternalLogFormat("Generating {0} in {1} ({2})", path, parent, oldPath);
                    if (this.isMaster == true)
                    {
                        child = new File(parent, path, Path.GetFileName(path), true, Directory.Exists(oldPath), InitialState.New, MasterState.Created);
                    }
                    else
                    {
                        child = new File(parent, path, Path.GetFileName(path), false, Directory.Exists(oldPath), InitialState.New, System.IO.File.Exists(path) ? SlaveState.Exist : SlaveState.NonExist);
                    }
                    parent.children.Add(child);
                    parent.children.Sort((a, b) => string.CompareOrdinal(a.path, b.path));
                }

                parent = child;
            }

            return(parent);
        }
Exemplo n.º 9
0
 public static extern void WriteState(UInt32 deviceNum, SlaveState State);
Exemplo n.º 10
0
 public static extern void Run(SlaveState State = SlaveState.Operational);
Exemplo n.º 11
0
 public void WriteState(SlaveState state)
 {
     SoemInterrop.WriteState(Id, state);
 }