Example #1
0
        ErrorArgs ParseError(byte[] Data)
        {
            ErrorArgs oArgs = new ErrorArgs();

            if (Data.Length == 14)
            {
                if (Data[1] == 48 && Data[2] == 50)
                {
                    oArgs.TimeStamp = ParseHex(Data, 3, 6);
                    oArgs.State     = (ushort)ParseHex(Data, 9, 2);
                    oArgs.Error     = (short)ParseInt(Data, 11, 3);
                }
            }
            return(oArgs);
        }
Example #2
0
        private void ProcessIncomingData(List <byte> PortBuffer)
        {
            byte[] Data;

            int Front, Back = 0;

            if (PortBuffer.Count > 0)
            {
                Front = PortBuffer.IndexOf((byte)36);
                if (Front > -1)
                {
                    Back = PortBuffer.IndexOf((byte)10, Front);
                    if (Back > -1)
                    {
                        Data = new byte[Back - Front];
                        PortBuffer.CopyTo(Front, Data, 0, Back - Front);
                        Front = ((Data[1] - 48) * 10) + (Data[2] - 48);
                        switch (Front)
                        {
                        case (int)RobotOutputType.Announcement:
                            if (this.AnnounceReceived != null)
                            {
                                AnnounceArgs oArgs = new AnnounceArgs();
                                this.AnnounceReceived(this, oArgs);
                            }
                            break;

                        case (int)RobotOutputType.Error:

                            if (this.ErrorReceived != null)
                            {
                                ErrorArgs oArgs = ParseError(Data);
                                this.ErrorReceived(this, oArgs);
                            }

                            break;

                        case (int)RobotOutputType.Sensor:
                            if (this.OutputReceived != null)
                            {
                                OutputArgs oArgs = ParseSensor(Data);
                                this.OutputReceived(this, oArgs);
                            }

                            break;

                        case (int)RobotOutputType.Acknowledge:
                            if (this.ACKReceived != null)
                            {
                                ACKArgs oArgs = new ACKArgs();
                                oArgs.TimeStamp = ParseHex(Data, 3, 6);
                                this.ACKReceived(this, oArgs);
                            }
                            break;

                        case (int)RobotOutputType.Configuration:
                            if (this.ConfigReceived != null)
                            {
                                ConfigArgs oArgs = ParseConfig(Data);
                                this.ConfigReceived(this, oArgs);
                            }
                            break;

                        default:
                            break;
                        }
                        PortBuffer.RemoveRange(0, Back);
                        // Search through the bytes to find the data you want
                        // then remove the data from the list. It is good to
                        // clean up unused bytes (usually everything before
                        // what you're looking for)
                    }

                    //                    System.Windows.Forms.Message  M = new System.Windows.Forms.Message("a");
                    //                    MessageReceivedCallBack
                }
            }
        }