Exemple #1
0
 public void Queue(IEnumerable <byte> b)
 {
     Buffer.AddRange(b);
     if (Buffer.Count >= MaxPacketSize)
     {
         Transmit();
     }
 }
Exemple #2
0
 public void WriteInt32(int value)
 {
     byte[] buf = BitConverter.GetBytes(value);
     if (BitConverter.IsLittleEndian)
     {
         Array.Reverse(buf);
     }
     Buffer.AddRange(buf);
 }
Exemple #3
0
 public void WriteDouble(double val)
 {
     byte[] buf = BitConverter.GetBytes(val);
     if (BitConverter.IsLittleEndian)
     {
         Array.Reverse(buf);
     }
     Buffer.AddRange(buf);
 }
Exemple #4
0
 public void WriteBytes(byte[] buf, int length)
 {
     if (length < 0)
     {
         length = buf.Length;
     }
     byte[] newBuf = new byte[length];
     Array.Copy(buf, newBuf, length);
     Buffer.AddRange(newBuf);
 }
Exemple #5
0
        public void FillBytes(byte value, int count)
        {
            var bytes = new byte[count];

            for (int i = 0; i < count; ++i)
            {
                bytes[i] = value;
            }
            Flush();
            Buffer.AddRange(bytes);
        }
Exemple #6
0
        private void ReadAndResolve()
        {
            if (SerialPort.BytesToRead == 0)
            {
                return;
            }

            var readResult = SerialPort.ReadExisting();

            this.Info("接收数据:" + readResult);
            var bytes = Encoding.ASCII.GetBytes(readResult);

            Buffer.AddRange(bytes);

            Resolving();
        }
 /// <summary>
 /// 書き込み
 /// </summary>
 /// <param name="Bytes">バイト配列</param>
 /// <returns>成功したらtrueを返す</returns>
 private void Write(byte[] Bytes)
 {
     Buffer.AddRange(Bytes);
 }
        public void MakeIteration()
        {
            if (IterationBegins != null)
            {
                IterationBegins(this, EventArgs.Empty);
            }

            if (GetAppearenceCount != null && PerformAppearence != null)
            {
                var c = GetAppearenceCount();
                for (var i = 0; i < c; i++)
                {
                    Buffer.Add(PerformAppearence());
                }
                ++CurrentIteration;
            }

            if (Pool.Count != 0 && GetMutationOrigins != null && PerformMutation != null)
            {
                var mutationSource = GetMutationOrigins();
                foreach (var source in mutationSource)
                {
                    source.Item1.Inherited = true;
                    for (var i = 0; i < source.Item2; i++)
                    {
                        var m = PerformMutation(source.Item1);
                        if (m == null)
                        {
                            continue;
                        }
                        m.Parent1 = source.Item1.Id;
                        Buffer.Add(m);
                    }
                }
            }

            if (Pool.Count != 0 && GetCrossoverFamilies != null && PerformCrossover != null)
            {
                var pairs = GetCrossoverFamilies();
                foreach (var pair in pairs)
                {
                    pair.Item1.Inherited = pair.Item2.Inherited = true;
                    for (var i = 0; i < pair.Item3; i++)
                    {
                        var cross = PerformCrossover(pair.Item1, pair.Item2);
                        if (cross == null)
                        {
                            continue;
                        }
                        cross.Parent1 = pair.Item1.Id;
                        cross.Parent2 = pair.Item2.Id;
                        Buffer.Add(cross);
                    }
                }
            }

            if (ReevaluateOldGenes)
            {
                foreach (var e in Pool)
                {
                    e.Evaluated = false;
                }
            }

            if (CanKeepOldGenesInBuffer)
            {
                Buffer.AddRange(Pool);
            }

            Pool.Clear();

            if (DisableEqualGenes)
            {
                for (var i = Buffer.Count - 1; i >= 0; i--)
                {
                    for (var j = i - 1; j >= 0; j--)
                    {
                        if (Buffer[i].Equals(Buffer[j]))
                        {
                            Buffer.RemoveAt(j);
                            j--;
                            i--;
                        }
                    }
                }
            }

            if (EvaluationBegins != null)
            {
                EvaluationBegins();
            }

            foreach (var e in Buffer.Where(z => !z.Evaluated))
            {
                Evaluate(e);
            }

            if (EvaluationCompleted != null)
            {
                EvaluationCompleted();
            }

            if (PerformSelection != null)
            {
                PerformSelection(Buffer, Pool);
            }
            else
            {
                Pool.AddRange(Buffer);
            }

            Buffer.Clear();

            foreach (var g in Pool)
            {
                g.Evaluated = true;
                g.Age++;
                if (g.Id == 0)
                {
                    g.Id = ++CurrentId;
                }
                if (g.Generation == 0)
                {
                    g.Generation = CurrentIteration;
                }
            }

            if (PerformBanking != null)
            {
                PerformBanking();
            }

            if (IterationCallBack != null)
            {
                IterationCallBack();
            }
        }
 public void AddLines(List <T> Lines)
 {
     Buffer.AddRange(Lines);
 }
Exemple #10
0
 public void WriteFloat(float value)
 {
     Flush();
     Buffer.AddRange(BitConverter.GetBytes(value));
 }
Exemple #11
0
 public void WriteInt64(long value)
 {
     Flush();
     Buffer.AddRange(BitConverter.GetBytes(value));
 }
Exemple #12
0
 public void WriteInt16(ushort value)
 {
     Flush();
     Buffer.AddRange(BitConverter.GetBytes(value));
 }
Exemple #13
0
 public void WriteBytes(params byte[] bytes)
 {
     Flush();
     Buffer.AddRange(bytes);
 }