예제 #1
0
        private void SendRestData()
        {
            StringBuilder sb = new StringBuilder();

            sb.Append("update workorder set status = 2 where id in (");

            DataTable dt = Global.mysqlHelper.GetDataTable("select * from workorder where status = 1 and thickness = "
                                                           + comboThickness.Text + " order by id asc");

            byte[] sendbuf = new byte[400];
            int    count   = dt.Rows.Count;

            if (count > (30 - Global.dataCount))
            {
                count = 30 - Global.dataCount;
            }
            sendbuf[0] = Global.stationAddr;
            sendbuf[1] = Global.writeCmd;
            sendbuf[2] = (byte)((Global.offset + Global.dataCount * 6) / 256);
            sendbuf[3] = (byte)((Global.offset + Global.dataCount * 6) % 256);
            sendbuf[4] = (byte)(count * 6 / 256);
            sendbuf[5] = (byte)(count * 6 % 256);


            sendbuf[6] = (byte)(count * 12);

            for (int i = 0; i < count; i++)
            {
                WorkOrder order = new WorkOrder(dt.Rows[i]);
                sendbuf[7 + 12 * i]     = (byte)((order.Length << 16) >> 24);
                sendbuf[7 + 12 * i + 1] = (byte)((order.Length << 24) >> 24);
                sendbuf[7 + 12 * i + 2] = (byte)(order.Length >> 24);
                sendbuf[7 + 12 * i + 3] = (byte)((order.Length << 8) >> 24);

                sendbuf[7 + 12 * i + 4] = (byte)((order.GrossWidth << 16) >> 24);
                sendbuf[7 + 12 * i + 5] = (byte)((order.GrossWidth << 24) >> 24);
                sendbuf[7 + 12 * i + 6] = (byte)(order.GrossWidth >> 24);
                sendbuf[7 + 12 * i + 7] = (byte)((order.GrossWidth << 8) >> 24);

                sendbuf[7 + 12 * i + 8]  = (byte)((order.Done << 16) >> 24);
                sendbuf[7 + 12 * i + 9]  = (byte)((order.Done << 24) >> 24);
                sendbuf[7 + 12 * i + 10] = (byte)(order.Done >> 24);
                sendbuf[7 + 12 * i + 11] = (byte)((order.Done << 8) >> 24);

                sb.Append(order.id.ToString() + ",");
                Global.procData[i + Global.dataCount].id         = order.id;
                Global.procData[i + Global.dataCount].Lenth      = order.Length;
                Global.procData[i + Global.dataCount].Thickness  = order.Thickness;
                Global.procData[i + Global.dataCount].GrossWidth = order.GrossWidth;
                Global.procData[i + Global.dataCount].status     = (int)OrderStatus.WORKING;
            }
            uint crc = SystemUnit.getCRC(sendbuf, 0, count * 12 + 7);

            sendbuf[count * 12 + 7] = (byte)(crc / 256);
            sendbuf[count * 12 + 8] = (byte)(crc % 256);
            Global.commHelper.SendControlCmd(sendbuf, count * 12 + 9);
            timerBreak.Enabled = true;
            sb.Append("0)");
            Global.mysqlHelper.ExecuteSql(sb.ToString());
        }
예제 #2
0
        void comm_DataReceived(object sender, SerialDataReceivedEventArgs e)
        {
            int n = comm.BytesToRead;

            byte[] buff = new byte[n];
            comm.Read(buff, 0, n);
            if (Global.logOpen == 1)
            {
                Log.WriteLog("CommPort", "INFO", "【comm_DataReceived】 接收数据:" + SystemUnit.ToHexString(buff));
            }

            Buffer.BlockCopy(buff, 0, curBuff, curCount, n);
            curCount = curCount + n;
            if (curCount < 5)
            {
                return;
            }
            if (SystemUnit.getCRC(curBuff, 0, curCount - 2) == (curBuff[curCount - 2] << 8 | curBuff[curCount - 1]))
            {
                byte[] proBuff = new byte[curCount];
                Buffer.BlockCopy(curBuff, 0, proBuff, 0, curCount);
                curCount = 0;
                procData(proBuff);
            }
            if (curCount > 250)
            {
                curCount = 0;
            }
        }
예제 #3
0
        private void SendReadStatusCmd()
        {
            byte[] sendbuf = new byte[8];
            sendbuf[0] = Global.stationAddr;
            sendbuf[1] = Global.readCmd;
            sendbuf[2] = (byte)(Global.runStatusOffset / 256);
            sendbuf[3] = (byte)(Global.runStatusOffset % 256);
            sendbuf[4] = 0;
            sendbuf[5] = 2;
            uint crc = SystemUnit.getCRC(sendbuf, 0, 6);

            sendbuf[6] = (byte)(crc / 256);
            sendbuf[7] = (byte)(crc % 256);
            Global.commHelper.SendControlCmd(sendbuf, 8);
        }
예제 #4
0
        private void SendReadDataCmd(int offset, int count)
        {
            byte[] sendbuf = new byte[8];
            sendbuf[0] = Global.stationAddr;
            sendbuf[1] = Global.readCmd;
            sendbuf[2] = (byte)(offset / 256);
            sendbuf[3] = (byte)(offset % 256);
            sendbuf[4] = (byte)(count * 6 / 256);
            sendbuf[5] = (byte)(count * 6 % 256);
            uint crc = SystemUnit.getCRC(sendbuf, 0, 6);

            sendbuf[6] = (byte)(crc / 256);
            sendbuf[7] = (byte)(crc % 256);
            Global.commHelper.SendControlCmd(sendbuf, 8);
        }
예제 #5
0
        private void sendNewOrders(int thickness)
        {
            FlushProcData();
            Global.runMode = RunMode.WRITE;
            string sql = "insert into working " +
                         "(id, productorder, type, scheduledate, lenth, width, thickness, gross, done, undone," +
                         "completedate, machinecode, worker, worth, remark, status, receivedate, grosswidth)" +
                         "select* from workorder a where a.status = 1 and a.thickness = " + thickness.ToString();

            Global.mysqlHelper.ExecuteSql(sql);
            sql = "update workorder a, working b set a.status = 2 where a.id = b.id";
            Global.mysqlHelper.ExecuteSql(sql);

            StringBuilder sb = new StringBuilder();

            sb.Append("update working set status = 2 where id in (");
            DataTable dt = Global.mysqlHelper.GetDataTable("select * from working order by workingid asc");

            byte[] sendbuf = new byte[400];
            int    count   = dt.Rows.Count;

            //判断订单数是否大于设备最大订单数30
            if (count > 30)
            {
                Global.isDataOver = true;
            }
            else
            {
                Global.isDataOver = false;
            }

            //判断是否可以一次发完
            Global.isSendAll = true;
            if (count > Global.dataCount)
            {
                Global.isSendAll = false;
                count            = Global.dataCount;
            }
            sendbuf[0] = Global.stationAddr;
            sendbuf[1] = Global.writeCmd;
            sendbuf[2] = (byte)(Global.offset / 256);
            sendbuf[3] = (byte)(Global.offset % 256);
            sendbuf[4] = (byte)(Global.dataCount * 6 / 256);
            sendbuf[5] = (byte)(Global.dataCount * 6 % 256);
            sendbuf[6] = (byte)(Global.dataCount * 12);

            for (int i = 0; i < count; i++)
            {
                WorkOrder order = new WorkOrder(dt.Rows[i]);
                sendbuf[7 + 12 * i]     = (byte)((order.Length << 16) >> 24);
                sendbuf[7 + 12 * i + 1] = (byte)((order.Length << 24) >> 24);
                sendbuf[7 + 12 * i + 2] = (byte)(order.Length >> 24);
                sendbuf[7 + 12 * i + 3] = (byte)((order.Length << 8) >> 24);

                sendbuf[7 + 12 * i + 4] = (byte)((order.GrossWidth << 16) >> 24);
                sendbuf[7 + 12 * i + 5] = (byte)((order.GrossWidth << 24) >> 24);
                sendbuf[7 + 12 * i + 6] = (byte)(order.GrossWidth >> 24);
                sendbuf[7 + 12 * i + 7] = (byte)((order.GrossWidth << 8) >> 24);

                sendbuf[7 + 12 * i + 8]  = (byte)((order.Done << 16) >> 24);
                sendbuf[7 + 12 * i + 9]  = (byte)((order.Done << 24) >> 24);
                sendbuf[7 + 12 * i + 10] = (byte)(order.Done >> 24);
                sendbuf[7 + 12 * i + 11] = (byte)((order.Done << 8) >> 24);

                sb.Append(order.id.ToString() + ",");
                Global.procData[i].id         = order.id;
                Global.procData[i].Lenth      = order.Length;
                Global.procData[i].Thickness  = order.Thickness;
                Global.procData[i].GrossWidth = order.GrossWidth;
                Global.procData[i].status     = (int)OrderStatus.WORKING;
            }
            uint crc = SystemUnit.getCRC(sendbuf, 0, Global.dataCount * 12 + 7);

            sendbuf[Global.dataCount * 12 + 7] = (byte)(crc / 256);
            sendbuf[Global.dataCount * 12 + 8] = (byte)(crc % 256);
            Global.commHelper.SendControlCmd(sendbuf, Global.dataCount * 12 + 9);
            timerBreak.Enabled = true;
            sb.Append("0)");
            Global.mysqlHelper.ExecuteSql(sb.ToString());
            lblWorkingShowInfo.Text      = "订单发送中……";
            lblWorkingShowInfo.ForeColor = Color.Green;
        }