Simple class to control networked projectors via the PJLink protocol. See full spec here: http://pjlink.jbmia.or.jp/english/data/PJLink%20Specifications100.pdf This library was written in one day, so don't expect perfection. Most information must be fetched from commands after execution (sendCommand). For most common tasks, there are some shortcuts available in the PJLinkConnectionPJLinkConnection class. Basic usage: // Create connection object, communicating with projector with IP 192.168.1.14 // Projector has authentication enabled, password is rv (ignored if auth disabled) PJLinkConnection c = new PJLinkConnection("192.168.1.14", "rv"); //using shortcuts c.turnOn(); c.turnOff(); System.Console.WriteLine(c.getProjectorInfo()); //using low(er) level commands ErrorStatusCommand esc = new ErrorStatusCommand(); if (c.sendCommand(esc) == Command.Response.SUCCESS) Console.WriteLine(esc.dumpToString()); else Console.WriteLine("Communication Error");
Beispiel #1
0
        private void connect_Click(object sender, EventArgs e)
        {
            System.Net.IPAddress address = null;

            if (System.Net.IPAddress.TryParse(ipAddress.Text, out address))
            {
                Status.Text = "Connecting to " + address.ToString();
                c = new PJLinkConnection(ipAddress.Text, "JBMIAProjectorLink");

                LampStatusCommand l = new LampStatusCommand();
                int hours = l.getHoursOfLamp(1);
                string status = l.getStatusOfLamp(1).ToString();
                string power = c.powerQuery().ToString();
                ProjectorInfo pi = new ProjectorInfo();
                Status.Text = "Connected. \n Projector is now: " + power + "\n" + "\nstatus: " + status + "\nlamphours: " + hours;
                Status.Text += "\nFan:" + pi.FanStatus;
                Status.Text += " Lamp:" + pi.LampStatus;
                Status.Text += " Input:" + pi.Input;
                Status.Text += "\nCover:" + pi.CoverStatus;
                Status.Text += " Filter:" + pi.FilterStatus;
                Status.Text += " NumLamps:" + pi.NumOfLamps;
                Status.Text += "\nOthers:" + pi.PowerStatus;

            }
            else
            {
                Status.Text = "Invalid IP Address Entered";
            }
        }
        private async void btnInfo_Click(object sender, RoutedEventArgs e)
        {
            //try
            {
                string info           = "";
                rv.PJLinkConnection c = connectBeamer();
                info = await c.getProjectorInfo();

                LampStatusCommand lscmd = new LampStatusCommand();
                if (await c.sendCommand(lscmd) == Command.Response.SUCCESS)
                {
                    info += "\n";
                    info += lscmd.dumpToString();
                }

                var view = ApplicationView.GetForCurrentView();
                view.TryResizeView(new Size(328, 250));
                InfoDialog dialog = new InfoDialog(info);
                await dialog.ShowAsync();

                view.TryResizeView(new Size(328, 100));
            }
            //catch (Exception)
            {
            }
        }
        private async void btnMute_Click(object sender, RoutedEventArgs e)
        {
            await Task.Run(async() =>
            {
                try
                {
                    rv.PJLinkConnection c = connectBeamer();
                    AVMuteCommand qcmd    = new AVMuteCommand(AVMuteCommand.Action.QUERYSTATE);
                    if (await c.sendCommand(qcmd) == Command.Response.SUCCESS)
                    {
                        AVMuteCommand acmd;
                        if (qcmd.Status == AVMuteCommand.Action.MUTE)
                        {
                            acmd = new AVMuteCommand(AVMuteCommand.Action.UNMUTE);

                            await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal,
                                                                                          () =>
                            {
                                _timerMuteBlink.Stop();
                                btnMute.Background = btndefBack;
                            });
                        }
                        else
                        {
                            acmd = new AVMuteCommand(AVMuteCommand.Action.MUTE);
                            await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal,
                                                                                          () =>
                            {
                                _timerMuteBlink.Start();
                            });
                        }
                        await c.sendCommand(acmd);
                    }
                }
                catch (Exception)
                {
                }
            });
        }
Beispiel #4
0
        static void Main(string[] args)
        {
            PJLinkConnection c = new PJLinkConnection("192.168.1.14", "rv");

            //shortcuts
            //c.turnOn();
            //System.Console.WriteLine(c.getProjectorInfo());

            //detailed command calls

            //PowerCommand pc1 = new PowerCommand(PowerCommand.Powr.QUERY);
            //if (c.sendCommand(pc1) == Command.Response.SUCCESS)
            //    Console.WriteLine("Projector is " + pc1.Status.ToString());
            //else
            //    Console.WriteLine("Communication Error");

            //PowerCommand pc2 = new PowerCommand(PowerCommand.Powr.ON);
            //if (c.sendCommand(pc2) == Command.Response.SUCCESS)
            //    Console.WriteLine("Switching on successful");
            //else
            //    Console.WriteLine("Communication Error");

            //PowerCommand pc3 = new PowerCommand(PowerCommand.Powr.QUERY);
            //if (c.sendCommand(pc3) == Command.Response.SUCCESS)
            //    Console.WriteLine("Projector is " + pc3.Status.ToString());
            //else
            //    Console.WriteLine("Communication Error");

            //ErrorStatusCommand esc = new ErrorStatusCommand();
            //if (c.sendCommand(esc) == Command.Response.SUCCESS)
            //    Console.WriteLine(esc.dumpToString());
            //else
            //    Console.WriteLine("Communication Error");

            //LampStatusCommand lsc = new LampStatusCommand();
            //if (c.sendCommand(lsc) == Command.Response.SUCCESS)
            //    Console.WriteLine(lsc.dumpToString());
            //else
            //    Console.WriteLine("Communication Error");

            //ProjectorNameCommand pnc = new ProjectorNameCommand();
            //if (c.sendCommand(pnc) == Command.Response.SUCCESS)
            //    Console.WriteLine(pnc.dumpToString());
            //else
            //    Console.WriteLine("Communication Error");

            //ManufacturerNameCommand mnc = new ManufacturerNameCommand();
            //if (c.sendCommand(mnc) == Command.Response.SUCCESS)
            //    Console.WriteLine(mnc.dumpToString());
            //else
            //    Console.WriteLine("Communication Error");

            //ProductNameCommand prnc = new ProductNameCommand();
            //if (c.sendCommand(prnc) == Command.Response.SUCCESS)
            //    Console.WriteLine(prnc.dumpToString());
            //else
            //    Console.WriteLine("Communication Error");

            //OtherInfoCommand oic = new OtherInfoCommand();
            //if (c.sendCommand(oic) == Command.Response.SUCCESS)
            //    Console.WriteLine(oic.dumpToString());
            //else
            //    Console.WriteLine("Communication Error");

            //InputCommand ic1 = new InputCommand();
            //if (c.sendCommand(ic1) == Command.Response.SUCCESS)
            //    Console.WriteLine(ic1.dumpToString());
            //else
            //    Console.WriteLine("Communication Error");

            //InputCommand ic2 = new InputCommand(InputCommand.InputType.RGB, 2);
            //if (c.sendCommand(ic2) == Command.Response.SUCCESS)
            //    Console.WriteLine(ic2.dumpToString());
            //else
            //    Console.WriteLine("Communication Error");

            ProjectorInfo pi = ProjectorInfo.create(c);
            string s = pi.toXmlString();
            Console.WriteLine(s);

            Console.ReadKey();
        }
Beispiel #5
0
 public void InitPJLinkConnection()
 {
     _connection = new PJLinkConnection(IP.ToString(), PASSWORD);
 }
        public static async Task <ProjectorInfo> create(PJLinkConnection c)
        {
            ProjectorInfo pi = new ProjectorInfo();

            pi._projectorHostName = c.HostName;
            ProjectorNameCommand pnc = new ProjectorNameCommand();

            if (await c.sendCommand(pnc) == Command.Response.SUCCESS)
            {
                pi._projectorHostName = pnc.Name;
            }

            ManufacturerNameCommand mnc = new ManufacturerNameCommand();

            if (await c.sendCommand(mnc) == Command.Response.SUCCESS)
            {
                pi._projectorManufacturerName = mnc.Manufacturer;
            }

            ProductNameCommand prnc = new ProductNameCommand();

            if (await c.sendCommand(prnc) == Command.Response.SUCCESS)
            {
                pi._projectorProductName = prnc.ProductName;
            }

            ErrorStatusCommand esc = new ErrorStatusCommand();

            if (await c.sendCommand(esc) == Command.Response.SUCCESS)
            {
                pi._fanStatus    = esc.FanStatus;
                pi._lampStatus   = esc.LampStatus;
                pi._coverStatus  = esc.CoverStatus;
                pi._filterStatus = esc.FilterStatus;
                pi._otherStatus  = esc.OtherStatus;
            }

            PowerCommand pc = new PowerCommand(PowerCommand.Power.QUERY);

            if (await c.sendCommand(pc) == Command.Response.SUCCESS)
            {
                pi._powerStatus = pc.Status;
            }

            LampStatusCommand lsc = new LampStatusCommand();

            if (await c.sendCommand(lsc) == Command.Response.SUCCESS)
            {
                pi._multiLampStatus = lsc.StatusList;
                pi._multiLampHours  = lsc.HoursList;
                pi._numOfLamps      = lsc.NumOfLamps;
            }

            InputCommand ic = new InputCommand();

            if (await c.sendCommand(ic) == Command.Response.SUCCESS)
            {
                pi._input     = ic.Input;
                pi._inputPort = ic.Port;
            }

            return(pi);
        }
 public ProjectorApp()
 {
     link = new PJLinkConnection(host, password);
 }
        public static ProjectorInfo create(PJLinkConnection c)
        {
            ProjectorInfo pi = new ProjectorInfo();
            pi._projectorHostName = c.HostName;
            ProjectorNameCommand pnc = new ProjectorNameCommand();
            if (c.sendCommand(pnc) == Command.Response.SUCCESS)
                pi._projectorHostName = pnc.Name;

            ManufacturerNameCommand mnc = new ManufacturerNameCommand();
            if (c.sendCommand(mnc) == Command.Response.SUCCESS)
                pi._projectorManufacturerName = mnc.Manufacturer;

            ProductNameCommand prnc = new ProductNameCommand();
            if (c.sendCommand(prnc) == Command.Response.SUCCESS)
                pi._projectorProductName = prnc.ProductName;

            ErrorStatusCommand esc = new ErrorStatusCommand();
            if (c.sendCommand(esc) == Command.Response.SUCCESS)
            {
                pi._fanStatus = esc.FanStatus;
                pi._lampStatus = esc.LampStatus;
                pi._coverStatus = esc.CoverStatus;
                pi._filterStatus = esc.FilterStatus;
                pi._otherStatus = esc.OtherStatus;
            }

            PowerCommand pc = new PowerCommand(PowerCommand.Power.QUERY);
            if (c.sendCommand(pc) == Command.Response.SUCCESS)
                pi._powerStatus = pc.Status;

            LampStatusCommand lsc = new LampStatusCommand();
            if (c.sendCommand(lsc) == Command.Response.SUCCESS)
            {
                pi._multiLampStatus = lsc.StatusList;
                pi._multiLampHours = lsc.HoursList;
                pi._numOfLamps = lsc.NumOfLamps;
            }

            InputCommand ic = new InputCommand();
            if (c.sendCommand(ic) == Command.Response.SUCCESS)
            {
                pi._input = ic.Input;
                pi._inputPort = ic.Port;
            }

            return pi;
        }
        private async void btnPwr_Click(object sender, RoutedEventArgs e)
        {
            await Task.Run(async() =>
            {
                try
                {
                    await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                    {
                        this.btnPwr.Background = new SolidColorBrush(Colors.LawnGreen);
                        this.btnMute.IsEnabled = false;
                        _timerPowerBlink.Start();
                    });

                    rv.PJLinkConnection c            = connectBeamer();
                    PowerCommand.PowerStatus powStat = PowerCommand.PowerStatus.UNKNOWN;
                    try
                    {
                        powStat = await c.powerQuery();
                    }
                    catch (Exception)
                    {
                        try
                        {
                            powStat = await c.powerQuery();
                        }
                        catch (Exception)
                        {
                        }
                    }
                    switch (powStat)
                    {
                    case PowerCommand.PowerStatus.OFF:
                    case PowerCommand.PowerStatus.COOLING:
                    case PowerCommand.PowerStatus.UNKNOWN:
                        await c.turnOn();
                        await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                        {
                            _timerPowerCheck.Interval = new TimeSpan(0, 0, 5);     //10 sec;
                        });

                        break;

                    case PowerCommand.PowerStatus.ON:
                    case PowerCommand.PowerStatus.WARMUP:
                        await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                        {
                            this.btnPwr.Background = btndefBack;
                            this.btnMute.IsEnabled = false;
                            _timerMuteBlink.Stop();
                            _timerPowerBlink.Stop();
                            btnMute.Background = btndefBack;
                        });
                        await c.turnOff();
                        break;
                    }
                }
                catch (Exception)
                {
                }
            });
        }
        async void _timerPowerCheck_Elapsed(object source, object e)
        {
            await Task.Run(async() =>
            {
                try
                {
                    rv.PJLinkConnection c            = connectBeamer();
                    PowerCommand.PowerStatus powStat = PowerCommand.PowerStatus.UNKNOWN;
                    try
                    {
                        powStat = await c.powerQuery();
                    }
                    catch (Exception)
                    {
                        try
                        {
                            powStat = await c.powerQuery();
                        }
                        catch (Exception)
                        {
                        }
                    }
                    switch (powStat)
                    {
                    case PowerCommand.PowerStatus.OFF:
                    case PowerCommand.PowerStatus.COOLING:
                    case PowerCommand.PowerStatus.UNKNOWN:
                        await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                        {
                            this.btnPwr.Background = btndefBack;
                            this.btnMute.IsEnabled = false;
                            _startupRoundCntr++;
                            if (_timerPowerCheck.Interval == new TimeSpan(0, 0, 5) && powStat != PowerCommand.PowerStatus.UNKNOWN)
                            {
                                _timerPowerCheck.Interval = new TimeSpan(0, 1, 0);     // 1min
                                _startupRoundCntr         = 0;
                                _timerPowerBlink.Stop();
                                this.btnPwr.Background = btndefBack;
                            }
                        });
                        break;

                    case PowerCommand.PowerStatus.ON:
                    case PowerCommand.PowerStatus.WARMUP:
                        await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() =>
                        {
                            this._timerPowerBlink.Stop();
                            this.btnPwr.Background = new SolidColorBrush(Colors.LawnGreen);
                            this.btnMute.IsEnabled = true;
                            AVMuteCommand qcmd     = new AVMuteCommand(AVMuteCommand.Action.QUERYSTATE);
                            if (await c.sendCommand(qcmd) == Command.Response.SUCCESS)
                            {
                                if (qcmd.Status == AVMuteCommand.Action.MUTE)
                                {
                                    _timerMuteBlink.Start();
                                }
                                else
                                {
                                    _timerMuteBlink.Stop();
                                    btnMute.Background = btndefBack;
                                }
                            }
                            _startupRoundCntr++;
                            if (_timerPowerCheck.Interval == new TimeSpan(0, 0, 5) && _startupRoundCntr == 10)
                            {
                                _timerPowerCheck.Interval = new TimeSpan(0, 1, 0);     // 1min
                                _startupRoundCntr         = 0;
                                _timerPowerBlink.Stop();
                                this.btnPwr.Background = new SolidColorBrush(Colors.LawnGreen);
                            }
                        });
                        break;
                    }
                    await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                    {
                        if (_timerPowerCheck.Interval == new TimeSpan(0, 0, 5) && _startupRoundCntr == 10)
                        {
                            _timerPowerCheck.Interval = new TimeSpan(0, 1, 0); // 1min
                            _startupRoundCntr         = 0;
                            _timerPowerBlink.Stop();
                            this.btnPwr.Background = btndefBack;
                        }
                    });
                }
                catch (Exception)
                {
                }
            });
        }
        private async void Page_Loaded(object sender, RoutedEventArgs e)
        {
            if (!LoadConfig())
            {
                tmrTimer.Stop();
                txtTime.Text       = "Invalid Config";
                btnMute.Visibility = Visibility.Collapsed;
                btnPwr.Visibility  = Visibility.Collapsed;
                btnInfo.Visibility = Visibility.Collapsed;
            }
            btndefBack = btnPwr.Background;

            // Hook up the Elapsed event for the timer.
            _timerMuteBlink.Tick += _timerMuteBlink_Elapsed;

            // Set the Interval to 0.5 seconds (500 milliseconds).
            _timerMuteBlink.Interval = new TimeSpan(0, 0, 0, 0, 500);

            _timerPowerCheck.Tick    += _timerPowerCheck_Elapsed;
            _timerPowerCheck.Interval = new TimeSpan(0, 1, 0); // 1min
            _timerPowerCheck.Start();

            _timerPowerBlink.Tick    += _timerPowerBlink_Elapsed;
            _timerPowerBlink.Interval = new TimeSpan(0, 0, 0, 0, 500); // 0.5sec

            rv.PJLinkConnection      c       = connectBeamer();
            PowerCommand.PowerStatus powStat = PowerCommand.PowerStatus.UNKNOWN;
            try
            {
                powStat = await c.powerQuery();
            }
            catch (Exception)
            {
                try
                {
                    powStat = await c.powerQuery();
                }
                catch (Exception)
                {
                }
            }
            switch (powStat)
            {
            case PowerCommand.PowerStatus.OFF:
            case PowerCommand.PowerStatus.COOLING:
            case PowerCommand.PowerStatus.UNKNOWN:
                this.btnPwr.Background = btndefBack;
                this.btnMute.IsEnabled = false;
                break;

            case PowerCommand.PowerStatus.ON:
            case PowerCommand.PowerStatus.WARMUP:
                this.btnPwr.Background = new SolidColorBrush(Colors.LawnGreen);
                this.btnMute.IsEnabled = true;
                try
                {
                    AVMuteCommand qcmd = new AVMuteCommand(AVMuteCommand.Action.QUERYSTATE);
                    if (await c.sendCommand(qcmd) == Command.Response.SUCCESS)
                    {
                        if (qcmd.Status == AVMuteCommand.Action.MUTE)
                        {
                            _timerMuteBlink.Start();
                        }
                        else
                        {
                            _timerMuteBlink.Stop();
                        }
                    }
                }
                catch (Exception)
                {
                }
                break;
            }
        }