示例#1
0
        /// <summary>
        /// 实际落袋发送   WCS->WMS
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void PocketSend()
        {
            try
            {
                DataTable tb = createdata.GetPlcSednCode();
                if (tb != null)
                {
                    if (tb.Rows.Count > 0)
                    {
                        foreach (DataRow row in tb.Rows)
                        {
                            string      seqId  = string.Empty;
                            List <byte> wmsSeq = new List <byte>();
                            string      code   = row["ExpressNo"].ToString();
                            if (code.Trim().Length == 0)
                            {
                                continue;
                            }
                            // 如果code为noread,以12个0作为单号发送
                            if ("noread\r" == code)
                            {
                                code = "000000000000";
                            }
                            byte[] arrayL = System.Text.Encoding.ASCII.GetBytes(code);
                            if (row["endprot"].ToString().Trim().Length == 0)
                            {
                                return;
                            }
                            short  endprot = short.Parse(row["endprot"].ToString());
                            byte[] array;
                            //// 如果数据库查到的落袋格口为14,实际是因为格口锁定而落入13格口
                            //if (endprot == 14)
                            //{
                            //    short readport = 13;
                            //    array = BitConverter.GetBytes(readport);
                            //}
                            //else
                            //{
                            array = BitConverter.GetBytes(endprot); //数据域 格口 2字节
                            //}
                            wmsSeq.Add(array[1]);
                            wmsSeq.Add(array[0]);
                            wmsSeq.Add(byte.Parse(code.Length.ToString()));

                            foreach (char letter in arrayL)
                            {
                                byte value = Convert.ToByte(letter);
                                wmsSeq.Add(value);  //数据域 运单号 动态长度
                            }

                            short prot = short.Parse(row["prot"].ToString());

                            if (prot == 19)
                            {
                                wmsSeq.Add(0XF0);
                            }
                            else
                            {
                                if (endprot == 19)
                                {
                                    wmsSeq.Add(0XF0);
                                }
                                // 如果因为满袋而未分拣,plc会返回落袋格口99
                                else if (endprot == 99)
                                {
                                    wmsSeq.Add(0x02);
                                }
                                else
                                {
                                    wmsSeq.Add(0X00); //数据域 异常码 1字节
                                }
                            }
                            wmsSeq.Add(0X02);  //数据域 TAG 1字节
                            byte lenData = byte.Parse((5 + wmsSeq.Count).ToString());
                            bool sendSts = WmsCommon.Instance().ErrWmsSendData(0X84, lenData, wmsSeq, ref seqId);
                            if (sendSts)
                            {
                                string plcId = row["plcid"].ToString();
                                createdata.UpDataWmsPlcData(plcId);
                                createdata.UpDataWmsseqIdData(seqId, plcId);
                                Log.WriteLog2(DateTime.Now + " 发送落袋信息成功。 条码:" + code + "  实际格口:" + plcId);
                                tb_message.AppendText(DateTime.Now.ToString() + code + " 落袋发送消息成功\r\n");
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Log.WriteLog2("发送WMS落袋信息 ex" + ex.Message);
            }
        }