Example #1
0
        public byte[] GetPowerControl(功率控制 power)
        {
            byte[] sendBytes = new byte[6] {
                0xff, 0xdd, 0x00, 0x00, 0x00, 0xdd
            };

            sendBytes[2] = (byte)power;
            return(sendBytes);
        }
Example #2
0
        public bool PowerControl(功率控制 power)
        {
            while (Interlocked.Read(ref _NumberForInterLock) == 0)
            {
                Thread.Sleep(5);
            }
            Interlocked.Decrement(ref _NumberForInterLock);

            _CreateUdpClient(Function_Module.GetConfig("本机IP"), Convert.ToInt32(Function_Module.GetConfig("本机端口")));
            byte[] sendBytes = GetPowerControl(power);
            byte[] recvBytes = new byte[6];
            try
            {
                _UdpClient.Send(sendBytes, sendBytes.Length, _RemoteIP, _RemotePort);
                _UdpClient.Client.ReceiveTimeout = 3000;
                if (_UdpClient.Client.Receive(recvBytes) > 0)
                {
                    _UdpClient.Close();
                    Interlocked.Increment(ref _NumberForInterLock);
                    return(true);
                }
                else
                {
                    _UdpClient.Close();
                    Interlocked.Increment(ref _NumberForInterLock);
                    return(false);
                }
            }
            catch (Exception)
            {
                if (_UdpClient != null)
                {
                    _UdpClient.Close();
                }
                Interlocked.Increment(ref _NumberForInterLock);
                return(false);
            }
        }