You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
149 lines
4.8 KiB
C#
149 lines
4.8 KiB
C#
using GTN;
|
|
using gts;
|
|
using Rs.DataAccess;
|
|
using Rs.Framework;
|
|
using Rs.Motion.Base;
|
|
using Rs.Motion.Ztm;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.Diagnostics;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Net.NetworkInformation;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Rs.Motion.GugaoPulse
|
|
{
|
|
/// <summary>
|
|
/// 固高脉冲卡
|
|
/// </summary>
|
|
public class GugaoPulseCardManager : ICardManager
|
|
{
|
|
/// <summary>
|
|
/// 执行底层接口的返回值
|
|
/// </summary>
|
|
private short apiResult = 0;
|
|
/// <summary>
|
|
/// 保存一共有多少张卡
|
|
/// </summary>
|
|
Dictionary<ushort,ICard> cardDic= new Dictionary<ushort,ICard>();
|
|
private GugaoPulseCardManager() {
|
|
|
|
}
|
|
|
|
private static GugaoPulseCardManager instance;
|
|
public static GugaoPulseCardManager Instance
|
|
{
|
|
get
|
|
{
|
|
if(instance==null)
|
|
{
|
|
instance = new GugaoPulseCardManager();
|
|
}
|
|
|
|
return instance;
|
|
}
|
|
}
|
|
|
|
public override IIOCard AddIoCard(int cardID, string name, string vender, bool isEthercat, ushort inNum, ushort outNum, int slaveID)
|
|
{
|
|
GLinkIOCard ioCard = new GLinkIOCard();
|
|
string filename = $"config/motion/io/gugao{cardID}.xml";
|
|
if (!File.Exists(filename))
|
|
{
|
|
ioCard.CardID = (ushort)cardID;
|
|
ioCard.Name = name;
|
|
ioCard.Vender = vender;
|
|
ioCard.IsEtherCat = isEthercat;
|
|
ioCard.Init((short)cardID,inNum, outNum, (ushort)slaveID);
|
|
bool suc = XmlSerializerHelper.Instance.Serialize<GLinkIOCard>(filename, ioCard);
|
|
}
|
|
else
|
|
XmlSerializerHelper.Instance.Deserialize<GLinkIOCard>(filename, out ioCard);
|
|
if (ioCard != null)
|
|
{
|
|
//ztmIOCard.SetMc(0);
|
|
//ioCards.Add(ztmIOCard);
|
|
//Add(ztmIOCard);
|
|
}
|
|
return ioCard;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 同一类卡统一初始化
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public override ErrorCode Init()
|
|
{
|
|
SqliteHelper db = new SqliteHelper();
|
|
DataTable dt = db.GetDataTable("select * from motioncard where vender='gugao' and enable=1 order by id desc");
|
|
if(dt!=null&&dt.Rows.Count>0)
|
|
{
|
|
foreach (DataRow row in dt.Rows)
|
|
{
|
|
//ICard card = new GugaoPulseCard(ushort.Parse(row["cardid"].ToString()), 8, $"gugaopulse{row["cardid"]}.xml");
|
|
//card.Init();
|
|
//cardDic.Add(ushort.Parse(row["cardid"].ToString()), card);
|
|
//打开运动控制卡
|
|
apiResult = mc_pulse.GT_Open(short.Parse(row["cardid"].ToString()), 0, 1);
|
|
if (apiResult != 0)
|
|
{
|
|
return ErrorCode.CardInitFail;
|
|
}
|
|
//清楚报警和限位
|
|
apiResult = mc_pulse.GT_ClrSts(0, 1, 8);
|
|
if (apiResult != 0)
|
|
{
|
|
return ErrorCode.Fail;
|
|
}
|
|
short value = 32767 * 5 / 10;
|
|
apiResult = mc_pulse.GT_SetDac(0, 11, ref value, 1);
|
|
MessageQueue.Instance.Insert($"GT_SetDac ret={apiResult}");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
return ErrorCode.CardNotExist;
|
|
}
|
|
IsInitialized = true;
|
|
return ErrorCode.Ok;
|
|
}
|
|
|
|
public ICard GetCard(ushort cardID)
|
|
{
|
|
|
|
ICard card;
|
|
if (cardDic.ContainsKey((ushort)cardID)) return cardDic[(ushort)cardID];
|
|
card = new GugaoPulseCard(cardID, 8, $"gugaopulse{cardID}.xml");
|
|
card.Init();
|
|
if(!cardDic.ContainsKey((ushort)cardID))
|
|
{
|
|
cardDic.Add((ushort)cardID, card);
|
|
}
|
|
return card;
|
|
|
|
|
|
//if (cardDic.ContainsKey(cardID))
|
|
// return cardDic[cardID];
|
|
//return null;
|
|
}
|
|
|
|
public ErrorCode ComparePulse(short CardId,ushort channel, bool dp = true,short HcmpPulseWidth=100)
|
|
{
|
|
short value = (short)channel;
|
|
if (value != 0)
|
|
{
|
|
value = (short)(1 << (channel - 1));
|
|
}
|
|
apiResult = mc_pulse.GT_ComparePulse(CardId, (short)(1 << (channel - 1)), (short)(dp ? 1 : 0), HcmpPulseWidth);
|
|
if (apiResult != 0)
|
|
{
|
|
return ErrorCode.Fail;
|
|
}
|
|
return ErrorCode.Ok;
|
|
}
|
|
}
|
|
}
|