public Command_Window()
 {
     InitializeComponent();
     Server = new ServerClass();
     /* Start ProcessDataBuffer Timer */
     /* Start ProcessCommandDataBuffer Timer */
     StartProcessDataTimer();
     StartProcessCommandTimer();
 }
Exemplo n.º 2
0
        public byte[] GetFinalbytesOfCommand(byte[] Deviceid, byte[] Command_Pkt_TypeID, byte[] databytes)
        {
            /* Prepare PacketObject */
            PacketClass PktObj = FramePacketforCommand(Deviceid, Global.Command_KeyCodePkt_TypeID, databytes);
            /* Calculating Length of the PAcket */
            short length = (short)(Global.Packet_Default_length + PktObj.Data.Length);

            PktObj.Packet_Length = BitConverter.GetBytes(length);           // Getting Bytes from checksum.. Length

            ushort Chksum = ServerClass.Calc_ChecksumForCommandObj(PktObj); // Calculates Checksum Of the Packet

            PktObj.Checksum = BitConverter.GetBytes(Chksum);                //Checksum

            PktObj = ServerClass.Reverse_PacketBytes(PktObj);               // Reversing the Object byte[] arrays

            byte[] Final_bytes = ServerClass.PktObjectToByteArray(PktObj);  // Convering Object to byte[] array.

            return(Final_bytes);
        }
Exemplo n.º 3
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                string trimed_port = port_textBox.Text.Trim();
                if (trimed_port == "")
                {
                    // Error Related Port Number cannot be empty.\
                    MessageBox.Show("Port number cannot be empty !!", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
                }
                else // SOme port number has entered.
                {
                    int    portnumber = Convert.ToInt32(trimed_port); // Converting Port  String to Int.
                    string Ip_address = ip_textBox.Text;
                    if (portnumber > 65535)  // I.e Empty port or Port number has greaterthan 65535
                    {
                        MessageBox.Show("Port number should be lessthan 65535!!", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
                        port_textBox.Text = ""; // Setting the Empty text in Port_textbox.
                        port_textBox.Focus();   // to set the port Textbox to be Focused
                    }
                    else                        // Perfect Port Number.
                    {
                        /* Call Start_TcpServer() Method to satrt Tcp Server. */
                        HideBackgroundCntent();
                        Dlg       = new Modal_dlg();
                        Dlg.Owner = Window.GetWindow(this);
                        Server    = new ServerClass();
                        // To Start the TcpListener
                        Server.Initialize_Server(Ip_address, portnumber);   // To Start the Tcp Server.
                        Dlg.ShowDialog();
                        if (Global.Is_Manuallyclosed)
                        {
                            Global.Is_Manuallyclosed = false;
                            Server.ClearAllObbjectsused();
                            // To Show the Background content
                            ShowBackgroundCntent();
                        }
                        else //I.e The Tcp Client has been Connected to the Server , SO you should not stop the Server.
                        {
                            /*
                             * 0. Start the Processing Timer to Process the Data_Buffer.
                             * */

                            Processing_Timer           = new System.Timers.Timer(500); // Checking for evey 0.5 Sec whether any Client Connected or not.
                            Processing_Timer.Elapsed  += new ElapsedEventHandler(Server.ProcessDataBuffer);
                            Processing_Timer.AutoReset = true;
                            Processing_Timer.Enabled   = true;

                            /*
                             *   SendDatatoClient() Should be accessible from outside
                             * 1. Close the MainWindow
                             * 2. Display the  Commands Window
                             *
                             * /*/
                        }
                    }

                    // Should close the Main Form & Will Another Form can be Shown.
                }
            }
            catch (Exception ex)
            {
                DateTime now_time = DateTime.Now;
                string   time     = Convert.ToString(now_time);
                Global.AppendTexttoFile(Global.exception_filepath, "Exception Ocuured On Main Form Connect Click:  " + ex.Message + time); // Logging the Execptions Ocuured
            }
        }