Ejemplo n.º 1
0
 private void timer1_Tick(object sender, EventArgs e)
 {
     //定时向子板发送05自动读取命令以收到错误坐标指令
     for (int i = 0; i < childNumList.Count; i++)
     {
         System.Threading.Thread.Sleep(500);
         PortOrder po = new PortOrder(Direction.AB, "05", childNumList[i].ToString(), "", "");
         sp2.Write(hexToString(po.getConnOrder()), 0, hexToString(po.getConnOrder()).Length);
     }
 }
Ejemplo n.º 2
0
 private void radioHand_MouseClick(object sender, MouseEventArgs e)
 {
     strs = "";
     childRandnum = "";
     timer1.Stop();
     timer1.Enabled = false;
     lightSet.ForeColor = Color.Black;
         for (int i = 1; i < 9; i++)
         {
             System.Threading.Thread.Sleep(1000);
             PortOrder po = new PortOrder(Direction.AB, "04", "0" + i, "", "");
             byte[] bt = hexToString(po.getConnOrder());
             sp2.Write(bt, 0, bt.Length);
         }
     RexvData.ReadOnly = false;
     insertButton.Enabled = true;
 }
Ejemplo n.º 3
0
 private void insertButton_Click(object sender, EventArgs e)
 {       
     if (RexvData.Text == "")
     {
         MessageBox.Show("机种号不能为空!请输入机种号");
     }
     else
     {
         for (int i = 0; i < strs.Length; i++) //strs共享的板子数据编号
         {
             System.Threading.Thread.Sleep(2000);
             PortOrder po = new PortOrder(Direction.AB, "03","0"+strs[i],"","");
         byte[] bt = hexToString(po.getConnOrder());
         sp2.Write(bt, 0, bt.Length);
         }
     }
 }
Ejemplo n.º 4
0
        string childRandnum = "";//手动定位成功的子板号
        //扫码枪串口1接收数据
        private void sp_DataReceived(object sender, EventArgs e)
        {
            System.Threading.Thread.Sleep(100);
            this.Invoke((EventHandler)(delegate
            {
                try
                {
                    dataBasePoints = "";
                    lightSet.ForeColor = Color.Black;
                    if (radioAuto.Checked)
                    {
                        childNumList.Clear();
                        RexvData.Text = "";
                        Byte[] rb = new Byte[sp.BytesToRead];
                        UTF8Encoding utf = new UTF8Encoding();
                        sp.Read(rb, 0, rb.Length);//接收到数据从缓冲区以字节数组形式读出来                                                                      
                        string[] ds = utf.GetString(rb).Split(',');
                        string machineNum = ds[0];
                        string pointNumber = ds[1].Substring(0, 2);
                        string adressPoint = ds[1].Substring(2, (ds[1].Length) - 2);
                        string newStyle = Regex.Replace(adressPoint, @"(\w{2})", "$1,").Trim(',');
                        RexvData.Text = machineNum;
                        String sql = "select childNumber,adressNumber from machines where machineId='" + machineNum + "';";
                        MySqlDataReader rder = DataBaseSys.GetDataReaderValue(sql);
                        if (rder.Read())
                        {
                            string[] point = rder[1].ToString().Split(',');//4                      
                            string pointOld = "";
                            for (int i = 0; i < point.Length; i++)
                            {
                                pointOld += point[i];
                            }
                            dataBasePoints = pointOld;
                            string[] pointNums = Regex.Replace(pointOld, @"(\w{4})", "$1,").Trim(',').Split(',');
                            string[] twoPoint = Regex.Replace(adressPoint, @"(\w{4})", "$1,").Trim(',').Split(',');
                            if (!Enumerable.SequenceEqual(pointNums, twoPoint))
                            {
                                MessageBoxButtons messButton1 = MessageBoxButtons.OKCancel;
                                DialogResult dr1 = MessageBox.Show("已有该机种,坐标不一致!需要修改吗?", "提示", messButton1);
                                if (dr1 == DialogResult.OK)//如果点击“确定”按钮
                                {
                                    if (!vip) MessageBox.Show("您没有管理员权限无法修改!");
                                    else
                                    {
                                        string sqlAuto = "update machines set childNumber='" + pointNumber + "' ,adressNumber='" + newStyle + "' where machineId= '" + RexvData.Text + "'";
                                        DataBaseSys.ExecuteNonQuery(sqlAuto);
                                        pointNums = twoPoint;
                                        String sqlUpdate = "select childNumber,adressNumber from machines where machineId='" + RexvData.Text + "';";
                                        MySqlDataReader rderUpdate = DataBaseSys.GetDataReaderValue(sqlUpdate);
                                        rder = rderUpdate;
                                        if (rderUpdate.Read())
                                        {
                                            string[] pointUpdate = rderUpdate[1].ToString().Split(',');//4                      
                                            string pointOldUpdate = "";
                                            for (int i = 0; i < pointUpdate.Length; i++)
                                            {
                                                pointOldUpdate += pointUpdate[i];
                                            }
                                            dataBasePoints = pointOldUpdate;
                                            MessageBox.Show("修改成功!");
                                        }
                                    }
                                }
                            }
                            DataTable dt = new DataTable();
                            dt.Rows.Add();
                            for (int i = 0; i < pointNums.Length; i++)
                            {
                                dt.Columns.Add("P" + (i + 1), System.Type.GetType("System.String"));
                                dt.Rows[0][i] = pointNums[i];
                            }
                            DataSet ds2 = new DataSet();
                            ds2.Tables.Add(dt);
                            //sda.Fill(ds2);
                            dataAdressView1.DataSource = ds2.Tables[0];
                            dataAdressView1.ReadOnly = true;
                            //dataAdressView1.Rows[0].Cells[0].Style.BackColor = Color.Red;

                            //自动模式下解析数据库存放的坐标地址用来与子板通讯
                            string[] adressPointData = rder[1].ToString().Split(',');
                            // string pointNum = msr[0].ToString();
                            string[] adressPoint1 = getChildNum(adressPointData);
                            //adressPoint1 = adressPoint1.Where(sP => !string.IsNullOrEmpty(sP)).ToArray();
                            for (int i = 0; i < adressPoint1.Length; i++)
                            {
                                if (!string.IsNullOrEmpty(adressPoint1[i]))
                                {
                                    PortOrder po = new PortOrder(Direction.AB, "02", "0" + (i + 1), "0" + adressPoint1[i].Length / 4, adressPoint1[i]);
                                    childNumList.Add("0" + (i + 1));
                                    sp2.Write(hexToString(po.getConnOrder()), 0, hexToString(po.getConnOrder()).Length);
                                }
                            }
                            //定时向子板发送05自动读取命令以收到错误坐标指令
                            timer1.Enabled = true;
                            timer1.Start();
                        }
                        else
                        {
                            MessageBoxButtons messButton = MessageBoxButtons.OKCancel;
                            DialogResult dr = MessageBox.Show("检测到是新机种!确定添加吗?", "提示", messButton);
                            if (dr == DialogResult.OK)//如果点击“确定”按钮
                            {
                                try
                                {
                                    string addSql = "insert into machines(machineId,childNumber,adressNumber) values('" + machineNum + "','" + pointNumber + "','" + newStyle + "')";
                                    DataBaseSys.ExecuteNonQuery(addSql);
                                    MessageBox.Show("添加成功!请重新扫描。");
                                }
                                catch (Exception)
                                {
                                    MessageBox.Show("添加失败!");
                                }
                            }
                            else {RexvData.Text = ""; dataAdressView1.DataSource = new DataTable(); }
                            sp.DiscardInBuffer();
                        }
                    }
                }
                catch (Exception x)
                {
                    MessageBox.Show("出现异常错误!" + x.ToString());
                }
            }));
        }