예제 #1
0
파일: Lib.cs 프로젝트: SchawnnDev/DmxApp
        public void TurnLightsOn()
        {
            //connect to controller if not connected
            ConnectToController();
            Guid queueId = Guid.Empty;
            //queues allow you to segregate events that run in parallel; use Guid.Empty for the shared queue
            //when all effects on a given queue ID (other than Empty) are complete, the queue is deleted
            //and those channels return to off.
            //the Guid.Empty queue is never deleted so allows you set permanent state
            int priority = 1;
            //priority allows you to control the order in which parallel queues are stacked

            //create a random helper
            Random random = new Random();
            //pick a random channel number (note some lights such as DMX RGB lights, smoke machines) etc.
            //require multiple channels to turn the light on
            //for example rgbwae lights have a base address which you set on the back of the light
            //which is RED then you have GREEN, BLUE, WHITE, AMBER, LUMA/BRIGHTNESS, EFFECTS
            //to set the light to aqua, you need to set Base+1 [Green], Base+2 [Blue] and Base+5 [Luma] to 255
            // int channel = random.Next(0, 512);
            int channel = 0;
            //set value to 255 (full on)
            byte channelValue = 18;

            //call the controller to set the value on the queue; this is a permanent set (will stay until you change it)
            DmxController <DMXProUSB> .SetDmxValue(queue : queueId, channel : channel, priority : priority, value : channelValue);
        }
예제 #2
0
파일: Lib.cs 프로젝트: SchawnnDev/DmxApp
 void DMXProUSB_StateChangedHandler(object sender, StateChangedEventArgs e)
 {
     //this handler is called by a different (non UI) thread so if you want to update
     //ui controls you'll need to BeginInvoke
     //get the current DMX values
     var values = DmxController <DMXProUSB> .GetCurrentValues();
 }
예제 #3
0
        static Result ExecuteGet(DmxController dmx, HttpListenerRequest request)
        {
            string error = "";

            for (int i = 0; i < request.QueryString.Count; i++)
            {
                string   key    = request.QueryString.GetKey(i);
                string[] values = request.QueryString.GetValues(i);
                string   name   = "'" + key + "=" + values[values.Length - 1] + "'";
                if (key.StartsWith("ch"))
                {
                    int channel;
                    if (!int.TryParse(key.Substring(2), out channel))
                    {
                        error = "Could not parse channel in argument " + name;
                        break;
                    }
                    if (channel < 0 || channel >= 512)
                    {
                        error = "Invalid channel in argument " + name;
                        break;
                    }
                    int value;
                    if (!int.TryParse(values[values.Length - 1], out value))
                    {
                        error = "Could not parse DMX value in argument " + name;
                        break;
                    }
                    if (value < 0 || value > 255)
                    {
                        error = "Invalid DMX value in argument " + name;
                        break;
                    }
                    try
                    {
                        dmx[channel] = (byte)value;
                    } catch (Exception ex)
                    {
                        return(new Result
                        {
                            Code = HttpStatusCode.InternalServerError,
                            Content = "Error while setting DMX channel " + channel + " to " + value + ": " + ex.Message
                        });
                    }
                }
                else
                {
                    error = "Unrecognized argument: " + name + "<br>";
                    break;
                }
            }
            return(new Result
            {
                Content = error.Length > 0 ? error : "OK",
                Code = error.Length > 0 ? HttpStatusCode.BadRequest : HttpStatusCode.OK
            });
        }
예제 #4
0
 public void Awake()
 {
     controller = GameObject.Find("DMXController").GetComponent <DmxController>();
     ip         = controller.remoteIP;
     universes  = new List <byte[]>()
     {
         universe0, universe1, universe2
     };
 }
예제 #5
0
 public void Awake()
 {
     controller = GameObject.Find("DMXController").GetComponent <DmxController>();
     ip         = controller.remoteIP;
     universes  = new List <byte[]>(numUniverses);
     for (int i = 0; i < numUniverses; i++)
     {
         universes.Add(new byte[512]);
     }
     InitializeRenderTexture();
 }
예제 #6
0
파일: Lib.cs 프로젝트: SchawnnDev/DmxApp
        public void Disconnect()
        {
            if (IsConnected)
            {
                DmxController <DMXProUSB> .SetDefaults(new DmxDefaults());

                //shut down DMX controller
                DmxController <DMXProUSB> .StateChanged -= DMXProUSB_StateChangedHandler;
                DmxController <DMXProUSB> .Dispose();
            }
        }
        public MainWindow()
        {
            InitializeComponent();

            LearningMode = false;

            current_scene    = new Scene("current_scn");
            ChControllerList = new List <ChannelController>();

            SavedScene.Add(new Scene(SCBT01.Name));
            SavedScene.Add(new Scene(SCBT02.Name));
            SavedScene.Add(new Scene(SCBT03.Name));
            SavedScene.Add(new Scene(SCBT04.Name));
            SavedScene.Add(new Scene(SCBT05.Name));
            SavedScene.Add(new Scene(SCBT06.Name));
            SavedScene.Add(new Scene(SCBT07.Name));
            SavedScene.Add(new Scene(SCBT08.Name));
            SavedScene.Add(new Scene(SCBT09.Name));
            SavedScene.Add(new Scene(SCBT10.Name));
            SavedScene.Add(new Scene(SCBT11.Name));
            SavedScene.Add(new Scene(SCBT12.Name));
            SavedScene.Add(new Scene(SCBT13.Name));
            SavedScene.Add(new Scene(SCBT14.Name));
            SavedScene.Add(new Scene(SCBT15.Name));
            SavedScene.Add(new Scene(SCBT16.Name));

            ChControllerList.Add(chControl1);
            ChControllerList.Add(chControl2);
            ChControllerList.Add(chControl3);
            ChControllerList.Add(chControl4);
            ChControllerList.Add(chControl5);
            ChControllerList.Add(chControl6);
            ChControllerList.Add(chControl7);
            ChControllerList.Add(chControl8);
            ChControllerList.Add(chControl9);
            ChControllerList.Add(chControl10);
            ChControllerList.Add(chControl11);
            ChControllerList.Add(chControl12);
            ChControllerList.Add(chControl13);
            ChControllerList.Add(chControl14);
            ChControllerList.Add(chControl15);
            ChControllerList.Add(chControl16);

            for (int i = 0; i < ChControllerList.Count; i++)
            {
                ChControllerList[i].channel = i + 1;
            }

            DmxController.Connect();
        }
        private void ChannelController_DmxValue_Changed(object sender, EventArgs e)
        {
            DmxUserControlLib.ChannelController control;

            if (sender is DmxUserControlLib.ChannelController)
            {
                control = sender as DmxUserControlLib.ChannelController;

                current_scene.setDmxValue(control.channel, control.dmxvalue);

                if (DmxController.IsOpen())
                {
                    DmxController.WriteValue(control.channel, control.dmxvalue);
                }
            }
        }
예제 #9
0
        static Result ExecutePut(DmxController dmx, HttpListenerRequest request)
        {
            if (!request.HasEntityBody || request.ContentLength64 != 1024)
            {
                return(new Result
                {
                    Code = HttpStatusCode.BadRequest,
                    Content = "Expected 1024 ASCII characters encoding 512 bytes of data in request body"
                });
            }
            long n      = request.ContentLength64;
            var  buffer = new byte[1024];

            request.InputStream.Read(buffer, 0, buffer.Length);

            byte[] newData;
            try
            {
                newData = Enumerable.Range(0, 512).Select(i => (byte)(DIGITS[buffer[2 * i]] * 0x10 + DIGITS[buffer[2 * i + 1]])).ToArray();
            } catch (Exception ex)
            {
                return(new Result
                {
                    Code = HttpStatusCode.BadRequest,
                    Content = ex.Message
                });
            }

            try
            {
                dmx.Data = newData;
            } catch (Exception ex)
            {
                return(new DmxServer.Program.Result
                {
                    Code = HttpStatusCode.InternalServerError,
                    Content = "Error setting DMX block data: " + ex.Message
                });
            }

            return(new Result
            {
                Code = HttpStatusCode.OK,
                Content = "OK"
            });
        }
예제 #10
0
파일: Lib.cs 프로젝트: SchawnnDev/DmxApp
        public void ConnectToController()
        {
            if (IsConnected)
            {
                return;
            }
            //you only need to set up limits once; this allows you to lock specific channels to max values, e.g. if they are behind a wall or under the floor and you don't want them heating up and burning

            DmxController <DMXProUSB> .SetLimits(new DmxLimits
            {
                Min = Enumerable.Range(0, 512).Select(c => (byte)0).ToArray(),
                Max = Enumerable.Range(0, 512).Select(c => (byte)255).ToArray(),
            });

            //in a try/catch (can throw)
            try
            {
                //attempt a start
                if (DmxController <DMXProUSB> .Start())
                {
                    //if now connected
                    if (DmxController <DMXProUSB> .Connected)
                    {
                        //attach to handler
                        //note: don't forget to detach this later if you lose connection
                        DmxController <DMXProUSB> .StateChanged += DMXProUSB_StateChangedHandler;
                    }
                    else
                    {
                        Console.WriteLine("DmxController.Start returned [true] but not connected");
                    }
                }
                else
                {
                    Console.WriteLine("DmxController.Start returned [false]");
                }
            }
            catch (Exception ex)
            {
                //exception occurred, failed to connect
                Console.WriteLine("DmxController.Start threw {0}", ex);
            }
        }
예제 #11
0
        static void Main(string[] args)
        {
            if (args.Length != 1 && args.Length != 2)
            {
                Console.Error.WriteLine("Usage: DmxServer <COMM PORT> [<HTTP PORT>]");
                return;
            }

            string dmxPort = args[0];

            Console.WriteLine("Connecting to " + dmxPort);
            var dmx = new DmxController(dmxPort);

            // https://stackoverflow.com/a/27376368/651139
            string localIP;

            using (Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, 0))
            {
                socket.Connect("8.8.8.8", 65530);
                IPEndPoint endPoint = socket.LocalEndPoint as IPEndPoint;
                localIP = endPoint.Address.ToString();
            }

            var    listener = new HttpListener();
            string prefix   = "http://" + localIP + ":" + (args.Length > 1 ? args[1] : "8080") + "/";

            listener.Prefixes.Add(prefix);
            Console.WriteLine("Listening at " + prefix);
            while (true)
            {
                listener.Start();
                var context  = listener.GetContext();
                var request  = context.Request;
                var response = context.Response;

                Result result;
                if (request.HttpMethod == "GET")
                {
                    if (request.Url.AbsolutePath == "/dmx")
                    {
                        result = ExecuteGet(dmx, request);
                    }
                    else if (request.Url.AbsolutePath == "/status")
                    {
                        result = new Result {
                            Code = HttpStatusCode.OK, Content = "DMX ready on " + dmxPort
                        };
                    }
                    else
                    {
                        result = new Result {
                            Code = HttpStatusCode.NotFound, Content = "Path " + request.Url.AbsolutePath + " not found"
                        };
                    }
                }
                else if (request.HttpMethod == "POST")
                {
                    if (request.Url.AbsolutePath == "/dmx")
                    {
                        result = ExecutePut(dmx, request);
                    }
                    else
                    {
                        result = new Result {
                            Code = HttpStatusCode.NotFound, Content = "Path " + request.Url.AbsolutePath + " not found"
                        };
                    }
                }
                else
                {
                    result = new Result
                    {
                        Code    = HttpStatusCode.MethodNotAllowed,
                        Content = request.HttpMethod + " not supported"
                    };
                }

                response.StatusCode = (int)result.Code;
                var buffer = Encoding.UTF8.GetBytes("<html><body>" + result.Content + "</body></html>");
                response.ContentLength64 = buffer.Length;
                var output = response.OutputStream;
                output.Write(buffer, 0, buffer.Length);
                output.Close();
            }
        }
예제 #12
0
파일: Lib.cs 프로젝트: SchawnnDev/DmxApp
 public void SetDmxValue(Guid queueId, DmxValue value, int priority)
 {
     DmxController <DMXProUSB> .SetDmxValue(queueId, value.Channel.Value, priority, value.Value);
 }