Example #1
0
        public static void SendMatrixCmd(MatrixCmd matrixCmd)
        {
            LogCtrl.Status(matrixCmd.description);
            Thread thread = new Thread(() => ExecuteMatrixCmd(matrixCmd));

            thread.Start();
        }
Example #2
0
        private static void MatrixPresetButton_Click(object sender, RoutedEventArgs e)
        {
            string s = InputDialogCtrl.Show("Enter preset number");

            if (s != null)
            {
                int preset;
                if (int.TryParse(s, out preset))
                {
                    MatrixCmd cmdBuff = MatrixCmd.getMatrixCmd("P" + preset);
                    SendMatrixCmd(cmdBuff);
                }
                else
                {
                    DialogCtrl.Show(DialogType.ERROR, OptionType.OKCANCEL, "Can't load preset!", "You entered an invalid preset number.");
                }
            }
        }
Example #3
0
        private static void ExecuteMatrixCmd(MatrixCmd matrixCmd)
        {
            using (TcpClient client = new TcpClient())
            {
                IAsyncResult ar = client.BeginConnect(ip, 10001, null, null);
                WaitHandle   wh = ar.AsyncWaitHandle;
                try
                {
                    if (!ar.AsyncWaitHandle.WaitOne(TimeSpan.FromSeconds(5), false))
                    {
                        LogCtrl.ThreadSafeError("Matrix: Can't connect");
                        return;
                    }

                    Stream stm = client.GetStream();
                    byte[] bb  = new byte[9];
                    stm.Write(matrixCmd.message, 0, matrixCmd.message.Length);
                    stm.Read(bb, 0, 9);

                    if (Encoding.UTF8.GetString(bb).Trim() == matrixCmd.response)
                    {
                        LogCtrl.ThreadSafeSuccess(matrixCmd.successText);
                    }
                    else
                    {
                        LogCtrl.ThreadSafeError(matrixCmd.failText);
                    }

                    client.EndConnect(ar);
                }
                catch (Exception e)
                {
                    LogCtrl.ThreadSafeError("Matrix: Error connecting.");
                    LogCtrl.ThreadSafeError(e.Message);
                }
                finally
                {
                    wh.Close();
                }
            }
        }