예제 #1
0
        /// <summary>
        /// easymodbus连接PLC
        /// </summary>
        /// <returns></returns>
        //private bool ModbusConnect()
        //{
        //    try
        //    {
        //        string ip = "192.168.10.7";
        //        PLC_ModbusClient = new ModbusClient(ip, 502);
        //        PLC_ModbusClient.Connect();

        //        if (PLC_ModbusClient.Connected)
        //        {
        //            return true;
        //        }
        //        else
        //        {
        //            return false;
        //        }
        //    }
        //    catch (Exception ex)
        //    {
        //
        //        return false;
        //    }
        //}



        private DataTable GetHomingAxisInfoByAxisID(int axisID)
        {
            DataTable           DT_Temp             = new DataTable();
            MySqlConnectionHelp mySqlConnectionHelp = new MySqlConnectionHelp();
            MySqlConnection     mySqlConnection     = mySqlConnectionHelp.GetMySqlCon();
            string       sql          = "select * from sp_axis_homing_info where Axis_ID = " + axisID;
            MySqlCommand mySqlCommand = new MySqlCommand(sql, mySqlConnection);

            DT_Temp = mySqlConnectionHelp.GetDataSet(mySqlCommand).Tables[0];
            mySqlConnectionHelp.CloseConn(mySqlConnection);

            return(DT_Temp);
        }
예제 #2
0
        private void AlarmRecord(bool hasTemplet, string alarmType, string alarmInfo)
        {
            MySqlConnectionHelp mySqlConnectionHelp = new MySqlConnectionHelp();
            MySqlConnection     mySqlConnection     = mySqlConnectionHelp.GetMySqlCon();
            string sql;

            if (hasTemplet)
            {
                if (this.comboBox_selectProduct.SelectedIndex > -1 && this.comboBox_selectProduct.Text != "System.Data.DataRowView")
                {
                    int    templetId;
                    string templetName = "";
                    bool   isNum       = int.TryParse(this.comboBox_selectProduct.SelectedValue.ToString(), out templetId);
                    templetName = this.comboBox_selectProduct.Text;
                    if (isNum)
                    {
                        sql = "insert into sp_alarm_info(Templet_ID,Templet_Name,Alarm_Type,Alarm_Info,Alarm_Time,Alarm_Date)" +
                              " values( '" + templetId + "' , '" + templetName + "' ,'" + alarmType + "' ,'" + alarmInfo + "' ,'" + DateTime.Now + "' ,'" + DateTime.Now.Date + "' )";
                    }
                    else
                    {
                        sql = "insert into sp_alarm_info(Alarm_Type,Alarm_Info,Alarm_Time,Alarm_Date)" +
                              " values( '" + alarmType + "' ,'" + alarmInfo + "' ,'" + DateTime.Now + "' ,'" + DateTime.Now.Date + "' )";
                    }
                }
                else
                {
                    sql = "insert into sp_alarm_info(Alarm_Type,Alarm_Info,Alarm_Time,Alarm_Date)" +
                          " values( '" + alarmType + "' ,'" + alarmInfo + "' ,'" + DateTime.Now + "' ,'" + DateTime.Now.Date + "' )";
                }
            }
            else
            {
                sql = "insert into sp_alarm_info(Alarm_Type,Alarm_Info,Alarm_Time,Alarm_Date)" +
                      " values( '" + alarmType + "' ,'" + alarmInfo + "' ,'" + DateTime.Now + "' ,'" + DateTime.Now.Date + "' )";
            }


            MySqlCommand mySqlCommand     = new MySqlCommand(sql, mySqlConnection);
            int          returnCode_Mysql = mySqlCommand.ExecuteNonQuery();//3.执行插入、删除、更改语句。执行成功返回受影响的数据的

            mySqlConnectionHelp.CloseConn(mySqlConnection);
            if (returnCode_Mysql <= 0)
            {
                MessageBox.Show("报警信息保存失败");
                return;
            }
        }
예제 #3
0
        private DataTable GetHomingAxisInfoByAxisID()
        {
            try
            {
                DataTable           DT_Temp             = new DataTable();
                MySqlConnectionHelp mySqlConnectionHelp = new MySqlConnectionHelp();
                MySqlConnection     mySqlConnection     = mySqlConnectionHelp.GetMySqlCon();
                string       sql          = " select * from sp_axis_homing_info  ";
                MySqlCommand mySqlCommand = new MySqlCommand(sql, mySqlConnection);
                DT_Temp = mySqlConnectionHelp.GetDataSet(mySqlCommand).Tables[0];
                mySqlConnectionHelp.CloseConn(mySqlConnection);

                return(DT_Temp);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return(null);
            }
        }
예제 #4
0
        private int GetTempletIDByTempletName(string templetName)
        {
            try
            {
                DataTable           dataTable           = new DataTable();
                MySqlConnectionHelp mySqlConnectionHelp = new MySqlConnectionHelp();
                MySqlConnection     mySqlConnection     = mySqlConnectionHelp.GetMySqlCon();
                string       sql          = "select * from sp_templet_info where Templet_Name =  '" + templetName + "'";
                MySqlCommand mySqlCommand = new MySqlCommand(sql, mySqlConnection);
                dataTable = mySqlConnectionHelp.GetDataSet(mySqlCommand).Tables[0];
                mySqlConnectionHelp.CloseConn(mySqlConnection);

                return((int)dataTable.Rows[0]["Templet_ID"]);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return(0);
            }
        }
예제 #5
0
        //检查数据库连接异常
        private bool CheackDBLink()
        {
            try
            {
                MySqlConnectionHelp mySqlConnectionHelp = new MySqlConnectionHelp();
                MySqlConnection     mySqlConnection     = mySqlConnectionHelp.GetMySqlCon();

                DataTable    dt           = new DataTable();
                string       sql          = "select * from tk_plc";
                MySqlCommand mySqlCommand = new MySqlCommand(sql, mySqlConnection);
                dt = mySqlConnectionHelp.GetDataSet(mySqlCommand).Tables[0];

                MainForm.PLC_IP = dt.Rows[0]["PLC_IP"].ToString();


                mySqlConnectionHelp.CloseConn(mySqlConnection);
                return(true);
            }
            catch (Exception ex)
            {
                this.richTextBox_Load.AppendText(DateTime.Now + " " + ex.Message + "\n");
                return(false);
            }
        }