Example #1
0
        /// <summary>
        /// Disconnect manual tool
        /// </summary>
        /// <param name="portName"></param>
        public void DisConnectManualTool(string portName)
        {
            var info = new HcToolInfo();
            // get values
            var values = info.GetValues();

            // change com port
            values[23] = Convert.ToByte(portName.Substring(3));
            // change mac number
            values[31] = values[23];
            // set values
            info.SetValues(values);
            // disconnect tool
            OnToolRemoved(info);
        }
Example #2
0
        private void ScannerOnToolAttach(HcToolInfo info)
        {
            var lockTakenScan     = false;
            var lockTakenRegister = false;

            try
            {
                // lock
                Monitor.TryEnter(ScannedTools, Timeout, ref lockTakenScan);
                Monitor.TryEnter(RegisteredTools, Timeout, ref lockTakenRegister);
                // check lock taken
                if (!lockTakenScan || !lockTakenRegister)
                {
                    return;
                }

                // get tools
                var register = FindToolInfo(RegisteredTools, info.Mac);
                var scan     = FindToolInfo(ScannedTools, info.Mac);
                // check scan tool
                switch (scan)
                {
                case null when register == null:
                    // add scan tool
                    ScannedTools.Add(info);
                    break;

                case null:
                    // set values
                    register.SetValues(info.GetValues());
                    // tool connect event
                    ToolConnect?.Invoke(register);
                    break;
                }
            }
            finally
            {
                // unlock
                if (lockTakenScan)
                {
                    Monitor.Exit(ScannedTools);
                }
                if (lockTakenRegister)
                {
                    Monitor.Exit(RegisteredTools);
                }
            }
        }
Example #3
0
        /// <summary>
        /// Connect manual tool
        /// </summary>
        /// <param name="portName">port name</param>
        public void ConnectManualTool(string portName)
        {
            var info = new HcToolInfo();
            // get values
            var values = info.GetValues();

            // change com port
            values[23] = Convert.ToByte(portName.Substring(3));
            // change baud rate
            values[24] = (57600 >> 8) & 0xFF;
            values[25] = 57600 & 0xFF;
            // change mac number
            values[31] = values[23];
            // set values
            info.SetValues(values);
            // connect tool
            OnToolConnect(info);
        }