Пример #1
0
        public bool set_name(string name)
        {
            try
            {
                if (_serialPort.IsOpen)
                {
                    Disc?.Invoke(this, null);
                }
                else
                {
                    _serialPort.PortName = name;
                    _serialPort.Open();
                    wakeup_counter();
                    if (counter_wakeup)
                    {
//						timer.Start();
                    }
                }
            }
            catch (Exception)
            {
            }

            return(_serialPort.IsOpen);
        }
Пример #2
0
        private void counter_synchro()
        {
            byte[] send = new byte[1];
            send[0] = (byte)0xAA;
            mutex   = true;
            if (_serialPort.IsOpen)
            {
                _serialPort.ReadTimeout = 350;
                _serialPort.DiscardInBuffer();

                int i = 0;
                for (; i < 3; i++)
                {
                    try
                    {
                        _serialPort.Write(send, 0, send.Length);
                        if (_serialPort.ReadByte() == 0xDD)
                        {
                            i = 1000;
                        }
                    }
                    catch (Exception E)
                    {
                    }
                }
                if (i < 999)
                {
                    Disc?.Invoke(this, null);
                }
            }
            mutex = false;
        }