Commit 4e0d0f28 authored by 潘栩锋's avatar 潘栩锋 🚴

Window_Tip 修改为 mvvm架构 整理 flyadService

parent 9634c9f8
...@@ -208,6 +208,12 @@ ...@@ -208,6 +208,12 @@
<PackageReference Include="Microsoft.Xaml.Behaviors.Wpf"> <PackageReference Include="Microsoft.Xaml.Behaviors.Wpf">
<Version>1.0.1</Version> <Version>1.0.1</Version>
</PackageReference> </PackageReference>
<PackageReference Include="MvvmLight">
<Version>5.4.1.1</Version>
</PackageReference>
<PackageReference Include="PropertyChanged.Fody">
<Version>2.6.1</Version>
</PackageReference>
</ItemGroup> </ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
......
<?xml version="1.0" encoding="utf-8"?>
<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="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: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
<Window x:Class="FLY.ControlLibrary.Window_Tip" <Window x:Class="FLY.ControlLibrary.Window_Tip"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Name="window_my" Width="400" Topmost="True" WindowStyle="None" ShowInTaskbar="False" ResizeMode="NoResize" Loaded="Window_Loaded" HorizontalContentAlignment="Right" VerticalContentAlignment="Bottom" SizeToContent="Height">
Title="Window_Tip" Width="400" Topmost="True" WindowStyle="None" ShowInTaskbar="False" ResizeMode="NoResize" Loaded="Window_Loaded" HorizontalContentAlignment="Right" VerticalContentAlignment="Bottom" SizeToContent="Height">
<Window.Resources> <Window.Resources>
<ResourceDictionary> <ResourceDictionary>
<ResourceDictionary.MergedDictionaries> <ResourceDictionary.MergedDictionaries>
...@@ -14,10 +13,10 @@ ...@@ -14,10 +13,10 @@
<Border BorderThickness="1" BorderBrush="Black"> <Border BorderThickness="1" BorderBrush="Black">
<Grid> <Grid>
<StackPanel Margin="10,5"> <StackPanel Margin="10,5">
<TextBlock Text="{Binding Title,ElementName=window_my}" FontWeight="Bold" FontSize="30" FontFamily="YouYuan" Margin="10,5"/> <TextBlock Text="{Binding Title}" FontWeight="Bold" FontSize="30" FontFamily="YouYuan" Margin="10,5"/>
<TextBlock Name="textblock_message" FontWeight="Bold" FontSize="15" FontFamily="YouYuan" Margin="20,5" TextWrapping="Wrap" /> <TextBlock Text="{Binding Message}" FontWeight="Bold" FontSize="15" FontFamily="YouYuan" Margin="20,5" TextWrapping="Wrap" />
</StackPanel> </StackPanel>
<Button Style="{StaticResource ResourceKey=ButtonStyle_empty}" Click="Button_Click" Background="Red" VerticalAlignment="Top" HorizontalAlignment="Right" > <Button Style="{StaticResource ResourceKey=ButtonStyle_empty}" Command="{Binding CloseCmd}" Background="Red" VerticalAlignment="Top" HorizontalAlignment="Right" >
<Path Data="{StaticResource ResourceKey=Geometry_window-close}" Fill="White" Height="36" Width="36" Stretch="Fill" SnapsToDevicePixels="True" Margin="4"/> <Path Data="{StaticResource ResourceKey=Geometry_window-close}" Fill="White" Height="36" Width="36" Stretch="Fill" SnapsToDevicePixels="True" Margin="4"/>
......
...@@ -11,6 +11,7 @@ using System.Windows.Media; ...@@ -11,6 +11,7 @@ using System.Windows.Media;
using System.Windows.Media.Imaging; using System.Windows.Media.Imaging;
using System.Windows.Shapes; using System.Windows.Shapes;
using System.ComponentModel; using System.ComponentModel;
using GalaSoft.MvvmLight.Command;
namespace FLY.ControlLibrary namespace FLY.ControlLibrary
{ {
...@@ -19,24 +20,20 @@ namespace FLY.ControlLibrary ...@@ -19,24 +20,20 @@ namespace FLY.ControlLibrary
/// </summary> /// </summary>
public partial class Window_Tip : Window public partial class Window_Tip : Window
{ {
public TimeSpan Duration; WdTipVm viewModel;
public string Message;
public Window_Tip() public Window_Tip()
{ {
InitializeComponent(); InitializeComponent();
Duration = TimeSpan.FromSeconds(2);
timer = new System.Windows.Threading.DispatcherTimer();
timer.Tick += new EventHandler(timer_Tick);
} }
public void Init(string title, string message, TimeSpan duration)
private void Window_Loaded(object sender, RoutedEventArgs e)
{ {
this.Left = SystemParameters.PrimaryScreenWidth - this.Width; if (viewModel == null)
this.Top = SystemParameters.PrimaryScreenHeight - this.Height - 100; {
this.textblock_message.Text = Message; viewModel = new WdTipVm();
timer.Interval = Duration; DataContext = viewModel;
timer.Start(); }
viewModel.Init(title, message, duration);
} }
/// <summary> /// <summary>
/// 右下角 提示 /// 右下角 提示
...@@ -46,19 +43,116 @@ namespace FLY.ControlLibrary ...@@ -46,19 +43,116 @@ namespace FLY.ControlLibrary
/// <param name="duration">持续时间</param> /// <param name="duration">持续时间</param>
public static void Show(string title, string message, TimeSpan duration) public static void Show(string title, string message, TimeSpan duration)
{ {
new Window_Tip() { Title = title, Message = message, Duration = duration }.Show(); WdTipVm.Show(title, message, duration);
} }
void timer_Tick(object sender, EventArgs e) /// <summary>
/// 右下角 短时间提示
/// </summary>
/// <param name="title">标题</param>
/// <param name="message">内容</param>
public static void ShowShortTime(string title, string message)
{ {
Show(title, message, TimeSpan.FromSeconds(2));
}
/// <summary>
/// 右下角 永远显示提示
/// </summary>
/// <param name="title">标题</param>
/// <param name="message">内容</param>
public static void Show(string title, string message)
{
Show(title, message, TimeSpan.MaxValue);
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
viewModel.LoadedCmd.Execute(null);
}
}
public class WdTipVm:INotifyPropertyChanged
{
private static Window_Tip Current=null;
public TimeSpan Duration { get; set; }
public string Message { get; set; }
public string Title { get; set; }
public RelayCommand LoadedCmd { get; private set; }
public RelayCommand CloseCmd { get; private set; }
public event PropertyChangedEventHandler PropertyChanged;
System.Windows.Threading.DispatcherTimer timer;
public WdTipVm()
{
timer = new System.Windows.Threading.DispatcherTimer();
timer.Tick += new EventHandler(timer_Tick);
InitCmd();
}
public void Init(string title, string message, TimeSpan duration)
{
Title = title;
Message = message;
Duration = duration;
if (!Current.IsVisible)
Current.Show();
if (duration < TimeSpan.MaxValue && duration > TimeSpan.MinValue)
{
timer.Interval = duration;
timer.Start();
}
else
{
if (timer.IsEnabled)
timer.Stop(); timer.Stop();
this.Close();
} }
void Button_Click(object sender, RoutedEventArgs e)
}
void InitCmd()
{
LoadedCmd = new RelayCommand(() =>
{
if (Current == null)
return;//不正常
Current.Left = SystemParameters.PrimaryScreenWidth - Current.Width;
Current.Top = SystemParameters.PrimaryScreenHeight - Current.Height - 100;
if (Duration < TimeSpan.MaxValue && Duration > TimeSpan.MinValue)
{
timer.Interval = Duration;
timer.Start();
}
});
CloseCmd = new RelayCommand(() =>
{ {
if (Current == null)
return;//不正常
timer_Tick(null, null); timer_Tick(null, null);
});
}
void timer_Tick(object sender, EventArgs e)
{
timer.Stop();
Current.Close();
Current = null;
} }
/// <summary>
/// 右下角 提示
/// </summary>
/// <param name="title">标题</param>
/// <param name="message">内容</param>
/// <param name="duration">持续时间</param>
public static void Show(string title, string message, TimeSpan duration)
{
if (Current == null)
Current = new Window_Tip();
System.Windows.Threading.DispatcherTimer timer; Current.Init(title, message, duration);
}
} }
} }
...@@ -24,38 +24,11 @@ namespace FLY.Thick.Base.Client ...@@ -24,38 +24,11 @@ namespace FLY.Thick.Base.Client
#region IFlyAD接口 #region IFlyAD接口
private IPEndPoint ep = new IPEndPoint(IPAddress.Parse("192.168.251.10"), 20006);
public IPEndPoint EP public IPEndPoint EP { get; set; } = new IPEndPoint(IPAddress.Parse("192.168.251.10"), 20006);
{
get public bool HasCRC { get; set; }
{
return ep;
}
set
{
if (!IPEndPoint.Equals(ep, value))
{
ep = value;
NotifyPropertyChanged("EP");
}
}
}
bool hascrc = false;
public bool HasCRC
{
get
{
return hascrc;
}
set
{
if (hascrc != value)
{
hascrc = value;
NotifyPropertyChanged("HasCRC");
}
}
}
private int gridsmooth = 0; private int gridsmooth = 0;
/// <summary> /// <summary>
...@@ -71,115 +44,41 @@ namespace FLY.Thick.Base.Client ...@@ -71,115 +44,41 @@ namespace FLY.Thick.Base.Client
if (gridsmooth != value) if (gridsmooth != value)
{ {
gridsmooth = value; gridsmooth = value;
NotifyPropertyChanged("GridSmooth");
}
}
}
private int poslen;
public int PosLen
{
get { return poslen; }
set
{
if (poslen != value)
{
poslen = value;
NotifyPropertyChanged("PosLen");
}
}
}
private MOTORTYPE motortype = MOTORTYPE.SERVO;
public MOTORTYPE MotorType
{
get { return motortype; }
set
{
if (motortype != value)
{
motortype = value;
NotifyPropertyChanged("MotorType");
} }
} }
} }
private int posofgrid;
public int PosLen { get; set; }
public MOTORTYPE MotorType { get; set; } = MOTORTYPE.SERVO;
/// <summary> /// <summary>
/// // 单位 pulse/grid /// // 单位 pulse/grid
/// </summary> /// </summary>
public int PosOfGrid public int PosOfGrid { get; set; }
{
get { return posofgrid; } public UInt16 Ratio01 { get; set; }
set
{
if (posofgrid != value) public UInt16 Ratio02 { get; set; }
{
posofgrid = value;
NotifyPropertyChanged("PosOfGrid"); public Int16 PosOffset { get; set; }
}
}
} /// <summary>
private UInt16 ratio01; /// 脉冲平移
public UInt16 Ratio01 /// </summary>
{ public UInt32 JogVelocity { get; set; }
get { return ratio01; }
set /// <summary>
{ /// 参数应用
if (ratio01 != value) /// </summary>
{
ratio01 = value;
NotifyPropertyChanged("Ratio01");
}
}
}
private UInt16 ratio02;
public UInt16 Ratio02
{
get { return ratio02; }
set
{
if (ratio02 != value)
{
ratio02 = value;
NotifyPropertyChanged("Ratio02");
}
}
}
private Int16 posoffset;
public Int16 PosOffset
{
get
{
return posoffset;
}
set
{
if (posoffset != value)
{
posoffset = value;
NotifyPropertyChanged("PosOffset");
}
}
}//脉冲平移
private UInt32 jogvelocity;
public UInt32 JogVelocity
{
get
{
return jogvelocity;
}
set
{
if (jogvelocity != value)
{
jogvelocity = value;
NotifyPropertyChanged("JogVelocity");
}
}
}
public void Apply() public void Apply()
{ {
FLYAD_OBJ_INTERFACE.Pack_Params p = new FLYAD_OBJ_INTERFACE.Pack_Params() FLYAD_OBJ_INTERFACE.Pack_Params p = new FLYAD_OBJ_INTERFACE.Pack_Params()
{ {
ep = EP, ep = EP.ToString(),
posofgrid = (UInt16)PosOfGrid, posofgrid = (UInt16)PosOfGrid,
motortype = MotorType, motortype = MotorType,
poslen = PosLen, poslen = PosLen,
...@@ -190,9 +89,12 @@ namespace FLY.Thick.Base.Client ...@@ -190,9 +89,12 @@ namespace FLY.Thick.Base.Client
hasCRC = HasCRC, hasCRC = HasCRC,
gridsmooth = GridSmooth gridsmooth = GridSmooth
}; };
string json = Newtonsoft.Json.JsonConvert.SerializeObject(p);
CurrObjSys.SetValueEx(mConn, mServerID, ID, CurrObjSys.SetValueEx(mConn, mServerID, ID,
FLYAD_OBJ_INTERFACE.SET_PARAMS, FLYAD_OBJ_INTERFACE.SET_PARAMS,
p.ToBytes()); Misc.Converter.StringToBytes(json));
} }
/// <summary> /// <summary>
/// 获取序列码 /// 获取序列码
...@@ -213,9 +115,13 @@ namespace FLY.Thick.Base.Client ...@@ -213,9 +115,13 @@ namespace FLY.Thick.Base.Client
/// <param name="AsyncState">可为null</param> /// <param name="AsyncState">可为null</param>
public void SetAccess(byte[] access, AsyncCBHandler AsyncDelegate, object AsyncState) public void SetAccess(byte[] access, AsyncCBHandler AsyncDelegate, object AsyncState)
{ {
var p = new FLYAD_OBJ_INTERFACE.Pack_SetAccessRequest() { data = access };
string json = Newtonsoft.Json.JsonConvert.SerializeObject(p);
CurrObjSys.CallFunctionEx(mConn, mServerID, ID, CurrObjSys.CallFunctionEx(mConn, mServerID, ID,
FLYAD_OBJ_INTERFACE.CALL_SETACCESS, FLYAD_OBJ_INTERFACE.CALL_SETACCESS,
new FLYAD_OBJ_INTERFACE.Pack_SetAccessRequest() { data = access }.ToBytes(), Misc.Converter.StringToBytes(json),
AsyncDelegate, AsyncState); AsyncDelegate, AsyncState);
} }
...@@ -227,14 +133,24 @@ namespace FLY.Thick.Base.Client ...@@ -227,14 +133,24 @@ namespace FLY.Thick.Base.Client
/// <param name="AsyncState">可为null</param> /// <param name="AsyncState">可为null</param>
public void GetGrid(Misc.DIRECTION direction, AsyncCBHandler AsyncDelegate, object AsyncState) public void GetGrid(Misc.DIRECTION direction, AsyncCBHandler AsyncDelegate, object AsyncState)
{ {
var p = new FLYAD_OBJ_INTERFACE.Pack_GetGridRequest() { direction = direction };
string json = Newtonsoft.Json.JsonConvert.SerializeObject(p);
CurrObjSys.CallFunctionEx(mConn, mServerID, ID, CurrObjSys.CallFunctionEx(mConn, mServerID, ID,
FLYAD_OBJ_INTERFACE.CALL_GETGRID, FLYAD_OBJ_INTERFACE.CALL_GETGRID,
new FLYAD_OBJ_INTERFACE.Pack_GetGridRequest() { direction = direction}.ToBytes(), Misc.Converter.StringToBytes(json),
AsyncDelegate, AsyncState); AsyncDelegate, AsyncState);
} }
/// <summary>
/// 向AD盒获取数据
/// </summary>
public void UpdateParam()
{
CurrObjSys.CallFunctionEx(mConn, mServerID, ID,
FLYAD_OBJ_INTERFACE.CALL_UPDATEPARAM,null);
}
#endregion #endregion
...@@ -268,11 +184,10 @@ namespace FLY.Thick.Base.Client ...@@ -268,11 +184,10 @@ namespace FLY.Thick.Base.Client
{ {
case FLYAD_OBJ_INTERFACE.GET_PARAMS: case FLYAD_OBJ_INTERFACE.GET_PARAMS:
{ {
FLYAD_OBJ_INTERFACE.Pack_Params p = new FLYAD_OBJ_INTERFACE.Pack_Params(); string json = Misc.Converter.BytesToString(infodata);
var p = Newtonsoft.Json.JsonConvert.DeserializeObject<FLYAD_OBJ_INTERFACE.Pack_Params>(json);
if (!p.TryParse(infodata)) EP = Misc.StringConverter.ToIPEndPoint(p.ep);
return;
EP = p.ep;
PosOffset = p.posoffset; PosOffset = p.posoffset;
JogVelocity = p.jogvelocity; JogVelocity = p.jogvelocity;
...@@ -299,38 +214,33 @@ namespace FLY.Thick.Base.Client ...@@ -299,38 +214,33 @@ namespace FLY.Thick.Base.Client
{ {
case FLYAD_OBJ_INTERFACE.CALL_GETACCESSINFO: case FLYAD_OBJ_INTERFACE.CALL_GETACCESSINFO:
{ {
AccessInfo a = new AccessInfo(); string json = Misc.Converter.BytesToString(retdata);
if (!a.TryParse(retdata)) AccessInfo a = Newtonsoft.Json.JsonConvert.DeserializeObject<AccessInfo>(json);
return;
((AsyncCBHandler)AsyncDelegate)(AsyncState, a); ((AsyncCBHandler)AsyncDelegate)(AsyncState, a);
} break; } break;
case FLYAD_OBJ_INTERFACE.CALL_SETACCESS: case FLYAD_OBJ_INTERFACE.CALL_SETACCESS:
{ {
AccessInfo a = new AccessInfo(); string json = Misc.Converter.BytesToString(retdata);
if (!a.TryParse(retdata)) AccessInfo a = Newtonsoft.Json.JsonConvert.DeserializeObject<AccessInfo>(json);
return;
((AsyncCBHandler)AsyncDelegate)(AsyncState, a); ((AsyncCBHandler)AsyncDelegate)(AsyncState, a);
} break; } break;
case FLYAD_OBJ_INTERFACE.CALL_GETGRID: case FLYAD_OBJ_INTERFACE.CALL_GETGRID:
{ {
GridInfo p = new GridInfo(); string json = Misc.Converter.BytesToString(retdata);
if (!p.TryParse(retdata)) GridInfo p = Newtonsoft.Json.JsonConvert.DeserializeObject<GridInfo>(json);
return;
((AsyncCBHandler)AsyncDelegate)(AsyncState, p); ((AsyncCBHandler)AsyncDelegate)(AsyncState, p);
}break; }break;
} }
} }
#region INotifyPropertyChanged 成员 #region INotifyPropertyChanged 成员
public event PropertyChangedEventHandler PropertyChanged; public event PropertyChangedEventHandler PropertyChanged;
protected void NotifyPropertyChanged(string propertyname)
{
if (PropertyChanged != null)
{
PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propertyname));
}
}
#endregion #endregion
} }
} }
\ No newline at end of file
...@@ -5,12 +5,28 @@ using System.Text; ...@@ -5,12 +5,28 @@ using System.Text;
namespace FLY.Thick.Base.Common namespace FLY.Thick.Base.Common
{ {
/// <summary>
/// 电机类型
/// </summary>
public enum MOTORTYPE public enum MOTORTYPE
{ {
/// <summary>
/// 没有
/// </summary>
NULL = 0, NULL = 0,
/// <summary>
/// 变频器
/// </summary>
VF0 = 1, VF0 = 1,
/// <summary>
/// 伺服电器
/// </summary>
SERVO = 2 SERVO = 2
} }
/// <summary>
/// 密码区状态
/// </summary>
public enum AREA_STATUS public enum AREA_STATUS
{ {
/// <summary> /// <summary>
...@@ -43,6 +59,9 @@ namespace FLY.Thick.Base.Common ...@@ -43,6 +59,9 @@ namespace FLY.Thick.Base.Common
VALID_WRERR = 6 VALID_WRERR = 6
} }
/// <summary>
/// 密码区错误内容
/// </summary>
public enum AREA_ERR public enum AREA_ERR
{ {
NO_ERR = 0, // 没有错误 NO_ERR = 0, // 没有错误
...@@ -50,101 +69,54 @@ namespace FLY.Thick.Base.Common ...@@ -50,101 +69,54 @@ namespace FLY.Thick.Base.Common
ERR_ACCESS = 2//无效使用码 ERR_ACCESS = 2//无效使用码
} }
/// <summary>
/// 授权码包
/// </summary>
public class AccessInfo public class AccessInfo
{ {
/// <summary>
/// 密码区状态
/// </summary>
public AREA_STATUS status; public AREA_STATUS status;
public AREA_ERR ret;
public byte[] code = new byte[7];
public UInt16 surplus;
public byte[] access = new byte[8];
#region IPack 成员 /// <summary>
/// 操作结果
public byte[] ToBytes() /// </summary>
{ public AREA_ERR ret;
List<byte> buf = new List<byte>();
buf.Add((byte)status);
buf.Add((byte)ret);
buf.AddRange(code);
buf.AddRange(BitConverter.GetBytes(surplus));
buf.AddRange(access);
return buf.ToArray();
}
public bool TryParse(byte[] value)
{
if (value.Count() < 18) /// <summary>
return false; /// 序列码
int idx = 0; /// </summary>
status = (AREA_STATUS)value[idx]; public byte[] code = new byte[7];
idx++;
ret = (AREA_ERR)value[idx];
idx++;
Array.Copy(value, idx, code, 0, code.Length);
idx += code.Length;
surplus = BitConverter.ToUInt16(value, idx); /// <summary>
idx += 2; /// 剩余时间
Array.Copy(value, idx, access, 0,access.Length); /// </summary>
idx += access.Length; public UInt16 surplus;
return true;
}
#endregion /// <summary>
/// 授权码
/// </summary>
public byte[] access = new byte[8];
} }
/// <summary>
/// grid 数据包
/// </summary>
public class GridInfo public class GridInfo
{ {
/// <summary>
/// 数据方向
/// </summary>
public Misc.DIRECTION direction; public Misc.DIRECTION direction;
public bool isall;//这就是全部 /// <summary>
public int grid_start; /// AD值数据
/// </summary>
public int[] data; public int[] data;
/// <summary>
#region IPack 成员 /// 厚度值数据
/// </summary>
public byte[] ToBytes() public double[] thick;
{
List<byte> buf = new List<byte>();
buf.AddRange(BitConverter.GetBytes((Int32)direction));
buf.AddRange(BitConverter.GetBytes(isall));
buf.AddRange(BitConverter.GetBytes(grid_start));
buf.AddRange(BitConverter.GetBytes(data.Length));
for (int i = 0; i < data.Length; i++)
buf.AddRange(BitConverter.GetBytes(data[i]));
return buf.ToArray();
}
public bool TryParse(byte[] value)
{
if (value.Length < (4 + 1 + 4 + 4))
return false;
int idx = 0;
direction = (Misc.DIRECTION)BitConverter.ToInt32(value, idx);
idx += 4;
isall = BitConverter.ToBoolean(value, idx);
idx++;
grid_start = BitConverter.ToInt32(value, idx);
idx += 4;
int len = BitConverter.ToInt32(value, idx);
idx += 4;
if (value.Length < (4 + 1 + 4 + 4 + len * 4))
return false;
data = new int[len];
for (int i = 0; i < len; i++)
{
data[i] = BitConverter.ToInt32(value, idx);
idx += 4;
}
return true;
}
#endregion
} }
......
...@@ -10,7 +10,6 @@ using FObjBase; ...@@ -10,7 +10,6 @@ using FObjBase;
namespace FLY.Thick.Base.IService namespace FLY.Thick.Base.IService
{ {
public delegate void TimeGridEventHandler(object sender, TimeGridEventArgs e);
public interface IFlyADService:INotifyPropertyChanged public interface IFlyADService:INotifyPropertyChanged
{ {
#region 参数 #region 参数
...@@ -49,6 +48,10 @@ namespace FLY.Thick.Base.IService ...@@ -49,6 +48,10 @@ namespace FLY.Thick.Base.IService
/// <param name="AsyncState">可为null</param> /// <param name="AsyncState">可为null</param>
void GetGrid(Misc.DIRECTION direction, AsyncCBHandler AsyncDelegate, object AsyncState); void GetGrid(Misc.DIRECTION direction, AsyncCBHandler AsyncDelegate, object AsyncState);
/// <summary>
/// 向AD盒获取数据
/// </summary>
void UpdateParam();
//event TimeGridEventHandler TimeGridEvent; //event TimeGridEventHandler TimeGridEvent;
//event IStatusChangedEventHandler IStatusChangedEvent; //event IStatusChangedEventHandler IStatusChangedEvent;
......
...@@ -12,10 +12,9 @@ namespace FLY.Thick.Base.OBJ_INTERFACE ...@@ -12,10 +12,9 @@ namespace FLY.Thick.Base.OBJ_INTERFACE
{ {
#region Pack #region Pack
public class Pack_Params : IPack public class Pack_Params
{ {
public IPEndPoint ep; public string ep;
public int poslen; public int poslen;
public MOTORTYPE motortype; public MOTORTYPE motortype;
public UInt16 posofgrid; public UInt16 posofgrid;
...@@ -25,158 +24,58 @@ namespace FLY.Thick.Base.OBJ_INTERFACE ...@@ -25,158 +24,58 @@ namespace FLY.Thick.Base.OBJ_INTERFACE
public UInt32 jogvelocity; public UInt32 jogvelocity;
public bool hasCRC; public bool hasCRC;
public int gridsmooth; public int gridsmooth;
#region IPack 成员
public byte[] ToBytes()
{
List<byte> buf = new List<byte>();
byte[] bs = Misc.Converter.IPEndPoint2Bytes(ep);
buf.AddRange(BitConverter.GetBytes(bs.Length));
buf.AddRange(bs);
buf.AddRange(BitConverter.GetBytes(poslen));
buf.AddRange(BitConverter.GetBytes((UInt16)motortype));
buf.AddRange(BitConverter.GetBytes(posofgrid));
buf.AddRange(BitConverter.GetBytes(ratio01));
buf.AddRange(BitConverter.GetBytes(ratio02));
buf.AddRange(BitConverter.GetBytes(posoffset));
buf.AddRange(BitConverter.GetBytes(jogvelocity));
buf.AddRange(BitConverter.GetBytes(hasCRC));
buf.AddRange(BitConverter.GetBytes(gridsmooth));
return buf.ToArray();
} }
public bool TryParse(byte[] value) public class Pack_SetAccessRequest
{
int cnt = 4 + 4 + 2 * 5 + 4 + 1 + 4;
if (value.Length < cnt)
return false;
int idx = 0;
int len = BitConverter.ToInt32(value, idx);
idx += 4;
cnt += len;
if (value.Length < cnt)
return false;
ep = Misc.Converter.Bytes2IPEndPoint(value, idx, len);
idx += len;
poslen = BitConverter.ToInt32(value, idx);
idx += 4;
motortype = (MOTORTYPE)BitConverter.ToUInt16(value, idx);
idx += 2;
posofgrid = BitConverter.ToUInt16(value, idx);
idx += 2;
ratio01 = BitConverter.ToUInt16(value, idx);
idx += 2;
ratio02 = BitConverter.ToUInt16(value, idx);
idx += 2;
posoffset = BitConverter.ToInt16(value, idx);
idx += 2;
jogvelocity = BitConverter.ToUInt32(value, idx);
idx += 4;
hasCRC = BitConverter.ToBoolean(value, idx);
idx++;
gridsmooth = BitConverter.ToInt32(value, idx);
idx++;
return true;
}
#endregion
}
public class Pack_SetAccessRequest : IPack
{ {
public byte[] data; public byte[] data;
public byte[] ToBytes()
{
List<byte> buf = new List<byte>();
buf.AddRange(BitConverter.GetBytes(data.Length));
buf.AddRange(data);
return buf.ToArray();
} }
public class Pack_GetGridRequest
public bool TryParse(byte[] value)
{
if (value.Length < 4)
return false;
int idx = 0;
int len = BitConverter.ToInt32(value, idx);
idx += 4;
if (value.Length < 4 + len)
return false;
data = new byte[len];
Array.Copy(value, idx, data, 0, len);
idx += len;
return true;
}
}
public class Pack_GetGridRequest : IPack
{ {
public Misc.DIRECTION direction; public Misc.DIRECTION direction;
public byte[] ToBytes()
{
List<byte> buf = new List<byte>();
buf.AddRange(BitConverter.GetBytes((int)direction));
return buf.ToArray();
}
public bool TryParse(byte[] value)
{
if (value.Length < 4)
return false;
int idx = 0;
direction = (Misc.DIRECTION)BitConverter.ToInt32(value, idx);
idx += 4;
return true;
}
} }
#endregion #endregion
#region GetValue #region GetValue
/// <summary> /// <summary>
/// Pack_Params /// json Pack_Params
/// </summary> /// </summary>
public const UInt16 GET_PARAMS = 0; public const UInt16 GET_PARAMS = 0;
#endregion #endregion
#region SetValue #region SetValue
/// <summary> /// <summary>
/// Pack_Params /// json Pack_Params
/// </summary> /// </summary>
public const UInt16 SET_PARAMS = 0; public const UInt16 SET_PARAMS = 0;
#endregion #endregion
#region PushMsg #region PushMsg
/// <summary> /// <summary>
/// Pack_Params /// json Pack_Params
/// </summary> /// </summary>
public const UInt16 PUSH_PARAMS = 0; public const UInt16 PUSH_PARAMS = 0;
#endregion #endregion
#region CallFunction #region CallFunction
/// <summary> /// <summary>
/// request:null /// request:null
/// reponse:AccessInfo /// reponse:json AccessInfo
/// </summary> /// </summary>
public const UInt16 CALL_GETACCESSINFO = 8; public const UInt16 CALL_GETACCESSINFO = 8;
/// <summary> /// <summary>
/// request:Pack_SetAccessRequest /// request:Pack_SetAccessRequest
/// reponse:AccessInfo /// reponse:json AccessInfo
/// </summary> /// </summary>
public const UInt16 CALL_SETACCESS = 9; public const UInt16 CALL_SETACCESS = 9;
/// <summary> /// <summary>
/// request:Pack_GetGridReqest /// request:Pack_GetGridReqest
/// reponse:GridInfo /// reponse:json GridInfo
/// </summary> /// </summary>
public const UInt16 CALL_GETGRID = 10; public const UInt16 CALL_GETGRID = 10;
/// <summary>
/// request:null
/// reponse:null
/// </summary>
public const UInt16 CALL_UPDATEPARAM = 11;
#endregion #endregion
} }
} }
...@@ -8,6 +8,7 @@ using FObjBase; ...@@ -8,6 +8,7 @@ using FObjBase;
using FLY.Thick.Base.OBJ_INTERFACE; using FLY.Thick.Base.OBJ_INTERFACE;
using FLY.Thick.Base.Common; using FLY.Thick.Base.Common;
using FLY.Thick.Base.IService; using FLY.Thick.Base.IService;
using Newtonsoft.Json;
namespace FLY.Thick.Base.Server.OBJProxy namespace FLY.Thick.Base.Server.OBJProxy
{ {
...@@ -19,17 +20,17 @@ namespace FLY.Thick.Base.Server.OBJProxy ...@@ -19,17 +20,17 @@ namespace FLY.Thick.Base.Server.OBJProxy
#endregion #endregion
FlyADBase.FlyAD7 mFlyAD; FlyADBase.FlyAD7 mFlyAD;
AD2ThickHandler AD2Thick;
public FlyAD_OBJProxy(int objsys_idx, UInt32 id, FlyADBase.FlyAD7 flyad) public FlyAD_OBJProxy(int objsys_idx, UInt32 id, FlyADBase.FlyAD7 flyad,
AD2ThickHandler AD2Thick )
: base(objsys_idx) : base(objsys_idx)
{ {
ID = id; ID = id;
mFlyAD = flyad; mFlyAD = flyad;
this.AD2Thick = AD2Thick;
mFlyAD.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(mFlyAD_PropertyChanged); mFlyAD.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(mFlyAD_PropertyChanged);
} }
void mFlyAD_PropertyChanged(object sender, PropertyChangedEventArgs e) void mFlyAD_PropertyChanged(object sender, PropertyChangedEventArgs e)
{ {
if ((e.PropertyName == "LocalEP") || if ((e.PropertyName == "LocalEP") ||
...@@ -62,11 +63,10 @@ namespace FLY.Thick.Base.Server.OBJProxy ...@@ -62,11 +63,10 @@ namespace FLY.Thick.Base.Server.OBJProxy
{ {
case FLYAD_OBJ_INTERFACE.GET_PARAMS: case FLYAD_OBJ_INTERFACE.GET_PARAMS:
{ {
mFlyAD.UpdateParam();
FLYAD_OBJ_INTERFACE.Pack_Params p = new FLYAD_OBJ_INTERFACE.Pack_Params() FLYAD_OBJ_INTERFACE.Pack_Params p = new FLYAD_OBJ_INTERFACE.Pack_Params()
{ {
ep = mFlyAD.LocalEP, ep = mFlyAD.LocalEP.ToString(),
hasCRC = mFlyAD.HasCRC, hasCRC = mFlyAD.HasCRC,
gridsmooth = mFlyAD.GridSmooth, gridsmooth = mFlyAD.GridSmooth,
posofgrid = mFlyAD.PosOfGrid, posofgrid = mFlyAD.PosOfGrid,
...@@ -77,10 +77,11 @@ namespace FLY.Thick.Base.Server.OBJProxy ...@@ -77,10 +77,11 @@ namespace FLY.Thick.Base.Server.OBJProxy
posoffset = mFlyAD.PosOffset, posoffset = mFlyAD.PosOffset,
jogvelocity = mFlyAD.JogVelocity jogvelocity = mFlyAD.JogVelocity
}; };
string json = JsonConvert.SerializeObject(p);
infodata = Misc.Converter.StringToBytes(json);
infodata = p.ToBytes(); }
}break; break;
default: default:
infodata = null; infodata = null;
break; break;
...@@ -92,12 +93,13 @@ namespace FLY.Thick.Base.Server.OBJProxy ...@@ -92,12 +93,13 @@ namespace FLY.Thick.Base.Server.OBJProxy
{ {
case FLYAD_OBJ_INTERFACE.SET_PARAMS: case FLYAD_OBJ_INTERFACE.SET_PARAMS:
{ {
FLYAD_OBJ_INTERFACE.Pack_Params p = new FLYAD_OBJ_INTERFACE.Pack_Params(); string json = Misc.Converter.BytesToString(infodata);
if (p.TryParse(infodata)) var p = JsonConvert.DeserializeObject<FLYAD_OBJ_INTERFACE.Pack_Params>(json);
{
mFlyAD.HasCRC = p.hasCRC; mFlyAD.HasCRC = p.hasCRC;
mFlyAD.GridSmooth = p.gridsmooth; mFlyAD.GridSmooth = p.gridsmooth;
mFlyAD.Connect(p.ep); var ep = Misc.StringConverter.ToIPEndPoint(p.ep);
mFlyAD.Connect(ep);
mFlyAD.PosOffset = p.posoffset; mFlyAD.PosOffset = p.posoffset;
mFlyAD.JogVelocity = p.jogvelocity; mFlyAD.JogVelocity = p.jogvelocity;
mFlyAD.PosOfGrid = p.posofgrid; mFlyAD.PosOfGrid = p.posofgrid;
...@@ -105,7 +107,7 @@ namespace FLY.Thick.Base.Server.OBJProxy ...@@ -105,7 +107,7 @@ namespace FLY.Thick.Base.Server.OBJProxy
mFlyAD.Ratio01 = p.ratio01; mFlyAD.Ratio01 = p.ratio01;
mFlyAD.Ratio02 = p.ratio02; mFlyAD.Ratio02 = p.ratio02;
}
} break; } break;
} }
} }
...@@ -113,52 +115,65 @@ namespace FLY.Thick.Base.Server.OBJProxy ...@@ -113,52 +115,65 @@ namespace FLY.Thick.Base.Server.OBJProxy
{ {
switch (funcid) switch (funcid)
{ {
case FLYAD_OBJ_INTERFACE.CALL_UPDATEPARAM:
{
mFlyAD.UpdateParam();
}break;
case FLYAD_OBJ_INTERFACE.CALL_GETACCESSINFO: case FLYAD_OBJ_INTERFACE.CALL_GETACCESSINFO:
{ {
GetAccessInfo( GetAccessInfo(
new AsyncCBHandler(delegate(object AsyncState, object retdata) new AsyncCBHandler(delegate(object AsyncState, object retdata)
{ {
ConnContext context = (ConnContext)AsyncState; ConnContext context = (ConnContext)AsyncState;
string json = JsonConvert.SerializeObject(retdata);
CurrObjSys.PushCallFunctionEx( CurrObjSys.PushCallFunctionEx(
context.from, context.from,
context.srcid, context.srcid,
ID, ID,
context.magic, context.magic,
FLYAD_OBJ_INTERFACE.CALL_GETACCESSINFO, FLYAD_OBJ_INTERFACE.CALL_GETACCESSINFO,
((AccessInfo)retdata).ToBytes()); Misc.Converter.StringToBytes(json)
);
}), new ConnContext(from, srcid, magic)); }), new ConnContext(from, srcid, magic));
} break; } break;
case FLYAD_OBJ_INTERFACE.CALL_SETACCESS: case FLYAD_OBJ_INTERFACE.CALL_SETACCESS:
{ {
FLYAD_OBJ_INTERFACE.Pack_SetAccessRequest p = new FLYAD_OBJ_INTERFACE.Pack_SetAccessRequest(); string json = Misc.Converter.BytesToString(infodata);
if (!p.TryParse(infodata))
break; var p = JsonConvert.DeserializeObject<FLYAD_OBJ_INTERFACE.Pack_SetAccessRequest>(json);
SetAccess( SetAccess(
p.data, p.data,
new AsyncCBHandler(delegate(object AsyncState, object retdata) new AsyncCBHandler(delegate(object AsyncState, object retdata)
{ {
ConnContext context = (ConnContext)AsyncState; ConnContext context = (ConnContext)AsyncState;
string json_reponse = JsonConvert.SerializeObject(retdata);
CurrObjSys.PushCallFunctionEx( CurrObjSys.PushCallFunctionEx(
context.from, context.from,
context.srcid, context.srcid,
ID, ID,
context.magic, context.magic,
FLYAD_OBJ_INTERFACE.CALL_SETACCESS, FLYAD_OBJ_INTERFACE.CALL_SETACCESS,
((AccessInfo)retdata).ToBytes()); Misc.Converter.StringToBytes(json_reponse)
);
}), new ConnContext(from, srcid, magic)); }), new ConnContext(from, srcid, magic));
} break; } break;
case FLYAD_OBJ_INTERFACE.CALL_GETGRID: case FLYAD_OBJ_INTERFACE.CALL_GETGRID:
{ {
FLYAD_OBJ_INTERFACE.Pack_GetGridRequest p = new FLYAD_OBJ_INTERFACE.Pack_GetGridRequest(); string json = Misc.Converter.BytesToString(infodata);
if (!p.TryParse(infodata))
break; var p = JsonConvert.DeserializeObject<FLYAD_OBJ_INTERFACE.Pack_GetGridRequest>(json);
GetGrid( GetGrid(
p.direction, p.direction,
new AsyncCBHandler(delegate(object AsyncState, object retdata) new AsyncCBHandler(delegate(object AsyncState, object retdata)
{ {
string json_reponse = JsonConvert.SerializeObject(retdata);
ConnContext context = (ConnContext)AsyncState; ConnContext context = (ConnContext)AsyncState;
CurrObjSys.PushCallFunctionEx( CurrObjSys.PushCallFunctionEx(
context.from, context.from,
...@@ -166,7 +181,7 @@ namespace FLY.Thick.Base.Server.OBJProxy ...@@ -166,7 +181,7 @@ namespace FLY.Thick.Base.Server.OBJProxy
ID, ID,
context.magic, context.magic,
FLYAD_OBJ_INTERFACE.CALL_GETGRID, FLYAD_OBJ_INTERFACE.CALL_GETGRID,
((GridInfo)retdata).ToBytes()); Misc.Converter.StringToBytes(json_reponse));
}), new ConnContext(from, srcid, magic)); }), new ConnContext(from, srcid, magic));
}break; }break;
} }
...@@ -251,14 +266,25 @@ namespace FLY.Thick.Base.Server.OBJProxy ...@@ -251,14 +266,25 @@ namespace FLY.Thick.Base.Server.OBJProxy
/// <param name="AsyncState">可为null</param> /// <param name="AsyncState">可为null</param>
void GetGrid(Misc.DIRECTION direction, AsyncCBHandler AsyncDelegate, object AsyncState) void GetGrid(Misc.DIRECTION direction, AsyncCBHandler AsyncDelegate, object AsyncState)
{ {
int[] dat; mFlyAD.GetGrid(direction, out int[] dat);
mFlyAD.GetGrid(direction, out dat); double[] thicks = null;
if (dat != null)
{
thicks = dat.Select(ad =>
{
int thick100 = AD2Thick(ad);
if (Misc.MyBase.ISVALIDATA(thick100))
return Math.Round(thick100 / 100.0, 2);
else
return double.NaN;
}).ToArray();
}
GridInfo p = new GridInfo() GridInfo p = new GridInfo()
{ {
data = dat,
direction = direction, direction = direction,
grid_start = 0, data = dat,
isall = true thick = thicks
}; };
AsyncDelegate(AsyncState, p); AsyncDelegate(AsyncState, p);
} }
......
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