Commit 588b37fa authored by 潘栩锋's avatar 潘栩锋 🚴

完成 flyad2021core

parent 27a325f8
......@@ -642,6 +642,7 @@ namespace FLY.Simulation.Flyad7
public int Speed { get; set; }
public int AD { get; set; }
public int ADMax
......
......@@ -306,6 +306,19 @@ namespace FlyADBase
pos1_LCShift = Pos1LCShift
}.ToBytes());
}
else if (e.PropertyName == nameof(Pos2LCShift))
{
CurrObjSys.CallFunctionEx(
conn,
FLYAD7_OBJ_INTERFACE.DRIVE_MAN_INTERFACE.ID,
ID,
FLYAD7_OBJ_INTERFACE.DRIVE_MAN_INTERFACE.CALL_PXX,
new FLYAD7_OBJ_INTERFACE.DRIVE_MAN_INTERFACE.Pack_Pos2Shift()
{
pos2_shift = Pos2LCShift
}.ToBytes());
}
}
void Init()
......@@ -1042,6 +1055,17 @@ namespace FlyADBase
/// </summary>
public int Speed { get; private set; }
/// <summary>
/// 纵向脉冲速度, pps, 1秒脉冲数
/// </summary>
public int Speed2 { get; private set; }
/// <summary>
/// 纵向脉冲,也叫主轴脉冲
/// </summary>
public int Position2 { get; private set; }
/// <summary>
/// 1000ms从AD卡获取(或推送)1个AD值。此AD值只用于调试,定点
/// </summary>
......@@ -1528,95 +1552,19 @@ namespace FlyADBase
/// </summary>
public Int32 Marker { get; protected set; }
#region 横向脉冲
/// <summary>
/// 逻辑横向脉冲偏移 Pos1 + Pos1LCShift = Pos1LC
/// </summary>
public int Pos1LCShift { get; set; }
#endregion
#region 主轴脉冲
/// <summary>
/// 纵向脉冲速度, pps, 1秒脉冲数
/// </summary>
public int Speed2 { get; set; }
/// <summary>
/// 纵向脉冲,也叫主轴脉冲
/// </summary>
public int Position2 { get; private set; }
/// <summary>
/// 设置纵向位置
/// </summary>
/// <param name="postion2"></param>
[Obsolete("pos2 不应该被修改")]
public void SetPos2(int postion2)
{
CurrObjSys.CallFunctionEx(
conn,
FLYAD7_OBJ_INTERFACE.DRIVE_MAN_INTERFACE.ID,
ID,
FLYAD7_OBJ_INTERFACE.DRIVE_MAN_INTERFACE.CALL_PXX,
new FLYAD7_OBJ_INTERFACE.DRIVE_MAN_INTERFACE.Pack_Pos2()
{
pos2 = postion2
}.ToBytes());
}
/// <summary>
/// 纵向偏移
/// 逻辑纵向脉冲偏移 Pos2 + Pos2LCShift = Pos2LC
/// </summary>
public void SetPos2Offset(int offset)
{
CurrObjSys.CallFunctionEx(
conn,
FLYAD7_OBJ_INTERFACE.DRIVE_MAN_INTERFACE.ID,
ID,
FLYAD7_OBJ_INTERFACE.DRIVE_MAN_INTERFACE.CALL_PXX,
new FLYAD7_OBJ_INTERFACE.DRIVE_MAN_INTERFACE.Pack_Pos2Shift()
{
pos2_shift = offset
}.ToBytes());
}
public int Pos2LCShift { get; set; }
/// <summary>
/// 纵向同步事件,0-1事件
/// </summary>
/// <param name="pos2"></param>
/// <param name="immediately">只要是 01,就立刻修正</param>
[Obsolete("pos2 不应该被修改")]
public void SetPos2At01(int pos2, bool immediately)
{
CurrObjSys.CallFunctionEx(
conn,
FLYAD7_OBJ_INTERFACE.DRIVE_MAN_INTERFACE.ID,
ID,
FLYAD7_OBJ_INTERFACE.DRIVE_MAN_INTERFACE.CALL_PXX,
new FLYAD7_OBJ_INTERFACE.DRIVE_MAN_INTERFACE.Pack_Pos2_01()
{
pos2 = pos2,
immediately = immediately
}.ToBytes());
LastPos2At01 = pos2;
}
#endregion
#region 同步控制 同步状态转换规则
/// <summary>
/// 进入同步状态
/// </summary>
/// <param name="pos2"></param>
[Obsolete("pos2 不应该被修改")]
public void SyncBegin(int pos2)
{
Drive(DRIVE_MAN_ORDER.SYNC, pos2);
IsSync = true;
}
/// <summary>
/// 进入同步状态
/// </summary>
......@@ -1653,19 +1601,7 @@ namespace FlyADBase
SyncOrders.Clear();
}
/// <summary>
/// 清空POS2同步列表
/// </summary>
[Obsolete("pos2 不应该被修改")]
public void SyncPos2Clear()
{
CurrObjSys.CallFunctionEx(
conn,
FLYAD7_OBJ_INTERFACE.DRIVE_MAN_INTERFACE.ID,
ID,
FLYAD7_OBJ_INTERFACE.DRIVE_MAN_INTERFACE.CALL_PXX,
new FLYAD7_OBJ_INTERFACE.DRIVE_MAN_INTERFACE.Pack_SyncPos2Clear().ToBytes());
}
#endregion
#region 同步扫描 脚本指令
......@@ -1677,8 +1613,8 @@ namespace FlyADBase
/// <param name="pos2_end"></param>
/// <param name="pos1lc"></param>
/// <param name="hasDataGrid"></param>
/// <param name="marker"></param>public void SyncRunAtLC(int pos2_begin, int pos2_end, int pos1lc, bool hasDataGrid, Int32 marker)
public void SyncRunAtLC(int pos2_begin, int pos2_end, int pos1lc, bool hasDataGrid, Int32 marker)
/// <param name="marker"></param>
public void SyncRunAtLC(int pos2lc_begin, int pos2lc_end, int pos1lc, bool hasDataGrid, Int32 marker)
{
CurrObjSys.CallFunctionEx(
conn,
......@@ -1687,8 +1623,8 @@ namespace FlyADBase
FLYAD7_OBJ_INTERFACE.DRIVE_MAN_INTERFACE.CALL_PXX,
new FLYAD7_OBJ_INTERFACE.DRIVE_MAN_INTERFACE.Pack_SyncRunAtLC()
{
pos2_begin = pos2_begin,
pos2_end = pos2_end,
pos2_begin = pos2lc_begin,
pos2_end = pos2lc_end,
pos1lc = pos1lc,
hasDataGrid = hasDataGrid,
marker = marker
......@@ -1696,8 +1632,8 @@ namespace FlyADBase
SyncOrders.Add(new SyncOrder_SyncRunAtLC()
{
Pos2Begin = pos2_begin,
Pos2End = pos2_end,
Pos2Begin = pos2lc_begin,
Pos2End = pos2lc_end,
Pos1LC = pos1lc,
HasDataGrid = hasDataGrid,
Marker = marker
......
......@@ -45,6 +45,16 @@ namespace FlyADBase
/// </summary>
int Speed { get; }
/// <summary>
/// 纵向脉冲,也叫主轴脉冲
/// </summary>
int Position2 { get; }
/// <summary>
/// 纵向速度
/// </summary>
int Speed2 { get; }
/// <summary>
/// 1000ms从AD卡获取(或推送)1个AD值。此AD值只用于调试,定点
/// </summary>
......@@ -73,11 +83,6 @@ namespace FlyADBase
/// <param name="enable"></param>
void SetOutput(UInt16 mask, UInt16 enable);
/// <summary>
/// 读取参数, 全部!!!!
/// </summary>
void UpdateParam();
#region 运动参数
/// <summary>
/// 设置 运动参数
......@@ -86,7 +91,7 @@ namespace FlyADBase
/// <param name="motortype">电机类型</param>
/// <param name="ratio01">脉冲比例 分母(电机脉冲)</param>
/// <param name="ratio02">脉冲比例 分子(编码器脉冲)</param>
void SetSysParam(UInt16 posOfGrid, MOTORTYPE motortype, UInt16 ratio01, UInt16 ratio02);
//void SetSysParam(UInt16 posOfGrid, MOTORTYPE motortype, UInt16 ratio01, UInt16 ratio02);
/// <summary>
/// 电机类型
/// </summary>
......@@ -267,54 +272,21 @@ namespace FlyADBase
/// 同步用标示
/// </summary>
Int32 Marker { get; }
#region 横向脉冲
/// <summary>
/// 逻辑横向脉冲偏移 Pos1 + Pos1LCShift = Pos1LC
/// </summary>
int Pos1LCShift { get; set; }
#endregion
#region 主轴脉冲
/// <summary>
/// 纵向脉冲,也叫主轴脉冲
/// </summary>
int Position2 { get; }
/// <summary>
/// 纵向速度
/// </summary>
int Speed2 { get; }
/// <summary>
/// 设置纵向位置
/// 逻辑纵向脉冲偏移 Pos2 + Pos2LCShift = Pos2LC
/// </summary>
/// <param name="postion2"></param>
[Obsolete("pos2 不应该被修改")]
void SetPos2(int postion2);
int Pos2LCShift { get; set; }
/// <summary>
/// 纵向偏移,这个是相对量
/// </summary>
[Obsolete("pos2 不应该被修改")]
void SetPos2Offset(int offset);
/// <summary>
/// 纵向同步事件,0-1事件
/// </summary>
/// <param name="pos2"></param>
/// <param name="immediately">只要是 01,就立刻修正</param>
[Obsolete("pos2 不应该被修改")]
void SetPos2At01(int pos2, bool immediately);
#endregion
#region 同步控制 同步状态转换规则
/// <summary>
/// 进入同步状态
/// </summary>
/// <param name="pos2"></param>
[Obsolete("pos2 不应该被修改")]
void SyncBegin(int pos2);
/// <summary>
/// 进入同步状态
/// </summary>
void SyncBegin();
/// <summary>
/// 退出同步状态
......@@ -324,24 +296,19 @@ namespace FlyADBase
/// 清空同步指令
/// </summary>
void SyncClear();
/// <summary>
/// 清空POS2同步列表
/// </summary>
[Obsolete("pos2 不应该被修改")]
void SyncPos2Clear();
#endregion
#region 同步扫描 脚本指令
/// <summary>
/// 同步扫描至;
/// D+0xE0+开始主轴位置+结束主轴位置+结束横向脉冲位置(逻辑位置)+脉冲开关(1B)+命令识标号(4B)
/// D+0xE0+开始主轴位置(逻辑位置)+结束主轴位置(逻辑位置)+结束横向脉冲位置(逻辑位置)+脉冲开关(1B)+命令识标号(4B)
/// </summary>
/// <param name="pos2_begin"></param>
/// <param name="pos2_end"></param>
/// <param name="pos2lc_begin"></param>
/// <param name="pos2lc_end"></param>
/// <param name="pos1lc"></param>
/// <param name="hasDataGrid"></param>
/// <param name="marker"></param>
void SyncRunAtLC(int pos2_begin, int pos2_end, int pos1lc, bool hasDataGrid, Int32 marker);
void SyncRunAtLC(int pos2lc_begin, int pos2lc_end, int pos1lc, bool hasDataGrid, Int32 marker);
/// <summary>
......
......@@ -42,10 +42,12 @@
<Reference Include="WindowsBase" />
</ItemGroup>
<ItemGroup>
<Compile Include="FlyAd2021Base.cs" />
<Compile Include="FlyAd2021Comm_SerialPort.cs" />
<Compile Include="FlyAd2021Core.cs" />
<Compile Include="FlyAd2021.cs" />
<Compile Include="Inc\IFlyAd2021Base.cs" />
<Compile Include="PackEventArgs.cs" />
<Compile Include="FlyAd2021Comm_TcpClient.cs" />
<Compile Include="Inc\IFlyAd2021Comm.cs" />
<Compile Include="Inc\IFlyAd2021Core.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ProtocolCommon.cs" />
</ItemGroup>
......
using FlyAd2021.Inc;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO.Ports;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace FlyAd2021
{
public class FlyAd2021Comm_SerialPort : IFlyAd2021Comm
{
/// <summary>
/// 串口号
/// </summary>
public string Addr { get; set; }
/// <summary>
/// 是否异常
/// </summary>
public bool IsError => !string.IsNullOrEmpty(ErrMsg);
/// <summary>
/// 异常信息
/// </summary>
public string ErrMsg { get; private set; }
/// <summary>
/// Open 成功
/// </summary>
public bool IsConnected { get; private set; }
/// <summary>
/// 运行中
/// </summary>
public bool IsRunning { get; private set; }
/// <summary>
/// 接收task调用
/// </summary>
public event Action<byte[]> RecMsg;
public event PropertyChangedEventHandler PropertyChanged;
SerialPort sp;
CancellationTokenSource cancellation;
CancellationTokenSource cancellation_waitforSend;
public FlyAd2021Comm_SerialPort()
{
sp = new SerialPort();
sp.BaudRate = 115200 * 2; ;
sp.Parity = Parity.None;
sp.StopBits = StopBits.One;
}
public void SendMsg(byte[] msg)
{
if (!IsConnected)
return;
try
{
sp.Write(msg, 0, msg.Length);
ErrMsg = null;
}
catch (Exception e) {
ErrMsg = e.Message;
IsConnected = false;
}
}
void OnTask()
{
while (!cancellation.IsCancellationRequested)
{
ConnectTask();
if (IsConnected)
{
//进入接收task
ReceiveTask();
}
//休息一会儿,在重连
try
{
Task.Delay(2000, cancellation.Token).Wait();
}
catch (Exception e)
{
//被打断了
break;
}
}
IsConnected = false;
}
/// <summary>
/// 连接任务
/// </summary>
void ConnectTask()
{
sp.PortName = Addr;
while (!cancellation.IsCancellationRequested)
{
try
{
sp.Open();
IsConnected = true;
ErrMsg = null;
return;
}
catch (Exception e)
{
//连接出错
//等待重试
ErrMsg = e.Message;
}
try
{
Task.Delay(2000, cancellation.Token).Wait();
}
catch (Exception e)
{
//被打断
return;
}
}
}
/// <summary>
/// 接收任务
/// </summary>
void ReceiveTask()
{
sp.DataReceived += Sp_DataReceived;
while (!cancellation.IsCancellationRequested)
{
if (!IsConnected)
break;
try
{
Task.Delay(1000, cancellation.Token).Wait();
}
catch (Exception e)
{
//被打断了
break;
}
}
sp.DataReceived -= Sp_DataReceived;
}
public void Start()
{
if (IsRunning)
return;
IsRunning = true;
sp.PortName = Addr;
cancellation = new CancellationTokenSource();
Task.Factory.StartNew(OnTask, cancellation.Token);
}
private void Sp_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
int bytesToRead = sp.BytesToRead;
if (bytesToRead <= 0)
return;
byte[] recBuf = new byte[bytesToRead];
sp.Read(recBuf, 0, bytesToRead);
RecMsg?.Invoke(recBuf);
}
public void Stop()
{
if (!IsRunning)
return;
IsRunning = false;
cancellation.Cancel();
sp.Close();
}
}
}
using FlyAd2021.Inc;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace FlyAd2021
{
/// <summary>
/// AD盒2021版,通讯模块,只负责 调用 核心模块 的Rec, Send
/// </summary>
public class FlyAd2021Comm_TcpClient : IFlyAd2021Comm
{
/// <summary>
/// IP 地址 and 端口号
/// </summary>
public string Addr { get; set; }
IPEndPoint RemoteEp => Misc.StringConverter.ToIPEndPoint(Addr);
/// <summary>
/// 是否异常
/// </summary>
public bool IsError => !string.IsNullOrEmpty(ErrMsg);
/// <summary>
/// 异常信息
/// </summary>
public string ErrMsg { get; private set; }
/// <summary>
/// 运行中
/// </summary>
public bool IsRunning { get; private set; }
/// <summary>
/// 连接成功
/// </summary>
public bool IsConnected { get; private set; }
/// <summary>
/// 接收task调用
/// </summary>
public event Action<byte[]> RecMsg;
public event PropertyChangedEventHandler PropertyChanged;
Socket sock;
CancellationTokenSource cancellation;
CancellationTokenSource cancellation_waitforSend;
public FlyAd2021Comm_TcpClient()
{
}
/// <summary>
/// 开始
/// </summary>
public void Start()
{
if (IsRunning)
return;
IsRunning = true;
cancellation = new CancellationTokenSource();
Task.Factory.StartNew(OnTask, cancellation.Token);
}
/// <summary>
/// 接收
/// </summary>
public void Stop()
{
if (!IsRunning)
return;
IsRunning = false;
cancellation.Cancel();
if (sock != null && sock.Connected)
{
sock.Close();
sock = null;
}
}
void OnTask()
{
while (!cancellation.IsCancellationRequested)
{
ConnectTask();
if (IsConnected)
{
sendBuf.Clear();
//启动发送task
Task.Factory.StartNew(SendTask, cancellation.Token);
//进入接收task
ReceiveTask();
//退出了,肯定连接断开了
}
//休息一会儿,在重连
try
{
Task.Delay(2000, cancellation.Token).Wait();
}
catch (Exception e)
{
//被打断了
break;
}
}
IsConnected = false;
}
/// <summary>
/// 连接任务
/// </summary>
void ConnectTask()
{
sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
sock.Blocking = true;
//1秒内,需要收到信息
sock.ReceiveTimeout = 1000;
//1秒内,必须发送完
sock.SendTimeout = 1000;
while (!cancellation.IsCancellationRequested)
{
try
{
sock.Connect(RemoteEp);
IsConnected = true;
ErrMsg = null;
return;
}
catch (SocketException e)
{
//连接出错
//等待重试
ErrMsg = e.Message;
}
try
{
Task.Delay(2000, cancellation.Token).Wait();
}
catch (Exception e)
{
//被打断
return;
}
}
}
/// <summary>
/// 接收任务
/// </summary>
void ReceiveTask()
{
byte[] buf = new byte[0x10000];
while (!cancellation.IsCancellationRequested)
{
int len;
try
{
len = sock.Receive(buf);
if (len == 0)
{
continue;//没收到数据,继续等
}
}
catch (SocketException e)
{
if (e.SocketErrorCode == SocketError.TimedOut)
continue;//超时而已
else if ((e.SocketErrorCode == SocketError.ConnectionAborted)
|| (e.SocketErrorCode == SocketError.ConnectionRefused)
|| (e.SocketErrorCode == SocketError.ConnectionReset))
{
IsConnected = false;
return;
}
//Console.WriteLine($"ReceiveTask() {e}");
//肯定断开连接了
IsConnected = false;
break;
}
RecMsg?.Invoke(buf.Take(len).ToArray());
}
if (sock != null)
{
sock.Close();
}
IsConnected = false;
}
/// <summary>
/// 发送任务
/// </summary>
void SendTask()
{
while (!cancellation.IsCancellationRequested)
{
while (sendBuf.Count > 0)
{
int slen;
try
{
slen = sock.Send(sendBuf.ToArray());
}
catch (Exception e)
{
//连接断开了
IsConnected = false;
break;
}
if (slen > 0)
sendBuf.RemoveRange(0, slen);
else if (slen <= 0)
{
//连接断开了
IsConnected = false;
break;
}
}
//重新等 下次被呼醒
cancellation_waitforSend = new CancellationTokenSource();
try
{
Task.Delay(-1, cancellation_waitforSend.Token).Wait();
}
catch (Exception e)
{
//被打断, 有数据需要发送
}
}
}
/// <summary>
/// 无限大,发送缓存
/// </summary>
List<byte> sendBuf = new List<byte>();
/// <summary>
/// 发送数据
/// </summary>
/// <param name="msg"></param>
public void SendMsg(byte[] msg)
{
if (!IsConnected)
return;
//放入,发送缓存区
sendBuf.AddRange(msg);
//呼醒 发送task
cancellation_waitforSend.Cancel();
}
}
}
<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd">
<PropertyChanged />
</Weavers>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<!-- This file was generated by Fody. Manual changes to this file will be lost when your project is rebuilt. -->
<xs:element name="Weavers">
<xs:complexType>
<xs:all>
<xs:element name="PropertyChanged" minOccurs="0" maxOccurs="1">
<xs:complexType>
<xs:attribute name="InjectOnPropertyNameChanged" type="xs:boolean">
<xs:annotation>
<xs:documentation>Used to control if the On_PropertyName_Changed feature is enabled.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="TriggerDependentProperties" type="xs:boolean">
<xs:annotation>
<xs:documentation>Used to control if the Dependent properties feature is enabled.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="EnableIsChangedProperty" type="xs:boolean">
<xs:annotation>
<xs:documentation>Used to control if the IsChanged property feature is enabled.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="EventInvokerNames" type="xs:string">
<xs:annotation>
<xs:documentation>Used to change the name of the method that fires the notify event. This is a string that accepts multiple values in a comma separated form.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="CheckForEquality" type="xs:boolean">
<xs:annotation>
<xs:documentation>Used to control if equality checks should be inserted. If false, equality checking will be disabled for the project.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="CheckForEqualityUsingBaseEquals" type="xs:boolean">
<xs:annotation>
<xs:documentation>Used to control if equality checks should use the Equals method resolved from the base class.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="UseStaticEqualsFromBase" type="xs:boolean">
<xs:annotation>
<xs:documentation>Used to control if equality checks should use the static Equals method resolved from the base class.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="SuppressWarnings" type="xs:boolean">
<xs:annotation>
<xs:documentation>Used to turn off build warnings from this weaver.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="SuppressOnPropertyNameChangedWarning" type="xs:boolean">
<xs:annotation>
<xs:documentation>Used to turn off build warnings about mismatched On_PropertyName_Changed methods.</xs:documentation>
</xs:annotation>
</xs:attribute>
</xs:complexType>
</xs:element>
</xs:all>
<xs:attribute name="VerifyAssembly" type="xs:boolean">
<xs:annotation>
<xs:documentation>'true' to run assembly verification (PEVerify) on the target assembly after all weavers have been executed.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="VerifyIgnoreCodes" type="xs:string">
<xs:annotation>
<xs:documentation>A comma-separated list of error codes that can be safely ignored in assembly verification.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="GenerateXsd" type="xs:boolean">
<xs:annotation>
<xs:documentation>'false' to turn off automatic generation of the XML Schema file.</xs:documentation>
</xs:annotation>
</xs:attribute>
</xs:complexType>
</xs:element>
</xs:schema>
\ No newline at end of file
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FlyAd2021.Inc
{
public interface IFlyAd2021Comm:INotifyPropertyChanged
{
/// <summary>
/// IP 地址 and 端口号
/// </summary>
string Addr { get; set; }
/// <summary>
/// 是否异常
/// </summary>
bool IsError { get; }
/// <summary>
/// 异常信息
/// </summary>
string ErrMsg { get; }
/// <summary>
/// 连接成功
/// </summary>
bool IsConnected { get; }
/// <summary>
/// 运行中
/// </summary>
bool IsRunning { get; }
/// <summary>
/// 开始
/// </summary>
void Start();
/// <summary>
/// 接收
/// </summary>
void Stop();
/// <summary>
/// 发送数据
/// </summary>
/// <param name="msg"></param>
void SendMsg(byte[] msg);
/// <summary>
/// 接收数据
/// </summary>
event Action<byte[]> RecMsg;
}
}
using System;
using FlyADBase;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
......@@ -8,9 +9,10 @@ using System.Threading.Tasks;
namespace FlyAd2021.Inc
{
/// <summary>
/// 实现基本的AD盒2021版 基本实现
/// AD盒2021版 , 核心模块
/// 实现AD盒2021版 基本接口
/// </summary>
public interface IFlyAd2021Base : INotifyPropertyChanged
public interface IFlyAd2021Core : INotifyPropertyChanged
{
#region 测量速度
bool IsMeasuring { get; }
......@@ -36,8 +38,6 @@ namespace FlyAd2021.Inc
void StopMeasure();
#endregion
/// <summary>
/// 包出错次数
/// </summary>
......@@ -49,6 +49,14 @@ namespace FlyAd2021.Inc
/// </summary>
bool IsConnected { get; }
#region 模块运行接口
/// <summary>
/// 超时判断,长时间收不到数据,会触发,0.5s调用一次
/// </summary>
void OnPoll_TimeOut();
/// <summary>
/// 在接收事件中调用;
/// 全部接收事件 及 超时事件也是在这里触发
......@@ -60,12 +68,27 @@ namespace FlyAd2021.Inc
/// </summary>
/// <returns></returns>
byte[] GetSendMsg();
/// <summary>
/// 有数据需要发送
/// </summary>
/// <param name="sender"></param>
event SendMsgEventHander SendMsgEvent;
/// <summary>
/// 复位全部状态,通常由于通讯模块检测到连接断开导致的
/// </summary>
void ResetMsg();
#endregion
#region AD 功能
/// <summary>
/// 数据推送事件
/// </summary>
event PushDataEventHandler PushDataEvent;
/// <summary>
/// 运行状态推送事件
/// </summary>
event PushRunResultEventHandler PushRunResultEvent;
#region IOComm IO指令
[CallBack(typeof(UInt16))]
......@@ -89,31 +112,31 @@ namespace FlyAd2021.Inc
#region RunComm 运行指令 SetRunParam
void SetRunParamV(UInt32 velocity, CallBackHandler asyncDelegate, object asyncContext);
void SetRunParam_V(UInt32 velocity, CallBackHandler asyncDelegate, object asyncContext);
void SetRunParamSV(UInt32 sv, CallBackHandler asyncDelegate, object asyncContext);
void SetRunParam_SV(UInt32 sv, CallBackHandler asyncDelegate, object asyncContext);
void SetRunParamAccTime(UInt32 accTime, CallBackHandler asyncDelegate, object asyncContext);
void SetRunParam_AccTime(UInt32 accTime, CallBackHandler asyncDelegate, object asyncContext);
void SetRunParamDecTime(UInt32 decTime, CallBackHandler asyncDelegate, object asyncContext);
void SetRunParam_DecTime(UInt32 decTime, CallBackHandler asyncDelegate, object asyncContext);
void SetRunParamHSpd1(UInt32 homespd1, CallBackHandler asyncDelegate, object asyncContext);
void SetRunParam_HSpd1(UInt32 homespd1, CallBackHandler asyncDelegate, object asyncContext);
void SetRunParamHSpd2(UInt32 homespd2, CallBackHandler asyncDelegate, object asyncContext);
void SetRunParam_HSpd2(UInt32 homespd2, CallBackHandler asyncDelegate, object asyncContext);
#endregion
#region RunComm 运行指令 GetRunParam
void GetRunParamV(CallBackHandler asyncDelegate, object asyncContext);
void GetRunParam_V(CallBackHandler asyncDelegate, object asyncContext);
void GetRunParamSV(CallBackHandler asyncDelegate, object asyncContext);
void GetRunParam_SV(CallBackHandler asyncDelegate, object asyncContext);
void GetRunParamAccTime(CallBackHandler asyncDelegate, object asyncContext);
void GetRunParam_AccTime(CallBackHandler asyncDelegate, object asyncContext);
void GetRunParamDecTime(CallBackHandler asyncDelegate, object asyncContext);
void GetRunParam_DecTime(CallBackHandler asyncDelegate, object asyncContext);
void GetRunParamHSpd1(CallBackHandler asyncDelegate, object asyncContext);
void GetRunParam_HSpd1(CallBackHandler asyncDelegate, object asyncContext);
void GetRunParamHSpd2(CallBackHandler asyncDelegate, object asyncContext);
void GetRunParam_HSpd2(CallBackHandler asyncDelegate, object asyncContext);
#endregion
......@@ -193,16 +216,74 @@ namespace FlyAd2021.Inc
#endregion
#region SysParamComm 系统参数指令
//[CallBack(typeof(UInt32))]
//void GetSysTick(CallBackHandler asyncDelegate, object asyncContext);
//void InitArea0()
/// <summary>
/// 获取系统当前Tick
/// </summary>
[CallBack(typeof(UInt32))]
void GetSysTick(CallBackHandler asyncDelegate, object asyncContext);
/// <summary>
/// 初始化系统信息区
/// </summary>
/// <param name="asyncDelegate"></param>
/// <param name="asyncContext"></param>
[CallBack(typeof(bool))]
void InitArea(CallBackHandler asyncDelegate, object asyncContext);
/// <summary>
/// 输入系统授权码
/// </summary>
/// <param name="access"></param>
/// <param name="asyncDelegate"></param>
/// <param name="asyncContext"></param>
[CallBack(typeof(AREA_ERR))]
void CheckAccessCode(byte[] access, CallBackHandler asyncDelegate, object asyncContext);
/// <summary>
/// 获取系统授权信息
/// </summary>
/// <param name="asyncDelegate"></param>
/// <param name="asyncContext"></param>
[CallBack(typeof(GetAccess_Reponse))]
void GetAccess(CallBackHandler asyncDelegate, object asyncContext);
/// <summary>
/// 系统运行时间+1
/// </summary>
/// <param name="asyncDelegate"></param>
/// <param name="asyncContext"></param>
void AddAccess(CallBackHandler asyncDelegate, object asyncContext);
#endregion
#region GetSysParam 读运行参数
[CallBack(typeof(MOTORTYPE))]
void GetSysParam_MotorType(CallBackHandler asyncDelegate, object asyncContext);
[CallBack(typeof(UInt16))]
void GetSysParam_Ratio01(CallBackHandler asyncDelegate, object asyncContext);
[CallBack(typeof(UInt16))]
void GetSysParam_Ratio02(CallBackHandler asyncDelegate, object asyncContext);
[CallBack(typeof(Int16))]
void GetSysParam_Zero(CallBackHandler asyncDelegate, object asyncContext);
[CallBack(typeof(UInt32))]
void GetSysParam_Jog(CallBackHandler asyncDelegate, object asyncContext);
#endregion
#region SetSysParam 设置运行参数
void SetSysParam_MotorType(MOTORTYPE motorType, CallBackHandler asyncDelegate, object asyncContext);
void SetSysParam_Ratio01(UInt16 ratio01, CallBackHandler asyncDelegate, object asyncContext);
void SetSysParam_Ratio02(UInt16 ratio02, CallBackHandler asyncDelegate, object asyncContext);
void SetSysParam_Zero(Int16 zero, CallBackHandler asyncDelegate, object asyncContext);
void SetSysParam_Jog(UInt32 jog, CallBackHandler asyncDelegate, object asyncContext);
#endregion
#endregion
}
......@@ -224,6 +305,20 @@ namespace FlyAd2021.Inc
}
public delegate void PushDataEventHandler(object sender, PushDataEventArgs e);
public class PushRunResultEventArgs : EventArgs
{
public byte SysTick { get; set; }
/// <summary>
/// 运行序号
/// </summary>
public UInt32 Serial { get; set; }
/// <summary>
/// 运行状态
/// </summary>
public DRIVE_MAN_STATUS Status { get; set; }
}
public delegate void PushRunResultEventHandler(object sender, PushRunResultEventArgs e);
/// <summary>
/// 异常不回复
/// </summary>
......@@ -232,7 +327,7 @@ namespace FlyAd2021.Inc
public delegate void CallBackHandler(object asyncContext, object retData);
public sealed class CallBackAttribute : Attribute
public class CallBackAttribute : Attribute
{
public Type RetType;
public CallBackAttribute(Type type)
......@@ -241,14 +336,31 @@ namespace FlyAd2021.Inc
}
}
/// <summary>
/// 有数据需要发送
/// </summary>
/// <param name="sender"></param>
public delegate void SendMsgEventHander(object sender);
public class GetEncAll_Reponse
{
public int pos1;
public int pos2;
}
public class GetRunResult_Reponse
{
public byte result;
public DRIVE_MAN_STATUS result;
public UInt32 serial;
}
public class GetAccess_Reponse
{
public AREA_STATUS status;
public AREA_ERR ret;
public byte[] code = new byte[6];
public UInt16 surplus;
public byte[] access = new byte[8];
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FlyAd2021
{
public class PackEventArgs : EventArgs
{
public PackEventArgs()
{
}
/// <summary>
/// 数据
/// </summary>
public List<byte> Pack { get; set; }
/// <summary>
/// 开始时间点
/// </summary>
public DateTime Time { get; set; }
}
public delegate void PackEventHandler(object sender, PackEventArgs e);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment