Пример #1
0
        private void btnStartLine_Click(object sender, EventArgs e)
        {
            PLC.setM(PLC_SLOT_Y3, 1);
            var data = PLC.GetPLCData();

            writeLog("发出生产线启动命令");
        }
Пример #2
0
        /// <summary>
        /// 处理相机读到的号码。
        /// </summary>
        /// <param name="barcode"></param>
        private bool HandleBarCode(string barcode)
        {
            var num = InputItem(barcode);

            if (iLastStatus != num)
            {
                try {
                    iLastStatus = num;
                    lock (LOCK_PLC) {
                        PLC.setM("R0", (num == 0) ? 1 : 0);
                    }
                    WriteFile(lblBarCode.Text + iLastStatus.ToString());
                } catch (Exception ex) {
                    WriteFile("HandleBarCode启动PLC出错!错误为:" + ex.Message);
                }
            }

            showLineInfo(num);
            return(num == 0);
        }
Пример #3
0
        private void showLineInfo(int status)
        {
            lock (LOCK_PLC) {
                Invoke((MethodInvoker) delegate {
                    switch (status)
                    {
                    case 1:
                        lblResult.Text = "当前商品已经装满,请装其它商品!";
                        PLC.setM("Y6", 1);
                        break;

                    case 2:
                        lblResult.Text = "当前商品未装满,不允许装其它商品!";
                        PLC.setM("Y7", 1);
                        break;

                    case 3:
                        lblResult.Text = "重量不合格!";
                        PLC.setM("Y4", 1);
                        break;

                    case -1:
                        lblResult.Text = "号码异常!";
                        PLC.setM("Y5", 1);
                        break;

                    default:
                        lblResult.Text = "";
                        PLC.setM("Y5", 0);
                        PLC.setM("Y6", 0);
                        PLC.setM("Y7", 0);
                        PLC.setM("Y4", 0);
                        break;
                    }
                });
            }
        }
Пример #4
0
 private void btnStop_Click(object sender, EventArgs e)
 {
     stopCameraReading();
     PLC.setM(PLC_SLOT_Y0, 0);
 }
Пример #5
0
 private static void PlcStartLine()
 {
     PLC.setM(PLC_SLOT_Y0, 1);
     PLC.GetPLCData();
 }
Пример #6
0
        private void openExcel()
        {
            var text = "";
            var num  = 0;

            openFile.Filter = "Excel Files|*.xls;*.xlsx";
            if (openFile.ShowDialog() == DialogResult.OK)
            {
                text = openFile.FileName;
            }
            if (text == "")
            {
                return;
            }
            strFilePath  = text;
            iTotalNumber = 0;
            try {
                var dataSet = ToDataTable(text);
                if (dataSet.Tables.Count != 0)
                {
                    var dataTable  = dataSet.Tables[0];
                    var dataTable2 = new DataTable();
                    if (dataTable != null)
                    {
                        lblBoxNo.Text   = dataTable.Rows[2][14].ToString();
                        strCurrentBoxNo = lblBoxNo.Text;
                        dataTable2.Columns.Add("EVNo");
                        dataTable2.Columns.Add("Number", typeof(int));
                        dataTable2.Columns.Add("Already", typeof(int));
                        dataTable2.Columns.Add("GrossWt", typeof(decimal));
                        dataTable2.Columns.Add("WtTolerance", typeof(decimal));
                        var fileName = GetFileName();
                        if (File.Exists(fileName))
                        {
                            if (MessageBox.Show("当前柜已有装柜记录,是否继续之前的装柜?", "重要提示", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == DialogResult.Yes)
                            {
                                var dataSet2 = ToDataTable(fileName);
                                if (dataSet2.Tables.Count == 0)
                                {
                                    MessageBox.Show("此文件数据已经被修改,无法正确加载!请删除\r\n" + fileName + " 后再打开!", "重要提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                                    return;
                                }
                                var dataTable3 = dataSet2.Tables[lblBoxNo.Text + "$"];
                                var num2       = 0;
                                var num3       = 0;
                                var text2      = "";
                                for (int i = 0; i < dataTable3.Rows.Count; i++)
                                {
                                    var dataRow = dataTable3.Rows[i];
                                    if (dataRow[0].ToString() == "")
                                    {
                                        break;
                                    }
                                    var num4     = int.Parse(dataRow[1].ToString());
                                    var num5     = int.Parse(dataRow[2].ToString());
                                    var dataRow2 = dataTable2.NewRow();
                                    dataRow2["EVNo"]        = dataRow[0].ToString();
                                    dataRow2["Number"]      = num4;
                                    dataRow2["Already"]     = num5;
                                    dataRow2["GrossWt"]     = dataRow[3];
                                    dataRow2["WtTolerance"] = dataRow[4];
                                    if (num4 > num5 & num5 > 0 & num3 == 0)
                                    {
                                        num2          = num4;
                                        num3          = num5;
                                        text2         = dataRow[0].ToString();
                                        iCurrentIndex = i;
                                    }
                                    num += int.Parse(dataRow[2].ToString());
                                    dataTable2.Rows.Add(dataRow2);
                                }
                                lblBarCode.Text           = text2;
                                lblCurrentNeedNumber.Text = num2.ToString();
                                lblCurrentNumber.Text     = num3.ToString();
                                lblAlreadyNumber.Text     = num.ToString();
                            }
                            else
                            {
                                System.IO.File.Delete(fileName);
                                lblBarCode.Text           = "";
                                lblCurrentNeedNumber.Text = "0";
                                lblCurrentNumber.Text     = "0";
                                lblAlreadyNumber.Text     = "0";
                                for (int j = 6; j < dataTable.Rows.Count; j++)
                                {
                                    var dataRow = dataTable.Rows[j];
                                    if (dataRow[0].ToString() == "")
                                    {
                                        break;
                                    }
                                    var dataRow2 = dataTable2.NewRow();
                                    dataRow2["EVNo"]        = dataRow[2].ToString();
                                    dataRow2["Number"]      = int.Parse(dataRow[7].ToString());
                                    dataRow2["Already"]     = 0;
                                    dataRow2["GrossWt"]     = decimal.Parse(dataRow[18].ToString());
                                    dataRow2["WtTolerance"] = decimal.Parse(dataRow[19].ToString());
                                    dataTable2.Rows.Add(dataRow2);
                                }
                            }
                        }
                        else
                        {
                            for (int k = 6; k < dataTable.Rows.Count; k++)
                            {
                                var dataRow = dataTable.Rows[k];
                                if (dataRow[2].ToString() == "")
                                {
                                    break;
                                }
                                var dataRow2 = dataTable2.NewRow();
                                dataRow2["EVNo"]        = dataRow[2].ToString();
                                dataRow2["Number"]      = int.Parse(dataRow[7].ToString());
                                dataRow2["Already"]     = 0;
                                dataRow2["GrossWt"]     = decimal.Parse(dataRow[18].ToString());
                                dataRow2["WtTolerance"] = decimal.Parse(dataRow[19].ToString());
                                dataTable2.Rows.Add(dataRow2);
                            }
                        }
                        gvData.DataSource = dataTable2;
                        gvData.Columns[0].HeaderCell.Value           = "EV号码";
                        gvData.Columns[1].HeaderCell.Value           = "箱数";
                        gvData.Columns[2].HeaderCell.Value           = "已装箱数";
                        gvData.Columns[3].HeaderCell.Value           = "毛重(kg)";
                        gvData.Columns[4].HeaderCell.Value           = "毛重公差(kg)";
                        gvData.Columns[0].Width                      = 125;
                        gvData.Columns[1].Width                      = 90;
                        gvData.Columns[2].Width                      = 90;
                        gvData.Columns[3].Width                      = 90;
                        gvData.Columns[4].Width                      = 130;
                        gvData.Columns[1].DefaultCellStyle.Alignment = DataGridViewContentAlignment.BottomRight;
                        gvData.Columns[2].DefaultCellStyle.Alignment = DataGridViewContentAlignment.BottomRight;
                        gvData.Columns[3].DefaultCellStyle.Alignment = DataGridViewContentAlignment.BottomRight;
                        gvData.Columns[3].DefaultCellStyle.Format    = "f4";
                        gvData.Columns[4].DefaultCellStyle.Alignment = DataGridViewContentAlignment.BottomRight;
                        gvData.Columns[4].DefaultCellStyle.Format    = "f6";
                        if (gvData.Rows.Count > 0 & num > 0)
                        {
                            gvData.Rows[iCurrentIndex].Selected = true;
                        }

                        lblResult.Text = "";

                        lock (LOCK_PLC) {
                            PLC.setM("Y5", 0);
                            PLC.setM("Y6", 0);
                            PLC.setM("Y7", 0);
                        }

                        writeLog("加载Excel完毕。");
                    }
                }
            } catch (Exception ex2) {
                WriteFile("加载Excel数据出错,请检查Excel格式是否正确!" + ex2.Message);
                MessageBox.Show("加载Excel数据出错,请检查Excel格式是否正确!", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Hand);
            }
        }