/// <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); } } } }
public DType Accept(TByte type, string x) { if (byte.TryParse(x, out var b)) { return(DByte.ValueOf(b)); } else { throw new Exception($"{x} 不是byte类型"); } }
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 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)); }
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; } } } } }
public void Accept(DByte type, RawTextTable x) { }
public void Accept(DByte type, ByteBuf x) { x.WriteByte(type.Value); }
public DType Accept(TByte type, XElement x, DefAssembly ass) { return(DByte.ValueOf(byte.Parse(x.Value.Trim()))); }
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); }
public void Accept(DByte type, Utf8JsonWriter x) { x.WriteNumberValue(type.Value); }
public string Accept(DByte type) { return(type.Value.ToString()); }
public DType Accept(TByte type, object x, DefAssembly ass) { return(DByte.ValueOf((byte)(int)x)); }
public void Accept(DByte type, DefAssembly x) { throw new NotImplementedException(); }
public bool Accept(DByte type) { return(type.Value == 0); }
public void Accept(DByte type, TType x, List <ResourceInfo> y) { }
public void Accept(DByte type, DefField x, List <ResourceInfo> y) { throw new NotImplementedException(); }
public void Accept(DByte type, StringBuilder x) { x.Append(type.Value); }
public DType Accept(TByte type, JsonElement x, DefAssembly ass) { return(DByte.ValueOf(x.GetByte())); }