示例#1
0
        public void DuplicateCommandTest()
        {
            ViscaApertureInquiry  apertureInquiry  = new ViscaApertureInquiry(id, (_) => { });
            ViscaBackLightInquiry backLightInquiry = new ViscaBackLightInquiry(id, (_) => { });
            ViscaBGainInquiry     bGainInquiry     = new ViscaBGainInquiry(id, (_) => { });
            ViscaExpCompInquiry   expCompInquiry   = new ViscaExpCompInquiry(id, (_) => { });
            ViscaGainInquiry      gainInquiry      = new ViscaGainInquiry(id, (_) => { });

            // Special local processor with very long timeout
            BlockingCollection <byte[]> sendQueue = new BlockingCollection <byte[]>(15);
            ViscaProtocolProcessor      visca     = new ViscaProtocolProcessor(
                new Action <byte[]>(b =>
            {
                sendQueue.Add(b);
            }),
                new Action <byte, string, object[]>((l, f, o) =>
            {
                Console.WriteLine("VISCA LOG:[{0}]", String.Format(f, o));
            }),
                120000
                );

            visca.EnqueueCommand(apertureInquiry);
            // First command will be de-queued after enqueing
            visca.CommandsInQueue.Should().Be(0);
            visca.EnqueueCommand(backLightInquiry);
            visca.CommandsInQueue.Should().Be(1);
            visca.EnqueueCommand(bGainInquiry);
            visca.CommandsInQueue.Should().Be(2);
            visca.EnqueueCommand(expCompInquiry);
            visca.CommandsInQueue.Should().Be(3);
            visca.EnqueueCommand(gainInquiry);
            visca.CommandsInQueue.Should().Be(4);
            visca.EnqueueCommand(bGainInquiry);
            visca.CommandsInQueue.Should().Be(4);
        }
示例#2
0
        public async Task Power_OnWithFeedback()
        {
            bool       power      = false;
            ViscaPower powerOnCmd = new ViscaPower(id, OnOffMode.On);

            visca.EnqueueCommand(powerOnCmd.OnCompletion(() => { power = true; }));

            Assert.That(sendQueue.TryTake(out byte[] powerPacket, 100), Is.True, "Timeout on sending data for Power On");
            Assert.That(powerPacket.SequenceEqual(new byte[] { 0x81, 0x01, 0x04, 0x00, 0x02, 0xff }), Is.True, "Power On bytes sequence does not match expected");

            // Respond Completion
            visca.ProcessIncomingData(new byte[] { 0x90, 0x50, 0xFF });

            ViscaPowerInquiry powerInquiry = new ViscaPowerInquiry(id, new Action <OnOffMode>(mode => { power = mode; Console.WriteLine("Event: power: {0}", mode); }));

            visca.EnqueueCommand(powerInquiry);
            Assert.That(sendQueue.TryTake(out byte[] powerInquiryPacket, 100), Is.True, "Timeout on sending data for Power Inquiry");
            Assert.That(powerInquiryPacket.SequenceEqual(new byte[] { 0x81, 0x09, 0x04, 0x00, 0xff }), Is.True, "Power Inquiry bytes sequence does not match expected");

            // Respond Power is On
            visca.ProcessIncomingData(new byte[] { 0x90, 0x50, 0x02, 0xFF });
            await Task.Delay(100);

            power.Should().Be(true);

            /*
             * using (var monitoredSubject = power.Monitor())
             * {
             *  // Send Power is ON
             *  visca.ProcessIncomingData(new byte[] { 0x90, 0x50, 0x02, 0xFF });
             *  await Task.Delay(100);
             *  monitoredSubject.Should().Raise("PowerChanged").WithSender(camera).WithArgs<ViscaCamera.OnOffEventArgs>(args => args.On == true);
             * }
             * camera.Power.Should().Be(true);
             */
        }