コード例 #1
0
ファイル: MonitorOPCServer.cs プロジェクト: wyh0395/opcserver
        public void shoutdownMonitor()
        {
            try
            {
                listener.Close();
            }
            catch (Exception ex)
            {
            }

            try
            {
                listeningThread.Abort();
            }
            catch (Exception ex)
            {
            }

            try
            {
                if (timeoutCheckingThread != null)
                {
                    timeoutCheckingThread.Abort();
                }
            }
            catch (Exception ex)
            {
            }

            try
            {
                if (sendCommandThread != null)
                {
                    sendCommandThread.Abort();
                }
            }
            catch (Exception ex)
            {
            }

            dbNameMapping.Clear();
            alertTable = null;
            labels.Clear();
            handles.Clear();
            lastUpdate.Clear();
            lastUpdateData.Clear();
            onlineLabel.Clear();
            currentOutputValue.Clear();
            try
            {
                opc.unRegisterOPCServer();
            }
            catch (Exception ex)
            {
            }

            server = null;
            LogUtil.writeLog(LogUtil.getFileName(), "[" + DateTime.Now.ToString() + "]: 关闭监控");
        }
コード例 #2
0
ファイル: MonitorOPCServer.cs プロジェクト: wyh0395/opcserver
 public static MonitorOPCServer getInstance()
 {
     if (server == null)
     {
         server = new MonitorOPCServer();
     }
     return(server);
 }
コード例 #3
0
        public static void saveAlertPacketContentToDb(PacketData data)
        {
            string rtu       = data.moduleID;
            string tableName = MonitorOPCServer.getInstance().alertTable;

            if (tableName == null)
            {
                return;
            }

            string sql = string.Format("insert into [{0}]" +
                                       "(rtu,[time],alertPosition,alertValue) values('{1}','{2}',{3},{4}", tableName,
                                       data.moduleID, data.sendTime, data.alertPos, data.alertValue);
            DBUtil db = new DBUtil();

            db.executeNonQuerySQL(sql);
        }
コード例 #4
0
ファイル: Main.cs プロジェクト: wyh0395/opcserver
        private void button1_Click(object sender, EventArgs e)
        {
            MonitorOPCServer monitorServer = MonitorOPCServer.getInstance();
            string           ip            = this.textBox1.Text;
            int port = -1;

            try
            {
                port = Convert.ToInt32(this.textBox2.Text);
            }
            catch (Exception ex)
            {
                MessageBox.Show("端口需要填写一个数字");
                return;
            }

            int minute = 0;

            if (this.checkBox1.Checked)
            {
                try
                {
                    minute = Convert.ToInt32(this.textBox3.Text);
                }
                catch (Exception ex)
                {
                    MessageBox.Show("超时时间需要填写一个数字");
                    return;
                }

                if (minute <= 0)
                {
                    MessageBox.Show("超时时间需要填写一个大于0的数字");
                    return;
                }
            }
            bool enableOutput = this.checkBox2.Checked;

            monitorServer.startMonitor(ip, port, minute, enableOutput);
            this.button1.Enabled = false;
            this.button2.Enabled = true;
        }
コード例 #5
0
        public static void savePacketContentToDb(PacketData data)
        {
            string rtu = data.moduleID;

            if (!MonitorOPCServer.getInstance().dbNameMapping.ContainsKey(rtu))
            {
                return;
            }

            string tableName = MonitorOPCServer.getInstance().dbNameMapping[rtu];

            string sql = string.Format("insert into [{0}]" +
                                       "(rtu,[time],dbm,ch1,ch2,ch3,ch4,ch5,ch6,ch7,ch8,ch9,ch10,ch11,ch12,ch13,ch14,ch15,ch16,ch17,ch18) values" +
                                       "('{1}','{2}',{3},{4},{5},{6},{7},{8},{9},{10},{11},{12},{13},{14},{15},{16},{17},{18},{19},{20},{21})", tableName,
                                       data.moduleID, data.sendTime, data.packetDataMap["GPRS-Level"], data.packetDataMap["AI1/AC1"], data.packetDataMap["AI2/AC2"]
                                       , data.packetDataMap["AI3/AC3"], data.packetDataMap["AI4/AC4"], data.packetDataMap["AI5/AC5"], data.packetDataMap["AI6/AC6"]
                                       , data.packetDataMap["DI1"], data.packetDataMap["DI2"], data.packetDataMap["DI3"], data.packetDataMap["DI4"]
                                       , data.packetDataMap["DI5"], data.packetDataMap["DI6"], data.packetDataMap["DO1"], data.packetDataMap["DO2"]
                                       , data.packetDataMap["DO3"], data.packetDataMap["DO4"], data.packetDataMap["DO5"], data.packetDataMap["DO6"]);

            DBUtil db = new DBUtil();

            db.executeNonQuerySQL(sql);
        }
コード例 #6
0
ファイル: Main.cs プロジェクト: wyh0395/opcserver
 private void button2_Click_1(object sender, EventArgs e)
 {
     MonitorOPCServer.getInstance().shoutdownMonitor();
     this.button1.Enabled = true;
     this.button2.Enabled = false;
 }
コード例 #7
0
ファイル: Main.cs プロジェクト: wyh0395/opcserver
 private void Form1_FormClosing(object sender, FormClosingEventArgs e)
 {
     MonitorOPCServer.getInstance().shoutdownMonitor();
 }
コード例 #8
0
 public static MonitorOPCServer getInstance()
 {
     if (server == null)
         server = new MonitorOPCServer();
     return server;
 }
コード例 #9
0
        public void shoutdownMonitor()
        {
            try
            {
                listener.Close();
            }
            catch (Exception ex)
            {
            }

            try
            {
                listeningThread.Abort();
            }
            catch (Exception ex)
            {
            }

            try
            {
                if (timeoutCheckingThread != null)
                {
                    timeoutCheckingThread.Abort();
                }
            }
            catch (Exception ex)
            {
            }

            try
            {
                if (sendCommandThread != null)
                {
                    sendCommandThread.Abort();
                }
            }
            catch (Exception ex)
            {
            }

            dbNameMapping.Clear();
            alertTable = null;
            labels.Clear();
            handles.Clear();
            lastUpdate.Clear();
            lastUpdateData.Clear();
            onlineLabel.Clear();
            currentOutputValue.Clear();
            try
            {
                opc.unRegisterOPCServer();
            }
            catch (Exception ex)
            {
            }

            server = null;
            LogUtil.writeLog(LogUtil.getFileName(), "[" + DateTime.Now.ToString() + "]: 关闭监控");
        }