1、固高脉冲卡去掉初始化时的配置项,改为从配置文件加载

2、固高脉冲卡增加对扩展IO卡的支持
master
lhiven 10 months ago
parent a224a888e4
commit 2fbaa910ef

@ -33,7 +33,7 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="halcondotnet">
<HintPath>C:\Users\Administrator\Desktop\Rs.MotionPlat\Rs.MotionPlat\bin\Debug\halcondotnet.dll</HintPath>
<HintPath>..\HWindow_Tool\bin\Debug\halcondotnet.dll</HintPath>
</Reference>
<Reference Include="log4net, Version=2.0.15.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
<HintPath>..\packages\log4net.2.0.15\lib\net45\log4net.dll</HintPath>

@ -172,7 +172,7 @@ namespace Rs.Motion.Base.Config
[XmlElement]
[CommonPropertyDescription("限位开关是否启用 根据卡的相关说明配置")]
[CopyAttribute]
public ushort EnableEL { get; set; }
public short EnableEL { get; set; }
[XmlElement]
[CommonPropertyDescription("软极限制动模式 0:减速停止 1:立即停止")]
[CopyAttribute]

@ -16,6 +16,7 @@ namespace Rs.Motion.Base
[XmlElement]
public List<IIO> DOut { get; set; } = new List<IIO>();
public ushort SlaveID { get; set; }
public ushort CardID { get; set; } = 0;
public string Name { get; set; } = "本地IO";

@ -56,65 +56,65 @@ namespace Rs.Motion.GugaoPulse
apiResult = mc_pulse_cfg.GT_SetDiConfig((short)Config.CardId, mc_pulse.MC_ALARM, (short)Config.AxisId, ref diConfig);
}
mc_pulse_cfg.GT_GetDoConfig((short)Config.CardId, mc_pulse.MC_GPO, 11, out mc_pulse_cfg.TDoConfig oConfig);
oConfig.reverse = 0;
mc_pulse_cfg.GT_SetDoConfig((short)Config.CardId, mc_pulse.MC_GPO, 11, ref oConfig);
//mc_pulse_cfg.GT_GetDoConfig((short)Config.CardId, mc_pulse.MC_GPO, 11, out mc_pulse_cfg.TDoConfig oConfig);
//oConfig.reverse = 0;
//mc_pulse_cfg.GT_SetDoConfig((short)Config.CardId, mc_pulse.MC_GPO, 11, ref oConfig);
mc_pulse_cfg.GT_GetDoConfig((short)Config.CardId, mc_pulse.MC_GPO, 12, out oConfig);
oConfig.reverse = 1;
mc_pulse_cfg.GT_SetDoConfig((short)Config.CardId, mc_pulse.MC_GPO, 12, ref oConfig);
//mc_pulse_cfg.GT_GetDoConfig((short)Config.CardId, mc_pulse.MC_GPO, 12, out oConfig);
//oConfig.reverse = 1;
//mc_pulse_cfg.GT_SetDoConfig((short)Config.CardId, mc_pulse.MC_GPO, 12, ref oConfig);
mc_pulse_cfg.GT_GetDoConfig((short)Config.CardId, mc_pulse.MC_GPO, 13, out oConfig);
oConfig.reverse = 1;
mc_pulse_cfg.GT_SetDoConfig((short)Config.CardId, mc_pulse.MC_GPO, 13, ref oConfig);
//mc_pulse_cfg.GT_GetDoConfig((short)Config.CardId, mc_pulse.MC_GPO, 13, out oConfig);
//oConfig.reverse = 1;
//mc_pulse_cfg.GT_SetDoConfig((short)Config.CardId, mc_pulse.MC_GPO, 13, ref oConfig);
//先判断正限位
if ((Config.EnableEL & 0x01) == 0)//禁用正限位
{
mc_pulse.GT_LmtsOff((short)Config.CardId, (short)Config.AxisId, mc_pulse.MC_LIMIT_POSITIVE);
}
else
{
axisConfig.limitPositiveIndex = (short)Config.AxisId;
//axisConfig.alarmIndex = (short)Config.AxisId;
apiResult = mc_pulse_cfg.GT_GetDiConfig((short)Config.CardId, mc_pulse.MC_LIMIT_POSITIVE, (short)Config.AxisId, out diConfig);
diConfig.active = 1;
diConfig.reverse = (short)Config.ElLogic;
diConfig.filterTime = 3;
apiResult = mc_pulse_cfg.GT_SetDiConfig((short)Config.CardId, mc_pulse.MC_LIMIT_POSITIVE, (short)Config.AxisId, ref diConfig);
//if ((Config.EnableEL & 0x01) == 0)//禁用正限位
//{
// mc_pulse.GT_LmtsOff((short)Config.CardId, (short)Config.AxisId, mc_pulse.MC_LIMIT_POSITIVE);
//}
//else
//{
// axisConfig.limitPositiveIndex = (short)Config.AxisId;
// //axisConfig.alarmIndex = (short)Config.AxisId;
// apiResult = mc_pulse_cfg.GT_GetDiConfig((short)Config.CardId, mc_pulse.MC_LIMIT_POSITIVE, (short)Config.AxisId, out diConfig);
// diConfig.active = 1;
// diConfig.reverse = (short)Config.ElLogic;
// diConfig.filterTime = 3;
// apiResult = mc_pulse_cfg.GT_SetDiConfig((short)Config.CardId, mc_pulse.MC_LIMIT_POSITIVE, (short)Config.AxisId, ref diConfig);
}
//先判断负限位
if (((Config.EnableEL >> 1) & 0x01) == 0)
{
mc_pulse.GT_LmtsOff((short)Config.CardId, (short)Config.AxisId, mc_pulse.MC_LIMIT_NEGATIVE);
}
else
{
axisConfig.limitNegativeIndex = (short)Config.AxisId;
apiResult = mc_pulse_cfg.GT_GetDiConfig((short)Config.CardId, mc_pulse.MC_LIMIT_NEGATIVE, (short)Config.AxisId, out diConfig);
diConfig.active = 1;
diConfig.reverse = (short)Config.ElLogic;
diConfig.filterTime = 3;
apiResult = mc_pulse_cfg.GT_SetDiConfig((short)Config.CardId, mc_pulse.MC_LIMIT_NEGATIVE, (short)Config.AxisId, ref diConfig);
}
if (Config.EnableInp == 1)
{
apiResult = mc_pulse_cfg.GT_GetDiConfig((short)Config.CardId, mc_pulse.MC_ARRIVE, (short)Config.AxisId, out diConfig);
diConfig.active = 1;
diConfig.reverse = (short)Config.InpLogic;
apiResult = mc_pulse_cfg.GT_SetDiConfig((short)Config.CardId, mc_pulse.MC_ARRIVE, (short)Config.AxisId, ref diConfig);
}
//}
////先判断负限位
//if (((Config.EnableEL >> 1) & 0x01) == 0)
//{
// mc_pulse.GT_LmtsOff((short)Config.CardId, (short)Config.AxisId, mc_pulse.MC_LIMIT_NEGATIVE);
//}
//else
//{
// axisConfig.limitNegativeIndex = (short)Config.AxisId;
// apiResult = mc_pulse_cfg.GT_GetDiConfig((short)Config.CardId, mc_pulse.MC_LIMIT_NEGATIVE, (short)Config.AxisId, out diConfig);
// diConfig.active = 1;
// diConfig.reverse = (short)Config.ElLogic;
// diConfig.filterTime = 3;
// apiResult = mc_pulse_cfg.GT_SetDiConfig((short)Config.CardId, mc_pulse.MC_LIMIT_NEGATIVE, (short)Config.AxisId, ref diConfig);
//}
//if (Config.EnableInp == 1)
//{
// apiResult = mc_pulse_cfg.GT_GetDiConfig((short)Config.CardId, mc_pulse.MC_ARRIVE, (short)Config.AxisId, out diConfig);
// diConfig.active = 1;
// diConfig.reverse = (short)Config.InpLogic;
// apiResult = mc_pulse_cfg.GT_SetDiConfig((short)Config.CardId, mc_pulse.MC_ARRIVE, (short)Config.AxisId, ref diConfig);
//}
apiResult = mc_pulse_cfg.GT_GetDiConfig((short)Config.CardId, mc_pulse.MC_HOME, (short)Config.AxisId, out diConfig);
diConfig.active = 1;
diConfig.reverse = (short)Config.HomeOrgLogic;
diConfig.filterTime = 3;
apiResult = mc_pulse_cfg.GT_SetDiConfig((short)Config.CardId, mc_pulse.MC_HOME, (short)Config.AxisId, ref diConfig);
apiResult = mc_pulse_cfg.GT_SetAxisConfig((short)Config.CardId, (short)Config.AxisId, ref axisConfig);
//apiResult = mc_pulse_cfg.GT_SetAxisConfig((short)Config.CardId, (short)Config.AxisId, ref axisConfig);
// mc_cfg.GT_SetDiConfig(short diType, short diIndex, ref TDiConfig pDi);
//mc_pulse.GT_EncSns((short)Config.CardId, 0);
mc_pulse.GT_ClrSts((short)Config.CardId, (short)Config.AxisId, 1);
@ -809,6 +809,7 @@ namespace Rs.Motion.GugaoPulse
homePrm.searchHomeDistance = 0;
homePrm.searchIndexDistance = 0;
homePrm.edge = (short)(Config.HomeOrgLogic == 0 ? 1 : 0);
apiResult = mc_pulse.GT_GoHome((short)Config.CardId, (short)Config.AxisId, ref homePrm);
// LogHelper.Debug($"axis {Config.AxisName} start home ,homedir={Config.HomeDir},homemode={Config.HomeMode}");

@ -49,14 +49,36 @@ namespace Rs.Motion.GugaoPulse
public override IIOCard AddIoCard(int cardID, string name, string vender, bool isEthercat, ushort inNum, ushort outNum, int slaveID)
{
string filename = string.Empty;
GLinkIOCard ioCard = new GLinkIOCard();
string filename = $"config/motion/io/gugao{cardID}.xml";
if(vender== "GugaoPulseExt")
{
//先打开卡
apiResult = mc_pulse.GT_OpenExtMdl((short)cardID, "gts.dll");
if(apiResult== 0)
{
mc_pulse.GT_LoadExtConfig((short)cardID, "ExtModule.cfg");
LogHelper.Debug($"打开扩展卡{slaveID-1}成功");
}
else
{
LogHelper.Debug($"打开扩展卡{slaveID - 1}失败");
}
filename = $"config/motion/io/gugaoext{cardID}.xml";
}
else
{
filename = $"config/motion/io/gugao{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<GLinkIOCard>(filename, ioCard);
}
@ -78,9 +100,10 @@ namespace Rs.Motion.GugaoPulse
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");
DataTable dt = db.GetDataTable("select * from motioncard where vender='gugao' 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)
{
//ICard card = new GugaoPulseCard(ushort.Parse(row["cardid"].ToString()), 8, $"gugaopulse{row["cardid"]}.xml");
@ -90,8 +113,20 @@ namespace Rs.Motion.GugaoPulse
apiResult = mc_pulse.GT_Open(short.Parse(row["cardid"].ToString()), 0, 1);
if (apiResult != 0)
{
MessageQueue.Instance.Warn($"mc_pulse.GT_Open({short.Parse(row["cardid"].ToString())}, 0, 1);ret={apiResult}");
return ErrorCode.CardInitFail;
}
else
{
//加载配置文件
short cardid = short.Parse(row["cardid"].ToString());
if(File.Exists($"gugao{cardid}.cfg"))
{
apiResult = mc_pulse.GT_LoadConfig(short.Parse(row["cardid"].ToString()), $"gugao{cardid}.cfg");
LogHelper.Debug($"加载固高配置文件gugao{cardid},ret={apiResult}");
}
MessageQueue.Instance.Insert($"mc_pulse.GT_Open({short.Parse(row["cardid"].ToString())}, 0, 1);ret={apiResult}");
}
//清楚报警和限位
apiResult = mc_pulse.GT_ClrSts(0, 1, 8);
if (apiResult != 0)

@ -32,6 +32,16 @@ namespace Rs.Motion
ushort.Parse(dr["OutNum"].ToString()),
int.Parse(dr["SlaveID"].ToString()
));
case "GugaoPulseExt":
return GugaoPulseCardManager.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()
));
case "GugaoPulse":
return GugaoPulseCardManager.Instance.AddIoCard(
int.Parse(dr["CardID"].ToString()),
@ -167,7 +177,31 @@ namespace Rs.Motion
if (apiResult == 0)
{
byte pValue = (byte)(~(value >> eio.Index) & 0x01);
return pValue;
if (eio.IsReverse)
{
return (short)((~pValue) & 0x01);
}
else
{
return (short)pValue;
}
}
}
else if(io.Card.Vender== "GugaoPulseExt")
{
GLinkIO eio = (GLinkIO)io;
apiResult = mc_pulse.GT_GetExtIoValue((short)io.CardID,(short)(io.Card.SlaveID-1), out ushort value);
if (apiResult == 0)
{
byte pValue = (byte)(~(value >> eio.Index) & 0x01);
if (eio.IsReverse)
{
return (short)((~pValue) & 0x01);
}
else
{
return (short)pValue;
}
}
}
else if (io.Card.Vender.ToLower() == "ztm")
@ -253,6 +287,23 @@ namespace Rs.Motion
}
}
}
else if (io.Card.Vender == "GugaoPulseExt")
{
GLinkIO eio = (GLinkIO)io;
apiResult = mc_pulse.GT_GetExtDoValue(io.CardID, (short)(io.Card.SlaveID-1), out ushort value);
if (apiResult == 0)
{
byte pValue = (byte)((value >> eio.Index) & 0x01);
if (io.IsReverse)
{
return (short)((~pValue) & 0x01);
}
else
{
return (short)pValue;
}
}
}
else if (io.Card.Vender.ToLower() == "ztm")
{
ZtmIO zio = (ZtmIO)io;
@ -310,6 +361,11 @@ namespace Rs.Motion
GLinkIO gio = (GLinkIO)io;
apiResult = mc_pulse.GT_SetDoBit(gio.CardID, mc_pulse.MC_GPO, (short)(gio.Index + 1), value);
}
else if (io.Card.Vender == "GugaoPulseExt")
{
GLinkIO gio = (GLinkIO)io;
apiResult = mc_pulse.GT_SetExtIoBit(gio.CardID,(short)(io.Card.SlaveID-1), (short)(gio.Index), value);
}
else if(io.Card.Vender.ToLower()=="ztm")
{
ZtmIO ztm = (ZtmIO)io;

Loading…
Cancel
Save