add emulator
This commit is contained in:
64
Emulator/AGVEmulator/DevCAL.cs
Normal file
64
Emulator/AGVEmulator/DevCAL.cs
Normal file
@@ -0,0 +1,64 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace AGVEmulator
|
||||
{
|
||||
class DevCAL : AR.Dev.RS232
|
||||
{
|
||||
public override bool ProcessRecvData(byte[] data)
|
||||
{
|
||||
var sample = "02 30 31 32 01 03";
|
||||
var barr = sample.Split(' ').ToList().Select(t => Convert.ToByte(t, 16)).ToArray();
|
||||
var sendstr = System.Text.Encoding.Default.GetString(barr);
|
||||
//RaiseMessage(MessageType.Normal, "Tx:" + barr.HexString());
|
||||
//WriteData(barr);
|
||||
return true;
|
||||
}
|
||||
|
||||
protected override bool CustomParser(byte[] buf, out byte[] remainBuffer)
|
||||
{
|
||||
|
||||
List<byte> remain = new List<byte>();
|
||||
bool retval = false;
|
||||
foreach (var b in buf)
|
||||
{
|
||||
if (retval)
|
||||
{
|
||||
remain.Add(b);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (b == 0x02) //stx
|
||||
{
|
||||
tempBuffer.Clear();
|
||||
tempBuffer.Add(b);
|
||||
}
|
||||
else if (b == 0x03) //etx
|
||||
{
|
||||
tempBuffer.Add(b);
|
||||
retval = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (tempBuffer.Count > 0 && tempBuffer[0] == 0xDD)
|
||||
{
|
||||
tempBuffer.Add(b);
|
||||
if (tempBuffer.Count > 10)
|
||||
{
|
||||
RaiseMessage(MessageType.Error, "buffer over");
|
||||
tempBuffer.Clear();
|
||||
retval = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//trash
|
||||
}
|
||||
}
|
||||
}
|
||||
remainBuffer = remain.ToArray();
|
||||
return retval;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user