Esempio n. 1
0
        //////////////
        ///
        private void Test()
        {
            if (Blaster.Connected == false)
            {
                return;
            }
            if (buttonTest.Enabled == false)
            {
                return;
            }
            if (_selectedItem == null || _selectedItem.Tag == null)
            {
                return;
            }
            if (_selectedItem.Tag.GetType() != typeof(BlasterCommand))
            {
                return;
            }

            BlasterCommand command = _selectedItem.Tag as BlasterCommand;

            if (command.RawData == null)
            {
                return;
            }

            switch (command.Speed)
            {
            case Speed.Fast:
                Blaster.Speed = 0;
                break;

            case Speed.Medium:
                Blaster.Speed = 1;
                break;

            case Speed.Slow:
                Blaster.Speed = 2;
                break;
            }

            switch (command.Port)
            {
            case Port.Both:
                Blaster.Send(0, command.RawData);
                break;

            case Port.One:
                Blaster.Send(1, command.RawData);
                break;

            case Port.Two:
                Blaster.Send(2, command.RawData);
                break;
            }
        }
        /// <summary>
        /// Overload for MS or SMK Blasting
        /// </summary>
        private void Send(int externalChannel, int card)
        {
            if (_blaster1Card == card)
            {
                _sendPort = 1;
            }
            else if (_blaster2Card == card)
            {
                _sendPort = 2;
            }
            else if (_blaster1Card == _blaster2Card)
            {
                _sendPort = 0;
            }

            if (_advandeLogging)
            {
                Log.WriteFile("ServerBlaster.Send: C {0} - B1{1} - B2{2}. Channel is {3}", card, _blaster1Card, _blaster2Card,
                              externalChannel);
            }

            try
            {
                foreach (char ch in externalChannel.ToString())
                {
                    if (char.IsDigit(ch) == false)
                    {
                        continue;
                    }
                    if (_advandeLogging)
                    {
                        Log.WriteFile("ServerBlaster.Sending {0} on blaster {1}", ch, _sendPort);
                    }

                    byte[] packet = _packetCollection[ch.ToString()] as byte[];

                    if (packet == null)
                    {
                        Log.WriteFile("ServerBlaster.Send: Missing packet for '{0}'", ch);
                    }
                    if (packet != null)
                    {
                        Blaster.Send(_sendPort, packet, _deviceType, _deviceSpeed, _advandeLogging);
                    }
                    if (packet != null && _sleepTime != 0)
                    {
                        Thread.Sleep(_sleepTime);
                    }
                    if (_advandeLogging)
                    {
                        Log.WriteFile("ServerBlaster.Send logic is done");
                    }
                }

                if (_sendSelect)
                {
                    //byte[] packet = _packetCollection["Select"] as byte[];
                    if (_advandeLogging)
                    {
                        Log.Write("ServerBlaster.Send: Sending Select");
                    }
                    byte[] packet = _packetCollection["Select"] as byte[];
                    if (packet != null)
                    {
                        Blaster.Send(_sendPort, packet, _deviceType, _deviceSpeed, _advandeLogging);
                    }
                }
            }
            catch (Exception e)
            {
                Log.WriteFile("ServerBlaster.Send: {0}", e.Message);
            }
        }