public void Set_value_R_DT(string value) { // 将DT或R的值改变 string com_info = mv.myportconfig.port_info.IniReadValue("COM_info", machine_num.ToString() + "号机"); port_moudbus myport = null; if (com_info == "com1") { myport = mv.myportconfig.mysp1; } if (com_info == "com2") { myport = mv.myportconfig.mysp2; } string key_string = machine_num.ToString() + "_" + value_name.ToString(); if (mv != null) { try { DataSet ds = mv.mysqlconnection.sql_search_database("Select * from data_table where data_name='" + key_string.ToString() + "'"); // ok DataRow dr = ds.Tables[0].Rows[0]; string type_string = dr[1].ToString(); string address_value = dr[2].ToString(); // 计算地址 int length = address_value.Length; int last_num = 0; if (length > 1) { string address_string = address_value.Substring(1, length - 1); //16进制处理 int int_length = address_string.Length; string last_string = address_string.Substring(int_length - 1, 1); last_num = Convert.ToInt32(last_string, 16); } else if (length == 1) { last_num = Convert.ToInt32(address_value, 16); } int qianmian = 0; try { qianmian = int.Parse(address_value.Substring(0, length - 1)); } catch { qianmian = 0; } int address = qianmian * 16 + last_num; // if (type_string == "R") { myport.Send_Write_Cmd5(Machine_num, (2048 + address).ToString("X").PadLeft(4, '0'), value); } } catch { } } }
private void Reset_Port_combo(ComboBox mycb, port_moudbus mypm) { mycb.Items.Clear(); for (int i = 1; i <= 20; i++) { try { mypm.sp.PortName = "COM" + i.ToString(); mypm.sp.Open(); mycb.Items.Add("COM" + i.ToString()); mypm.sp.Close(); } catch { } } }
private void myButton_start_Click(object sender, EventArgs e) { //只是暂时的,到时候要加入下载信息 // 首先相应的机号的端口号 try { Port_config.canxunjian = false; step = 0; string com_info = mv.myportconfig.port_info.IniReadValue("COM_info", machine_num.ToString() + "号机"); myport = null; if (com_info == "com1") { myport = mv.myportconfig.mysp1; } if (com_info == "com2") { myport = mv.myportconfig.mysp2; } label_step.Text = "开始下载工艺……"; // 取得要下载的数据 datalength = dataGridView1.Rows.Count; //int[] data_2000 = new int[datalength]; //int[] data_2500 = new int[datalength]; //int[] data_3000 = new int[datalength]; //int[] data_3500 = new int[datalength]; data_2000 = (int[])Redim(data_2000, datalength); data_2500 = (int[])Redim(data_2500, datalength); data_3000 = (int[])Redim(data_3000, datalength); data_3500 = (int[])Redim(data_3500, datalength); for (int i = 0; i < dataGridView1.Rows.Count; i++) { DataSet ds = mv.mysqlconnection.sql_search_database("select * from craft_machine" + machine_num.ToString()); int row_count = ds.Tables[0].Rows.Count; DataRow craftrow = null; //最后一行 if (row_count > 0) { craftrow = ds.Tables[0].Rows[row_count - 1]; } // 寻找温控的工艺代码 int code = 0; try { ds = mv.mysqlconnection.sql_search_database("select craft_code from craftcode where craft_name='" + dataGridView1[4, i].Value.ToString().Trim() + "'"); DataRow dr = ds.Tables[0].Rows[0]; code = int.Parse(dr[0].ToString()); //在工艺列表里找到 } catch { code = int.Parse(dataGridView1[4, i].Value.ToString()); } data_2000[i] = int.Parse(dataGridView1[1, i].Value.ToString()); data_2500[i] = int.Parse(dataGridView1[3, i].Value.ToString()); data_3000[i] = code; data_3500[i] = int.Parse(dataGridView1[5, i].Value.ToString()); } progressBar1.Value = 10; myport.Send_Write_Cmd16(machine_num, datalength, "07D0", data_2000); timer3.Enabled = true; // //label_step.Text = "下载进度1"; // progressBar1.Value = 20; // myport.Send_Write_Cmd16(machine_num, datalength, "09C4", data_2500); //// label_step.Text = "下载进度2"; // progressBar1.Value = 30; // myport.Send_Write_Cmd16(machine_num, datalength, "0BB8", data_3000); //// label_step.Text = "下载进度3"; // progressBar1.Value = 40; // myport.Send_Write_Cmd16(machine_num, datalength, "0DAC", data_3500); //// label_step.Text = "下载进度4"; // progressBar1.Value = 70; // myButton_start.Set_value_R_DT("ff00"); // Thread.Sleep(800); // if (step == 4) { progressBar1.Value = 100; } // else { MessageBox.Show("请检查下载情况!"); } // step = 0; //开始时间信息 DateTime dt = DateTime.Now; string nowtime = dt.ToString("yyyyMMddHHmmss"); string nowstart_time = dt.ToString("yyyy-MM-dd HH:mm:ss"); mv.mysqlconnection.excute_sql("update start_time set start_time='" + nowstart_time + "' where machine_num='" + machine_num.ToString() + "'"); try { mv.mysqlconnection.excute_sql("Create table info" + machine_num.ToString() + nowtime + "(duanhao int primary key,endtime datetime,data1 nvarchar(50),data2 nvarchar(50),data3 nvarchar(50),data4 nvarchar(50))"); } catch { } // draw_line(); // label_step.Text = ""; // save_info(); // progressBar1.Value = 0; // step = 0; //// MessageBox.Show("下载完成!"); } catch (Exception ex) { MessageBox.Show("通讯错误!"); progressBar1.Value = 0; } }