Example #1
0
        public void handleOneByte(byte b)
        {
            serialBuf.Add(b);

            if (serialBuf[0] != 0x68)
            {
                serialBuf.RemoveAt(0);
            }
            if (serialBuf.Count < 8)
            {
                return;
            }
            callEventArgs        = null;
            stateReportEventArgs = null;
            if (serialBuf[1] == 0xE5 && serialBuf.Count == 8)//呼叫器呼叫
            {
                if (serialBuf != null)
                {
                    callEventArgs = new RemoteCallEventArgs(serialBuf[5], serialBuf[6]);
                }
            }
            else if (serialBuf[1] == 0xE3)//状态上报
            {
                if (serialBuf.Count < 20)
                {
                    return;
                }
                else if (serialBuf.Count == 20)
                {
                    stateReportEventArgs = new CarStateReportEventArgs(serialBuf[5], serialBuf[6], serialBuf[7],
                                                                       serialBuf[8], serialBuf[9], serialBuf[10], serialBuf[11], serialBuf[12], serialBuf[13], serialBuf[14]);
                }
            }

            try
            {
                if ((null != remoteCallEvent) && (callEventArgs != null))
                {
                    remoteCallEvent(this, callEventArgs);
                    serialBuf.Clear();//有效帧
                }
                else if ((null != stateReportEventArgs) && (null != carStateReportEvent))
                {
                    carStateReportEvent(this, stateReportEventArgs);
                    serialBuf.Clear();
                }
                else
                {
                    serialBuf.RemoveAt(0);
                }
            }
            catch (Exception x)
            {
                Console.WriteLine(x.Message);
            }
        }
Example #2
0
        public void agvCarStateReport(object sender, CarStateReportEventArgs e)
        {
            if (e != null)
            {
                try
                {
                    writeLine("id " + e.CarId + " state " + e.Movement + " card " + e.CardId + " count " + e.TaskLen + " type " + e.Type);
                    newCanvas.carArray[e.CarId].posCard       = e.CardId;
                    newCanvas.carArray[e.CarId].remoteTaskLen = e.TaskLen;
                    newCanvas.carArray[e.CarId].status        = e.Movement;
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }

            //switch(e.Movement){
            //    case 7://卡位错误
            //        if (e != null && ((e.CardId == 0) || (e.TargetCardId == 0) || (e.EndCardId == 0)))
            //            break;
            //        startStation = newCanvas.findStationByCardID(e.CardId);
            //        targetStation = newCanvas.findStationByCardID(e.TargetCardId);
            //        endStation = newCanvas.findStationByCardID(e.EndCardId);
            //        if ((startStation == null) || (targetStation == null) || (endStation == null))
            //        {
            //            break;
            //        }
            //        newCanvas.carArray[e.CarId].posCard = e.CardId;
            //        serialHander.accessRoadTable(e.CarId, startStation, targetStation, endStation, this.newCanvas.AdjList, this.serialPort1, this.newCanvas);
            //        break;
            //    case 5://运行状态(包括启动时刻)//第一次启动,只需发路由表,不用发启动命令
            //        newCanvas.carArray[e.CarId].posCard = e.CardId;
            //        if (e.CardId == e.TargetCardId)
            //        {
            //            newCanvas.carArray[e.CarId].WorkState = false;
            //            return;
            //        }
            //        Thread.Sleep(10);
            //        if (e != null && e.Movement == 0x05 && CarState.CarStop == newCanvas.carArray[e.CarId].getRealState())
            //        {
            //            byte[] controlCommand = new byte[7] { (byte)0x68, (byte)0x55, (byte)0x01, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00 };
            //            controlCommand[5] = (byte)e.CarId;
            //            controlCommand[6] = (byte)((0x55 + 0x01 + e.CarId) % 256);
            //            serialPort1.Write(controlCommand, 0, controlCommand.Length);//发命令停车
            //        }
            //        break;
            //    case 4://工位停车(命令停车)
            //        newCanvas.carArray[e.CarId].posCard = e.CardId;
            //        if (e.CardId == e.TargetCardId)
            //        {
            //            newCanvas.carArray[e.CarId].WorkState = true;
            //            return;
            //        }
            //        Thread.Sleep(10);
            //        if (e!=null&&e.Movement == 0x04 && CarState.CarRun == newCanvas.carArray[e.CarId].getRealState())
            //        {
            //            byte[] controlCommand = new byte[7] { (byte)0x68, (byte)0x54, (byte)0x01, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00 };
            //            controlCommand[5] = (byte)e.CarId;
            //            controlCommand[6] = (byte)((0x54 + 0x01 + e.CarId) % 256);//开车命令
            //            serialPort1.Write(controlCommand, 0, controlCommand.Length);
            //        }
            //        break;
            //    default:
            //        newCanvas.carArray[e.CarId].posCard = e.CardId;
            //        break;
            //}
        }