Пример #1
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            mTimeOut++;
            mTimOut2++;
            if (mTimeOut >= 3)
            {
                lbMotor.BackColor = Color.Red;
                mLinkConnect      = false;
                mTimeOut          = 3;
            }
            if (mTimOut2 >= 3)
            {
                lbWeighter.BackColor = Color.Red;
                mLinkConnect2        = false;
                mTimOut2             = 3;
            }
            if (NetWork.IsConnectInternet())
            {
                lbNetwork.BackColor = Color.Lime;
            }
            else
            {
                lbNetwork.BackColor = Color.Red;
            }
            if (mPeriodCheck++ >= 1) // 1秒发送1次
            {
                string sendstr = "AT\r\n";
                byte[] send    = Encoding.Default.GetBytes(sendstr);
                serialComm.WritePort(send, 0, send.Length);
                mPeriodCheck = 0;
            }

            if (Environment.TickCount - time1 > 10000)
            {
                if (!STM32Ready)
                {
                    timer1.Enabled = false;
                    DialogResult dr = MessageBox.Show("电机异常,请检查设备并重启", "ERRO", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    if (dr == DialogResult.OK)
                    {
                        System.Environment.Exit(0);
                    }
                }
            }
            if (!STM32Ready && mLinkConnect && CodeSum != 0)
            {
                nowtick = TimeTransitionHelper.GetCurrentTimeUnix();
                nowtick = TimeTransitionHelper.GetCurrentTimeUnix();
                if ((nowtick - firsttick) / 3600 < 1)
                {
                    rate = (int)(CodeSum / ((nowtick - firsttick) / 3600 + 1));
                }
                else
                {
                    rate = CodeSum / ((nowtick - firsttick) / 3600.0);
                }
                lbRate.Text = "速率    " + rate.ToString("#0.00") + "件/小时";
            }
        }
Пример #2
0
        public void UpSqlite(BarInfo barInfo)
        {
            //根据编号查询结果
            BarInfo barInfo2 = infoDal.GetByNumber(barInfo.BNumber);

            if (barInfo2 == null)
            {
                infoDal.Insert(barInfo);
            }
            else
            {
                long nowtick = TimeTransitionHelper.GetCurrentTimeUnix();
                if (nowtick - barInfo.Btime > 1200)//20分钟后可再次扫码
                {
                    infoDal.Updata(barInfo);
                }
            }
        }
Пример #3
0
        private void OnComplete(object sender, OnCompleteEventArgs e)
        {
            //string strPort="";
            string portNum;
            string httpResponse;
            //bool IsDestionation= dic.TryGetValue(portNum, out List<string> destination);
            //if (IsDestionation)
            //{
            //    strDes=destination[0];
            //    strPort=destination[1];
            //}
            //else
            //{
            //    strDes = "无";
            //    strPort = "0";
            //}
            string time = DateTime.Now.ToString();


            if (CodeSum == 0)//记录第一次扫到条码的时间
            {
                firsttick = TimeTransitionHelper.GetCurrentTimeUnix();
            }
            this.Invoke(new Action(() =>
            {
                lbCode.ForeColor = Color.DarkBlue;
                lbCode.Text      = "单号    " + e.DataStrings;
            }));
            try
            {
                if (STM32Ready && mLinkConnect)
                {
                    if (NetWork.IsConnectInternet())
                    {
                        string data = "[{\"ticketsNum\":\"" + e.DataStrings + "\",\"workConsole\":\"" + workConsole + "\"}]";
                        httpResponse = HttpHelper.PostDataGetHtml(url, data);
                        JObject array = (JObject)JsonConvert.DeserializeObject(httpResponse);
                        portNum = array["port"].ToString().Trim('"');
                    }
                    else
                    {
                        return;
                    }
                    CodeSum++;
                    nowtick = TimeTransitionHelper.GetCurrentTimeUnix();
                    if ((nowtick - firsttick) / 3600 < 1)
                    {
                        rate = (int)(CodeSum / ((nowtick - firsttick) / 3600 + 1));
                    }
                    else
                    {
                        rate = CodeSum / ((nowtick - firsttick) / 3600.0);
                    }

                    this.Invoke(new Action(() =>
                    {
                        lbSum.Text         = "总数    " + Convert.ToString(CodeSum) + "/件";
                        lbRate.Text        = "速率    " + rate.ToString("#0.00") + "件/小时";
                        lbDestination.Text = "目的地    " + portNum + "号口";
                        if (dt != null)
                        {
                            if (dgvData.RowCount > 3000)
                            {
                                if (IsSavaCode)
                                {
                                    string dir = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + "\\条码记录";
                                    if (!System.IO.Directory.Exists(dir))
                                    {
                                        //创建pic文件夹
                                        System.IO.Directory.CreateDirectory(dir);
                                    }
                                    string time2 = Regex.Replace(time, pattern, string.Empty, RegexOptions.IgnoreCase);
                                    ExcelHelper.ExportToExcel(dt, dir + "\\" + time2 + ".xls");
                                }
                                dt.Clear();
                            }
                            DataRow dr     = dt.NewRow();
                            dr["单号"]       = e.DataStrings;
                            dr["重量(Kg)"]   = weightStr;
                            dr["目的地"]      = portNum + "号口";
                            dr["时间"]       = time;
                            dr["扫描时间(ms)"] = e.UseTime;
                            dt.Rows.Add(dr);
                            dgvData.FirstDisplayedScrollingRowIndex = dgvData.Rows.Count - 1;
                        }
                    }));

                    string sendstr = "win" + portNum + "\r\n";
                    byte[] send    = Encoding.Default.GetBytes(sendstr);
                    serialComm.WritePort(send, 0, send.Length);
                    STM32Ready = false;
                    time1      = Environment.TickCount;
                }
            }
            catch (Exception ex)
            {
            }
        }