Exemplo n.º 1
0
        /// <summary>
        /// Update Log
        /// </summary>
        /// <param name="status">Communication status</param>
        public void updateLog(comStatus status)
        {
            // ----- IF CONNECTION CLOSE -----
            if (status == comStatus.Close)
            {
                if (com.OpenInterface == Comm.interfaces.TCPClient || com.OpenInterface == Comm.interfaces.None)
                {
                    Disconnect();
                }
                else if (com.OpenInterface == Comm.interfaces.TCPServer)
                {
                    lblStatus.Text = "Server: Client disconnected";
                    //Log.add("Client disconnected");
                }
            }
            // ----- IF RECEIVED DATA -----
            else if (status == comStatus.OK)
            {
                TimeOut.Enabled = false;    // enable TimeOut timer (wait 40ms for next message)
                TimeOut.Enabled = true;

                // ----- ADD NEW DATA TO BUFFER -----
                byte[] newBytes = com.Read();
                if (newBytes.Length > 0)
                {
                    PrevData  = com.AddArray(PrevData, newBytes);
                    comBuffer = PrevData;
                }
            }
            // ----- IF CONNECTION OPENED -----
            else if (status == comStatus.Open)
            {
                if (com.OpenInterface == Comm.interfaces.TCPClient)
                {
                    //NetConnected();
                }
                else if (com.OpenInterface == Comm.interfaces.TCPServer)
                {
                    lblStatus.Text = "Server: Client connected";
                    //Log.add("Client connected");
                }
            }
            // ----- IF OPEN ERROR -----
            else if (status == comStatus.OpenError)
            {
                Dialogs.ShowErr("Connection Timeout", "Error");
            }
        }