|
|
|
|
using Rs.Framework;
|
|
|
|
|
using Rs.Motion.Base;
|
|
|
|
|
using Rs.Motion.Base.Config;
|
|
|
|
|
using Rs.Motion.Ztm;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Xml.Serialization;
|
|
|
|
|
|
|
|
|
|
namespace Rs.Motion.GugaoEcat
|
|
|
|
|
{
|
|
|
|
|
public class ZtmCard:ICard
|
|
|
|
|
{
|
|
|
|
|
private ushort m_mc = 999;
|
|
|
|
|
public ZtmCard(ushort cardID,ushort mc,ushort axisCount,string cfgName)
|
|
|
|
|
{
|
|
|
|
|
m_mc = mc;
|
|
|
|
|
CardID= cardID;
|
|
|
|
|
AxisCount= axisCount;
|
|
|
|
|
CfgName= cfgName;
|
|
|
|
|
Config = new CardConfig();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ushort GetMC()
|
|
|
|
|
{
|
|
|
|
|
return m_mc;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private ushort _CardID;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 卡编号
|
|
|
|
|
/// </summary>
|
|
|
|
|
[XmlIgnore]
|
|
|
|
|
public ushort CardID
|
|
|
|
|
{
|
|
|
|
|
get { return _CardID; }
|
|
|
|
|
set { _CardID = value; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private ushort _AxisCount;
|
|
|
|
|
[XmlIgnore]
|
|
|
|
|
public ushort AxisCount
|
|
|
|
|
{
|
|
|
|
|
get { return _AxisCount; }
|
|
|
|
|
set { _AxisCount = value; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private string _CfgName;
|
|
|
|
|
[XmlIgnore]
|
|
|
|
|
public string CfgName
|
|
|
|
|
{
|
|
|
|
|
get { return _CfgName; }
|
|
|
|
|
set { _CfgName = value; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override ErrorCode Init()
|
|
|
|
|
{
|
|
|
|
|
string baseDir = AppDomain.CurrentDomain.BaseDirectory;
|
|
|
|
|
string filePath=Path.Combine(baseDir,"Config","Motion", CfgName);
|
|
|
|
|
//检测文件夹是否存在,不存在则创建
|
|
|
|
|
if(!Directory.Exists(Path.GetDirectoryName(filePath)))
|
|
|
|
|
{
|
|
|
|
|
Directory.CreateDirectory(Path.GetDirectoryName(filePath));
|
|
|
|
|
}
|
|
|
|
|
//判断文件是否存在,如果不存在配置文件,则生成配置文件
|
|
|
|
|
if(!File.Exists(filePath))
|
|
|
|
|
{
|
|
|
|
|
Config.Init(CardID, AxisCount,0);
|
|
|
|
|
Config.AxisConfigs.ForEach((ac) => { ac.CardMc =(short) m_mc; });
|
|
|
|
|
bool suc = XmlSerializerHelper.Instance.Serialize(filePath, Config);
|
|
|
|
|
if(!suc)
|
|
|
|
|
{
|
|
|
|
|
return ErrorCode.CardLoadConfigFail;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
bool suc = XmlSerializerHelper.Instance.Deserialize<CardConfig>(filePath ,out CardConfig config);
|
|
|
|
|
Config=config;
|
|
|
|
|
foreach(AxisConfig ac in Config.AxisConfigs)
|
|
|
|
|
{
|
|
|
|
|
ac.CardMc = (short)m_mc;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
InitAxis();
|
|
|
|
|
return ErrorCode.Ok;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override ErrorCode Save()
|
|
|
|
|
{
|
|
|
|
|
if(Config != null)
|
|
|
|
|
{
|
|
|
|
|
string baseDir = AppDomain.CurrentDomain.BaseDirectory;
|
|
|
|
|
string filePath = Path.Combine(baseDir, "Config", "Motion", CfgName);
|
|
|
|
|
if (File.Exists(filePath))
|
|
|
|
|
{
|
|
|
|
|
File.Delete(filePath);
|
|
|
|
|
XmlSerializerHelper.Instance.Serialize(filePath, Config);
|
|
|
|
|
return ErrorCode.Ok;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return ErrorCode.CardNotInit;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private ErrorCode InitAxis()
|
|
|
|
|
{
|
|
|
|
|
for(int i=0; i<AxisCount; i++)
|
|
|
|
|
{
|
|
|
|
|
IAxis axis = new ZtmAxis(Config.AxisConfigs[i]);
|
|
|
|
|
axis.Card = this;
|
|
|
|
|
axis.Config.Axis = axis;
|
|
|
|
|
axis.Init();
|
|
|
|
|
AxisIdDic.Add(axis.Config.AxisId, axis);
|
|
|
|
|
AxisNameDic.Add(axis.Config.AxisName, axis);
|
|
|
|
|
}
|
|
|
|
|
return ErrorCode.Ok;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|