增加雷赛卡的支持

master
lhiven 5 months ago
parent edc408b6a1
commit 41ae928788

@ -149,10 +149,19 @@ namespace Rs.Framework
try
{
int len = m_Socket.Send(sendData);
//if(len <= 0)
//{
// m_IsConnected = false;
// m_Socket.Close();
// m_Socket.Dispose();
// Connect(m_HostName, m_Port);
// OnDisconnected?.Invoke(m_Socket);
//}
return len;
}
catch (Exception)
{
m_IsConnected = false;
m_Socket.Close();
m_Socket.Dispose();
Connect(m_HostName, m_Port);
@ -161,5 +170,12 @@ namespace Rs.Framework
}
return -1;
}
public void DisConnect()
{
m_Socket.Close();
m_Socket.Dispose();
m_IsConnected = false;
}
}
}

File diff suppressed because it is too large Load Diff

@ -1,13 +1,16 @@
using GTN;
using csLTDMC;
using GTN;
using gts;
using Rs.DataAccess;
using Rs.Framework;
using Rs.Motion.Base;
using Rs.Motion.GugaoEcat;
using Rs.Motion.GugaoPulse;
using Rs.Motion.Leisai;
using Rs.Motion.Ztm;
using System;
using System.Collections.Generic;
using System.ComponentModel.Design;
using System.Data;
using System.IO;
using System.Linq;
@ -62,6 +65,19 @@ namespace Rs.Motion
ushort.Parse(dr["OutNum"].ToString()),
int.Parse(dr["SlaveID"].ToString()
));
case "LeisaiPulse":
case "LeisaiPulseEx":
return LeisaiCardManager.Instance.AddIoCard(
int.Parse(dr["CardID"].ToString()),
dr["CardName"].ToString(),
dr["vender"].ToString(),
false,
ushort.Parse(dr["InNum"].ToString()),
ushort.Parse(dr["OutNum"].ToString()),
int.Parse(dr["SlaveID"].ToString()
));
default:return null;
}
}
@ -224,6 +240,36 @@ namespace Rs.Motion
}
}
else if (io.Card.Vender == "LeisaiPulse")
{
LeisaiIO eio = (LeisaiIO)io;
apiResult = LTDMC.dmc_read_inbit((ushort)io.CardID, eio.Index);
if (eio.IsReverse)
{
return (short)((~apiResult) & 0x01);
}
else
{
return (short)apiResult;
}
}
else if (io.Card.Vender == "LeisaiPulseEx")
{
LeisaiIO eio = (LeisaiIO)io;
ushort value = 0;
apiResult = LTDMC.nmc_read_inbit((ushort)io.CardID, eio.SlaveNo, eio.Index,ref value);
if(apiResult==0)
{
if (eio.IsReverse)
{
return (short)((~value) & 0x01);
}
else
{
return (short)value;
}
}
}
}
return -1;
}
@ -321,6 +367,36 @@ namespace Rs.Motion
}
}
}
else if (io.Card.Vender == "LeisaiPulse")
{
LeisaiIO eio = (LeisaiIO)io;
apiResult = LTDMC.dmc_read_outbit((ushort)io.CardID, eio.Index);
if (eio.IsReverse)
{
return (short)((~apiResult) & 0x01);
}
else
{
return (short)apiResult;
}
}
else if (io.Card.Vender == "LeisaiPulseEx")
{
LeisaiIO eio = (LeisaiIO)io;
ushort ioValue = 0;
apiResult = LTDMC.nmc_read_outbit((ushort)io.CardID,eio.SlaveNo, eio.Index,ref ioValue);
if(apiResult == 0)
{
if (eio.IsReverse)
{
return (short)((~ioValue) & 0x01);
}
else
{
return (short)ioValue;
}
}
}
}
return -1;
}
@ -371,6 +447,16 @@ namespace Rs.Motion
ZtmIO ztm = (ZtmIO)io;
short ret = CSZTM.ZTM.ZT_SetOutBit(ztm.mc,(short) ztm.SlaveNo, (short)ztm.Index, value);
}
else if (io.Card.Vender == "LeisaiPulse")
{
LeisaiIO gio = (LeisaiIO)io;
LTDMC.dmc_write_outbit((ushort)gio.CardID, gio.Index, value);
}
else if (io.Card.Vender == "LeisaiPulseEx")
{
LeisaiIO gio = (LeisaiIO)io;
LTDMC.nmc_write_outbit((ushort)gio.CardID,gio.SlaveNo, gio.Index, value);
}
}
return -1;
}

File diff suppressed because it is too large Load Diff

@ -0,0 +1,119 @@
using Rs.Framework;
using Rs.Motion.Base;
using Rs.Motion.Base.Config;
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.Leisai
{
public class LeisaiCard:ICard
{
public LeisaiCard(ushort cardID,ushort axisCount,string cfgName)
{
CardID= cardID;
AxisCount= axisCount;
CfgName= cfgName;
Config = new CardConfig();
}
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);
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;
}
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++)
{
try
{
IAxis axis = new LeisaiAxis(Config.AxisConfigs[i]);
axis.Card = this;
axis.Config.Axis = axis;
axis.Init();
AxisIdDic.Add(axis.Config.AxisId, axis);
AxisNameDic.Add(axis.Config.AxisName, axis);
}
catch (Exception)
{
}
}
return ErrorCode.Ok;
}
}
}

@ -0,0 +1,151 @@
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;
using csLTDMC;
namespace Rs.Motion.Leisai
{
/// <summary>
/// 蕾塞脉冲卡
/// </summary>
public class LeisaiCardManager : ICardManager
{
/// <summary>
/// 执行底层接口的返回值
/// </summary>
private short apiResult = 0;
/// <summary>
/// 保存一共有多少张卡
/// </summary>
Dictionary<ushort,ICard> cardDic= new Dictionary<ushort,ICard>();
private LeisaiCardManager() {
}
private static LeisaiCardManager instance;
public static LeisaiCardManager Instance
{
get
{
if(instance==null)
{
instance = new LeisaiCardManager();
}
return instance;
}
}
public override IIOCard AddIoCard(int cardID, string name, string vender, bool isEthercat, ushort inNum, ushort outNum, int slaveID)
{
string filename = string.Empty;
LeisaiIOCard ioCard = new LeisaiIOCard();
if(vender== "LeisaiPulseEx")
{
//先打开卡
apiResult = LTDMC.nmc_set_connect_state((ushort)cardID, (ushort)slaveID, 1, 0);
if(apiResult== 0)
{
LogHelper.Debug($"打开扩展卡{slaveID-1}成功");
}
else
{
LogHelper.Debug($"打开扩展卡{slaveID - 1}失败");
}
filename = $"config/motion/io/LeisaiPulseEx{cardID}.xml";
}
else
{
filename = $"config/motion/io/leisai{cardID}.xml";
}
//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.SlaveID = (ushort)slaveID;
ioCard.Init((short)cardID,inNum, outNum, (ushort)slaveID);
bool suc = XmlSerializerHelper.Instance.Serialize<LeisaiIOCard>(filename, ioCard);
}
else
XmlSerializerHelper.Instance.Deserialize<LeisaiIOCard>(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='leisai' and enable=1 order by id asc");
if(dt!=null&&dt.Rows.Count>0)
{
MessageQueue.Instance.Insert($"have {dt.Rows.Count} card need init");
foreach (DataRow row in dt.Rows)
{
ushort cardid = ushort.Parse(row["cardid"].ToString());
//打开运动控制卡
apiResult = LTDMC.dmc_board_init_onecard(cardid);
if (apiResult <= 0)
{
MessageQueue.Instance.Warn($"{apiResult} = LTDMC.dmc_board_init_onecard({cardid});");
return ErrorCode.CardInitFail;
}
else
{
//加载配置文件
if(File.Exists($"leisai{cardid}.ini"))
{
apiResult = LTDMC.dmc_download_configfile(ushort.Parse(row["cardid"].ToString()), $"leisai{cardid}.ini");
LogHelper.Debug($"加载蕾塞配置文件leisai{cardid},ret={apiResult}");
}
MessageQueue.Instance.Insert($"{apiResult} = LTDMC.dmc_download_configfile({ushort.Parse(row["cardid"].ToString())}, $\"leisai{{cardid}}.ini\");");
}
}
}
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 LeisaiCard(cardID, 8, $"leisai{cardID}.xml");
card.Init();
if(!cardDic.ContainsKey((ushort)cardID))
{
cardDic.Add((ushort)cardID, card);
}
return card;
}
}
}

@ -0,0 +1,14 @@
using Rs.Motion.Base;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Rs.Motion.Leisai
{
public class LeisaiIO : IIO
{
public ushort SlaveNo { get; set; }
}
}

@ -0,0 +1,49 @@
using Rs.Framework;
using Rs.Motion.Base;
using Rs.Motion.Ztm;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Serialization;
namespace Rs.Motion.Leisai
{
/// <summary>
/// GLink卡
/// </summary>
[XmlInclude(typeof(LeisaiIO))]
public class LeisaiIOCard : IIOCard
{
public override void Init(short cardID,ushort inCount, ushort outCount, ushort slaveNo)
{
for (ushort i = 0; i < outCount; i++)
{
LeisaiIO io = new LeisaiIO();
io.SlaveNo = slaveNo;
io.CardID = cardID;
io.CardID = (short)CardID;
io.Name = "Out" + i + "_" + slaveNo;
io.Index = i;
DOut.Add(io);
}
for (ushort i = 0; i < inCount; i++)
{
LeisaiIO io = new LeisaiIO();
io.SlaveNo=slaveNo;
io.CardID = cardID;
io.Card = this;
io.Name = "In" + i + "_" + slaveNo;
io.Index = i;
DIn.Add(io);
}
}
public override void Save()
{
string filename = $"config/motion/io/leisai{CardID}.xml";
XmlSerializerHelper.Instance.Serialize<LeisaiIOCard>(filename, this);
}
}
}

@ -77,8 +77,14 @@
<Compile Include="Invoke\GugaoECat\LookAheadEx.cs" />
<Compile Include="Invoke\GugaoPulse\config.cs" />
<Compile Include="Invoke\GugaoPulse\gts.cs" />
<Compile Include="Invoke\Leisai\LTDMC.cs" />
<Compile Include="Invoke\Ztm\ZTM.cs" />
<Compile Include="IoManager.cs" />
<Compile Include="Leisai\LeisaiAxis.cs" />
<Compile Include="Leisai\LeisaiCard.cs" />
<Compile Include="Leisai\LeisaiCardManager.cs" />
<Compile Include="Leisai\LeisaiIO.cs" />
<Compile Include="Leisai\LeisaiIOCard.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Ztm\ZtmAxis.cs" />
<Compile Include="Ztm\ZtmCard.cs" />

@ -19,6 +19,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HWindow_Tool", "HWindow_Too
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Rs.Cameras", "Rs.Cameras\Rs.Cameras.csproj", "{971D93FF-FD34-4088-9591-C25147290D22}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Rs.AutomaticDoubleUpAndDown", "..\Rs.AutomaticDoubleUpAndDown\Rs.AutomaticDoubleUpAndDown\Rs.AutomaticDoubleUpAndDown.csproj", "{983F6B3C-E08A-42F0-8A34-2E6590636811}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -57,6 +59,10 @@ Global
{971D93FF-FD34-4088-9591-C25147290D22}.Debug|Any CPU.Build.0 = Debug|Any CPU
{971D93FF-FD34-4088-9591-C25147290D22}.Release|Any CPU.ActiveCfg = Release|Any CPU
{971D93FF-FD34-4088-9591-C25147290D22}.Release|Any CPU.Build.0 = Release|Any CPU
{983F6B3C-E08A-42F0-8A34-2E6590636811}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{983F6B3C-E08A-42F0-8A34-2E6590636811}.Debug|Any CPU.Build.0 = Debug|Any CPU
{983F6B3C-E08A-42F0-8A34-2E6590636811}.Release|Any CPU.ActiveCfg = Release|Any CPU
{983F6B3C-E08A-42F0-8A34-2E6590636811}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

Loading…
Cancel
Save