|
|
|
|
using EGFramework;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 检测串口对应的空轨驱动器,或是颜色传感器,检测后记录到串口列表中
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class ModelSerialTest : EGModule,IEGFramework
|
|
|
|
|
{
|
|
|
|
|
public const int BAUD_RATE_ENGINE = 9600;
|
|
|
|
|
public const int BAUD_RATE_COLOR = 38400;
|
|
|
|
|
|
|
|
|
|
public const string PORT_LINUX = "/dev/ttyUSB0";
|
|
|
|
|
|
|
|
|
|
public const string PORT_WIN = "COM2";
|
|
|
|
|
|
|
|
|
|
public bool IsLinux = true;
|
|
|
|
|
|
|
|
|
|
public string TestPort { set; get; } = PORT_LINUX;
|
|
|
|
|
public string ColorSerialPort { set; get; } = "";
|
|
|
|
|
public string EngineSerialPort { set; get; } = "";
|
|
|
|
|
|
|
|
|
|
public IUnRegister ColorSensorInitEvent { set; get; }
|
|
|
|
|
|
|
|
|
|
public IUnRegister EngineInitEvent{ set; get; }
|
|
|
|
|
|
|
|
|
|
public override void Init()
|
|
|
|
|
{;
|
|
|
|
|
this.EGOnMessage<ResponseTarget>();
|
|
|
|
|
if (!IsLinux)
|
|
|
|
|
{
|
|
|
|
|
TestPort = PORT_WIN;
|
|
|
|
|
}
|
|
|
|
|
InitSerialPort();
|
|
|
|
|
// throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async void InitSerialPort()
|
|
|
|
|
{
|
|
|
|
|
this.EGSerialPort().Open(TestPort, 9600);
|
|
|
|
|
this.EGSendMessage(new RequestTargetReadEnabled(), TestPort, ProtocolType.SerialPort);
|
|
|
|
|
EngineInitEvent = this.EGRegisterMessageEvent<ResponseTarget>(OnEngineInit);
|
|
|
|
|
await Task.Delay(2000);
|
|
|
|
|
if(EngineSerialPort == "")
|
|
|
|
|
{
|
|
|
|
|
this.EGSerialPort().Close(TestPort);
|
|
|
|
|
EG.Print("Engine init failed USB,Time out.");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void OnEngineInit(ResponseTarget res,string sender,ProtocolType type)
|
|
|
|
|
{
|
|
|
|
|
if (type == ProtocolType.SerialPort)
|
|
|
|
|
{
|
|
|
|
|
EngineInitEvent.UnRegister();
|
|
|
|
|
this.EngineSerialPort = sender;
|
|
|
|
|
EG.Print("Engine sensor init success!");
|
|
|
|
|
this.GetModule<ModelTrackControl>();
|
|
|
|
|
// this.GetModule<ModelTrackControl>().ResetTrack();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|