コード例 #1
0
        private void AddLogLine(string txt)
        {
            try
            {
                if (string.IsNullOrEmpty(txt))
                {
                    return;
                }

                if (EventsLog.Lines.Count() >= 13)
                {
                    this.SuspendLayout();
                    var lines = new string[13];
                    for (int i = 1; i < EventsLog.Lines.Count(); i++)
                    {
                        lines[i - 1] = EventsLog.Lines[i];
                    }
                    lines[EventsLog.Lines.Count() - 1] = txt;
                    EventsLog.Clear();
                    EventsLog.Lines = lines;
                    this.ResumeLayout();
                }
                else
                {
                    EventsLog.AppendText(txt + Environment.NewLine);
                }
            }
            catch
            {
            }
        }
コード例 #2
0
ファイル: MainForm.cs プロジェクト: yuanhuihai/CSharp
        private void LogTimer_Tick(object sender, EventArgs e)
        {
            // For event logging this method (a timer and PickEvent) is better than
            // the events callback used into the Server console demo.
            // Here we are using the internal Server message queue without
            // disturbing the client handshake.
            while (Server.PickEvent(ref Event))
            {
                if (EventsLog.Lines.Count() > 256)
                {
                    EventsLog.Clear();
                }
                EventsLog.AppendText(Server.EventText(ref Event) + "\n");

                // Example of how use the parameters inside the event struct.
                // Here we check if our DB were changed and, if yes, update the
                // related textbox.


//                if ((Event.EvtCode == S7Server.evcDataWrite) &&   // write event
//                   (Event.EvtRetCode == 0) &&                    // succesfully
//                    (Event.EvtParam1 == S7Server.S7AreaDB))       // it's a DB

                if ((Event.EvtCode == S7Server.evcDataWrite) &&   // write event
                    (Event.EvtRetCode == 0))
                {
                    switch (Event.EvtParam2)
                    {
                    case 1: HexDump(DB1_Box, DB1, DB1.Length);
                        break;

                    case 2: HexDump(DB2_Box, DB2, DB2.Length);
                        break;

                    case 3: HexDump(DB3_Box, DB3, DB3.Length);
                        break;
                    }
                }
            }
        }