Exemplo n.º 1
0
 public void OnDataChange(int dwTransid, int hGroup, int hrMasterquality, int hrMastererror, int dwCount, int[] phClientItems, object[] pvValues, short[] pwQualities, OpcRcw.Da.FILETIME[] pftTimeStamps, int[] pErrors)
 {
     ThreadExceptionDialog.CheckForIllegalCrossThreadCalls = false;
     try
     {
         for (int i = 0; i < dwCount; i++)
         {
             if (pErrors[i] == 0)
             {
                 deviceStatus[phClientItems[i] - 1] = int.Parse(pvValues[i].ToString());
                 RefreshDisplay(phClientItems[i] - 1);
             }
         }
     }
     catch (System.Exception error)
     {
         mainFrm.AddErrToListView(String.Format("更新急停按钮状态失败:-{0}", error.Message));
         LogHelper.LogSimlpleString(DateTime.Now.ToString() + String.Format("更新急停按钮状态失败:-{0}", error.Message));
         //MessageBox.Show(String.Format("更新急停按钮状态失败:-{0}", error.Message),
         //    "连接失败", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
Exemplo n.º 2
0
 /// <summary>
 /// 打开Socket
 /// </summary>
 public void OpenSocket(string IP_Server, string Port_Receive)
 {
     try
     {
         socket_client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
         IPAddress  ipAddress = IPAddress.Parse(IP_Server);
         IPEndPoint ipe       = new IPEndPoint(ipAddress, int.Parse(Port_Receive));
         socket_client.Connect(ipe);
         SocketConnectFlag = true;
         // mainFrm.lblSannerStatus.Text = "初始化读码器成功";
         mainFrm.AddSuccessToListView("初始化读码器" + IP_Server + "成功");
         LogHelper.LogSimlpleString(DateTime.Now.ToString("G") + "初始化读码器" + IP_Server + "成功");
     }
     catch (Exception ex)
     {
         SocketConnectFlag = false;
         //mainFrm.lblSannerStatus.Text = "初始化读码器失败";
         mainFrm.AddErrToListView("初始化读码器" + IP_Server + "失败!异常:" + ex.Message);
         LogHelper.LogSimlpleString(DateTime.Now.ToString("G") + "初始化读码器" + IP_Server + "失败!异常:" + ex.Message);
         return;
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// 扫描核对分流,需要对任务进行拆分
        /// </summary>
        /// <param name="row"></param>
        /// <returns></returns>
        public bool SmflTaskPress()
        {
            if (returnTaskStatus != "10")
            {
                return(true); //不在可写入新任务状态,直接返回
            }
            DataSet ds_dev = new DataSet();

            if (scannerNo.Length < 2)
            {
                return(true);
            }
            string bzwms = "";



            //初始化命令设备
            MySqlConnection dbConn1;

            dbConn1 = new MySqlConnection(mainFrm.dbConnectionString);
            dbConn1.Open();

            MySqlConnection dbConnwms;

            dbConnwms = new MySqlConnection(mainFrm.dbConnectionStringWms);
            dbConnwms.Open();

            ds_dev      = MySqlHelper.ExecuteDataset(dbConn1, "select BARCODE from td_wcs_barcode where SCNNER_NO ='" + scannerNo + "'");
            currBarCode = ds_dev.Tables[0].Rows[0][0].ToString();
            if (currBarCode.Length < 2)
            {
                dbConn1.Close();
                dbConnwms.Close();
                return(true);
            }


            //调用
            string url = "http://192.168.0.3/wms/electronAutoController/getIdxConveyor?ctCode=" + currBarCode + "&lightNo=" + Convert.ToInt32(scannerNo);



            string strError = string.Empty;
            string result   = HttpHelper.GetHtml(url, out strError);

            zshmJson  zshm     = jsonHelp.DeserializeJsonToObject <zshmJson>(result);
            DataTable tblDatas = new DataTable("Datas");

            LogHelper.LogSimlpleString(DateTime.Now.ToString() + "-" + currBarCode + "-" + scannerNo + "-" + result);


            if (zshm.status.ToUpper() == "SUCCESS")
            {
                DataColumn dc = null;
                dc = tblDatas.Columns.Add("billId", Type.GetType("System.String"));
                dc = tblDatas.Columns.Add("chCode", Type.GetType("System.String"));
                dc = tblDatas.Columns.Add("ctCode", Type.GetType("System.String"));
                dc = tblDatas.Columns.Add("priority", Type.GetType("System.String"));

                for (int i = 0; i < zshm.result.Length; i++)
                {
                    DataRow newRow;
                    newRow             = tblDatas.NewRow();
                    newRow["billId"]   = zshm.result[i].billId.ToString().Trim();
                    newRow["chCode"]   = zshm.result[i].chCode.ToString().Trim();
                    newRow["ctCode"]   = zshm.result[i].ctCode.ToString().Trim();
                    newRow["priority"] = zshm.result[i].priority.ToString().Trim();

                    tblDatas.Rows.Add(newRow);
                }
            }
            currBarCode1 = "0";
            if (tblDatas.Rows.Count > 0)
            {
                for (int i = 0; i < tblDatas.Rows.Count; i++)
                {
                    if (tblDatas.Rows[i][1].ToString() == Convert.ToInt32(scannerNo).ToString())
                    {
                        currBarCode1 = "1";
                    }
                }
                currBarCode2 = tblDatas.Rows.Count.ToString();

                bill_id = tblDatas.Rows[0][0].ToString();
            }
            else
            {
                currBarCode2 = "0";
                bill_id      = "0";
            }



            // ds_dev = MySqlHelper.ExecuteDataset(dbConnwms, "select count(0) num  from idx_conveyor where ct_code='" + currBarCode + "' and ch_code='" + Convert.ToInt32( scannerNo).ToString() + "' ");
            //  currBarCode1 = tblDatas



            //ds_dev = MySqlHelper.ExecuteDataset(dbConnwms, "select count(0) num ,IFNULL(max(bill_id),0) bill_id  from idx_conveyor where ct_code='" + currBarCode + "' ");
            //currBarCode2 = ds_dev.Tables[0].Rows[0][0].ToString();
            //bill_id = ds_dev.Tables[0].Rows[0][1].ToString();


            if (currBarCode1 != "0")
            {
                ds_dev       = MySqlHelper.ExecuteDataset(dbConn1, "select count(0) num  from idx_conveyor_log where ct_code='" + currBarCode + "' and ch_code='" + Convert.ToInt32(scannerNo).ToString() + "' and bill_id='" + bill_id + "'");
                currBarCode4 = ds_dev.Tables[0].Rows[0][0].ToString();
            }



            string info = "1";

            if (currBarCode1 == "0")
            {
                info = "1";
            }
            else if (currBarCode2 == "1" || Convert.ToInt32(currBarCode4) >= 2)
            {
                info = "3";
            }
            else
            {
                info = "2";
            }



            if (scannerNo == "21")
            {
                if (currBarCode2 != "0" || currBarCode == "NoRead")
                {
                    info = "2";
                }
                else
                {
                    info = "1";
                }
            }

            ds_dev       = MySqlHelper.ExecuteDataset(dbConn1, "select BARCODE2 from td_wcs_barcode where SCNNER_NO ='22'");
            currBarCode3 = ds_dev.Tables[0].Rows[0][0].ToString();
            if (currBarCode3.Trim().Length < 1 && scannerNo == "22")
            {
                dbConn1.Close();
                dbConnwms.Close();
                return(true);
            }
            string outResult = "-1";
            string outPort   = "0";

            if (scannerNo == "22")
            {
                try
                {
                    string url1 = "http://192.168.0.3/wms/electronAutoController/saveAutoLineWeigh?ctCode=" + currBarCode + "&soWeight=" + Convert.ToDouble(currBarCode3) * 1000;


                    string strError1 = string.Empty;
                    string result1   = HttpHelper.GetHtml(url1, out strError1);

                    zshmCzJson zshmCz    = jsonHelp.DeserializeJsonToObject <zshmCzJson>(result1);
                    DataTable  tblDataTa = new DataTable("Datas");

                    LogHelper.LogSimlpleString(DateTime.Now.ToString() + "-" + currBarCode + "-" + Convert.ToDouble(currBarCode3) * 1000 + "-" + result1);


                    if (zshmCz.status.ToUpper() == "SUCCESS")
                    {
                        bzwms = "0";

                        DataColumn dc = null;
                        dc = tblDataTa.Columns.Add("outResult", Type.GetType("System.String"));
                        dc = tblDataTa.Columns.Add("outPort", Type.GetType("System.String"));

                        if (zshmCz.result.Length > 0)
                        {
                            for (int i = 0; i < 1; i++)
                            {
                                DataRow newRow;
                                newRow = tblDataTa.NewRow();
                                newRow["outResult"] = zshmCz.result[i].outResult.ToString().Trim();

                                if (newRow["outResult"].ToString() == "0")
                                {
                                    newRow["outPort"] = zshmCz.result[i].outPort.ToString().Trim();
                                }



                                tblDataTa.Rows.Add(newRow);
                            }



                            outResult = tblDataTa.Rows[0][0].ToString();
                            if (outResult == "0")
                            {
                                outPort = tblDataTa.Rows[0][1].ToString();
                            }
                            else
                            {
                                outPort = "5";
                                bzwms   = "1";
                            }
                        }
                        else
                        {
                            outPort = "5";
                            bzwms   = "1";
                        }
                    }
                    else
                    {
                        bzwms   = "1";
                        outPort = "5";
                    }

                    //MySqlCommand cmd = new MySqlCommand();
                    //cmd.CommandType = CommandType.StoredProcedure;
                    //cmd.CommandText = "P_AUTO_ONLINE_WEIGHT";
                    //cmd.Parameters.Add("@V_CT_CODE", MySqlDbType.VarChar, 30);
                    ////注意输出参数要设置大小,否则size默认为0,
                    //cmd.Parameters.Add("@V_SO_WEIGHT", MySqlDbType.Int32, 11);
                    ////设置参数的类型为输出参数,默认情况下是输入,
                    //cmd.Parameters.Add("@V_RESULT", MySqlDbType.Int32, 11);
                    //cmd.Parameters["@V_RESULT"].Direction = ParameterDirection.Output;
                    ////为参数赋值
                    //cmd.Parameters["@V_CT_CODE"].Value = currBarCode;
                    //cmd.Parameters["@V_SO_WEIGHT"].Value = Convert.ToDouble(currBarCode3) * 1000;
                    //cmd.Connection = dbConnwms;
                    ////执行
                    //cmd.ExecuteNonQuery();
                    //bzwms = cmd.Parameters["@V_RESULT"].Value.ToString();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());

                    LogHelper.LogSimlpleString(DateTime.Now.ToString() + "-121" + ex.ToString());
                }



                if (bzwms == "1")
                {
                    info = "5";
                }
                else
                {
                    if (outPort == "0")
                    {
                        mainFrm.zckfp++;
                        if (mainFrm.zckfp > 4)
                        {
                            mainFrm.zckfp = 1;
                        }

                        ds_dev       = MySqlHelper.ExecuteDataset(dbConn1, "select ckkstatus from idx_ckk where ckkid ='" + mainFrm.zckfp + "'");
                        currBarCode5 = ds_dev.Tables[0].Rows[0][0].ToString();

                        while (currBarCode5 != "1")
                        {
                            mainFrm.zckfp++;
                            if (mainFrm.zckfp > 4)
                            {
                                mainFrm.zckfp = 1;
                            }
                            ds_dev       = MySqlHelper.ExecuteDataset(dbConn1, "select ckkstatus from idx_ckk where ckkid ='" + mainFrm.zckfp + "'");
                            currBarCode5 = ds_dev.Tables[0].Rows[0][0].ToString();
                        }



                        info = mainFrm.zckfp.ToString();
                    }
                    else
                    {
                        info = outPort;
                    }
                }
            }


            currTaskId = (Convert.ToInt32(returnTaskId) * 999) % 10000;


            writeValues[0] = String.Format("{{{0}|{1}|{2}|0|0}}", currTaskId, info, 0, 0, 0);


            for (int i = 0; i < 3; i++)
            {
                opcServer.SyncWrite(writeValues, commandHandle);
                Thread.Sleep(120);
                mainFrm.AddErrToListView(writeValues[0] + "-" + scannerNo);
                if (scannerNo == "22")
                {
                    LogHelper.LogSimlpleString(DateTime.Now.ToString() + writeValues[0] + "-" + scannerNo + "-" + currBarCode + "-" + currBarCode1 + "-" + currBarCode2 + "-" + bzwms + "-" + Convert.ToDouble(currBarCode3) * 1000);
                }
                else
                {
                    LogHelper.LogSimlpleString(DateTime.Now.ToString() + writeValues[0] + "-" + scannerNo + "-" + currBarCode + "-" + currBarCode1 + "-" + currBarCode2);
                }
                RefreshStatus();
                if (returnTaskId == currTaskId.ToString() && returnTaskStatus != "2")     //写成功判断
                {
                    //数据库任务处理

                    string         strSql = "update td_wcs_barcode set BARCODE2='' , BARCODE  = @barcode where SCNNER_NO = @scnnerno";
                    MySqlParameter pt     = new MySqlParameter("@barcode", MySqlDbType.VarChar, 30);
                    pt.Value = "";

                    MySqlParameter ptno = new MySqlParameter("@scnnerno", MySqlDbType.VarChar, 10);
                    ptno.Value = scannerNo;
                    MySqlCommand mc = new MySqlCommand(strSql, dbConn1);
                    mc.Parameters.Add(pt);
                    mc.Parameters.Add(ptno);
                    mc.ExecuteNonQuery();


                    //if (info == "2" && (scannerNo != "21" || scannerNo != "22"))
                    //{
                    //    strSql = "update idx_conveyor set status  =2 where ct_code= @barcode1 and ch_code = @scnnerno1";
                    //    MySqlParameter pt1 = new MySqlParameter("@barcode1", MySqlDbType.VarChar, 30);
                    //    pt1.Value = currBarCode;

                    //    MySqlParameter ptno1 = new MySqlParameter("@scnnerno1", MySqlDbType.VarChar, 10);
                    //    ptno1.Value = Convert.ToInt32( scannerNo).ToString();
                    //    MySqlCommand mc1 = new MySqlCommand(strSql, dbConn1);
                    //    mc1.Parameters.Add(pt1);
                    //    mc1.Parameters.Add(ptno1);
                    //    mc1.ExecuteNonQuery();
                    //}


                    mainFrm.AddErrToListView("update" + scannerNo);
                    if (info != "1" || scannerNo == "22")
                    {
                        strSql = "insert into idx_conveyor_log(ct_code,ch_code,bill_id,status) values(  @barcode1 , @scnnerno1,@bill_id,@status)";
                        MySqlParameter pt2 = new MySqlParameter("@barcode1", MySqlDbType.VarChar, 30);
                        pt2.Value = currBarCode;

                        MySqlParameter ptno2 = new MySqlParameter("@scnnerno1", MySqlDbType.VarChar, 10);
                        ptno2.Value = Convert.ToInt32(scannerNo).ToString();

                        MySqlParameter ptno3 = new MySqlParameter("@bill_id", MySqlDbType.VarChar, 50);
                        ptno3.Value = bill_id.ToString();
                        MySqlParameter ptno4 = new MySqlParameter("@status", MySqlDbType.VarChar, 10);
                        ptno4.Value = info.ToString() + "-" + bzwms + "-" + currBarCode + "-" + currBarCode3;
                        MySqlCommand mc2 = new MySqlCommand(strSql, dbConn1);
                        mc2.Parameters.Add(pt2);
                        mc2.Parameters.Add(ptno2);
                        mc2.Parameters.Add(ptno3);
                        mc2.Parameters.Add(ptno4);
                        mc2.ExecuteNonQuery();
                    }

                    subTaskId++;
                    currBarCode   = " ";
                    barCodeStatus = true;
                    break;
                }
            }
            dbConn1.Close();
            dbConnwms.Close();


            // currBarCode = DataBaseInterface.GetCurrentBarCode(scannerNo);

            //if (checkBarCode == false || currBarCode == row["short_barcode"].ToString() || currBarCode == "NoRead") //条件满足写分流任务,SJ031G
            //{


            //    taskId = row["task_id"].ToString();
            //    subTaskId = subTaskId % 10;
            //    string currTaskId;
            //    if (taskId.Length > 8)
            //        currTaskId = taskId.Substring(taskId.Length - 8) + subTaskId.ToString();
            //    else
            //        currTaskId = taskId + subTaskId.ToString();

            //    string taskSeq = row["task_seq"].ToString();
            //    string commandInfo = row["command_info"].ToString();
            //    writeValues[0] = String.Format("{{{0}|{1}|{2}|0|0}}", currTaskId, commandInfo, 0);
            //    for (int i = 0; i < 3; i++)
            //    {
            //        opcServer.SyncWrite(writeValues, commandHandle);
            //        Thread.Sleep(110);
            //        RefreshStatus();
            //        if (returnTaskId == currTaskId && returnTaskStatus != "2") //写成功判断
            //        {
            //            //数据库任务处理
            //            DataBaseInterface.SmflTaskPress(taskSeq); //扫描分流任务处理
            //            DataBaseInterface.ClearCurrentBarCode(scannerNo); //清除条码
            //            subTaskId++;
            //            currBarCode = " ";
            //            barCodeStatus = true;
            //            break;
            //        }
            //    }
            //}
            //else
            //{
            //    barCodeStatus = false;
            //    barCodeInfo = "正确为:" + row["short_barcode"].ToString() + "实际为:" + currBarCode;
            //    mainFrm.AddListSystemEvent(deviceName + row["TO_ADDR"].ToString() + barCodeInfo);
            //}
            return(true);
        }