Esempio n. 1
0
        /// <summary>
        /// Reading continuously the port for getting response messages
        /// </summary>
        private void ReceiveMessageFromDevice()
        {
            ByteArray ba = new ByteArray();

            while (_isRunning)
            {
                try
                {
                    Thread.Sleep(10);
                    // check if port open
                    if (!_clsComm.IsOpen)
                    {
                        continue;
                    }

                    // read data
                    ba += _clsComm.ReadData(1000, 100, 100);

                    // wait for the end of the message
                    if (IsEndOfMessage(ba))
                    {
                        string data = DByte.byte_array_to_String(ba);
                        ba = new ByteArray();
                        if (string.IsNullOrEmpty(data))
                        {
                            continue;
                        }

                        // if receive more the one message the split the message and handle each of the messages
                        string[] split = data.Split(new char[] { '\n', '\r' });

                        foreach (var response in split)
                        {
                            if (string.IsNullOrEmpty(response))
                            {
                                continue;
                            }

                            if (CommandReceive != null)
                            {
                                CommandReceive(response);
                            }
                            Application.DoEvents();

                            // handle message
                            HandleMessage(response);
                        }
                    }
                }

                catch (Exception ex)
                {
                    if (ErrorMessage != null)
                    {
                        ErrorMessage("Error get Response data - " + ex.Message);
                    }
                }
            }
        }
Esempio n. 2
0
 public DType Accept(TByte type, string x)
 {
     if (byte.TryParse(x, out var b))
     {
         return(DByte.ValueOf(b));
     }
     else
     {
         throw new Exception($"{x} 不是byte类型");
     }
 }
Esempio n. 3
0
        public Hero()
        {
            this.Speed        = 10;
            this.health       = new DInt(Rand.Next(4, 10));
            this.evil         = new DBool();
            this.kind         = new DByte();
            this.attacking    = new DBool();
            this.attackSpeed  = new DByte((byte)Rand.Next(5, 12));
            this.attackDamage = new DByte((byte)Rand.Next(1, 4));

            this.type = 10;
        }
Esempio n. 4
0
        public Hero()
        {
            this.Speed = 10;
            this.health = new DInt(Rand.Next(4,10));
            this.evil = new DBool();
            this.kind = new DByte();
            this.attacking = new DBool();
            this.attackSpeed = new DByte((byte)Rand.Next(5,12));
            this.attackDamage = new DByte((byte)Rand.Next(1,4));

            this.type = 10;
        }
        public DType Accept(TByte type, ExcelStream x)
        {
            var d = x.Read();

            if (CheckNull(type.IsNullable, d))
            {
                return(null);
            }
            if (!byte.TryParse(d.ToString(), out byte v))
            {
                throw new InvalidExcelDataException($"{d} 不是 byte 类型值");
            }
            return(DByte.ValueOf(v));
        }
Esempio n. 6
0
        static ChineseConvert()
        {
            Type type = typeof(ChineseConvert);

            for (int i = 0; i < 2; i++)
            {
                string name = string.Format("{0}.Data.{1}.dat", type.Namespace, (i == 0) ? "gb2312" : "big5");
                Stream manifestResourceStream = type.Assembly.GetManifestResourceStream(name);
                byte[] buffer = new byte[manifestResourceStream.Length];
                manifestResourceStream.Read(buffer, 0, buffer.Length);
                int index = 0;
                if (i == 0)
                {
                    __gb2312Lib = new DByte[0xff, 0xff];
                    for (int j = 0xa7; j < 0xff; j++)
                    {
                        for (int k = 0xa1; k < 0xff; k++)
                        {
                            __gb2312Lib[j, k] = new DByte(buffer[index + 1], buffer[index]);
                            index            += 2;
                        }
                    }
                }
                else
                {
                    __big5Lib = new DByte[0xff, 0xff];
                    for (int m = 0xa1; m < 0xff; m++)
                    {
                        for (int n = 0x40; n < 0xff; n++)
                        {
                            __big5Lib[m, n] = new DByte(buffer[index + 1], buffer[index]);
                            index          += 2;
                        }
                    }
                }
            }
        }
Esempio n. 7
0
 public void Accept(DByte type, RawTextTable x)
 {
 }
Esempio n. 8
0
 public void Accept(DByte type, ByteBuf x)
 {
     x.WriteByte(type.Value);
 }
Esempio n. 9
0
 public DType Accept(TByte type, XElement x, DefAssembly ass)
 {
     return(DByte.ValueOf(byte.Parse(x.Value.Trim())));
 }
Esempio n. 10
0
 public void Accept(DByte type, StringBuilder line)
 {
     line.Append(type.Value);
 }
 public int Accept(DByte data, TType type, Title x)
 {
     SetTitleValue(x, data.Value);
     return(1);
 }
Esempio n. 12
0
 public void Accept(DByte type, Utf8JsonWriter x)
 {
     x.WriteNumberValue(type.Value);
 }
Esempio n. 13
0
 public string Accept(DByte type)
 {
     return(type.Value.ToString());
 }
Esempio n. 14
0
 public DType Accept(TByte type, object x, DefAssembly ass)
 {
     return(DByte.ValueOf((byte)(int)x));
 }
Esempio n. 15
0
 public void Accept(DByte type, DefAssembly x)
 {
     throw new NotImplementedException();
 }
Esempio n. 16
0
 public bool Accept(DByte type)
 {
     return(type.Value == 0);
 }
 public void Accept(DByte type, TType x, List <ResourceInfo> y)
 {
 }
Esempio n. 18
0
 public void Accept(DByte type, DefField x, List <ResourceInfo> y)
 {
     throw new NotImplementedException();
 }
Esempio n. 19
0
 public void Accept(DByte type, StringBuilder x)
 {
     x.Append(type.Value);
 }
Esempio n. 20
0
 public DType Accept(TByte type, JsonElement x, DefAssembly ass)
 {
     return(DByte.ValueOf(x.GetByte()));
 }