310 lines
8.6 KiB
C#
310 lines
8.6 KiB
C#
using Community;
|
||
using Model.MotionControl;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.Linq;
|
||
using System.Text;
|
||
using System.Threading.Tasks;
|
||
|
||
namespace Model
|
||
{
|
||
/// <summary>
|
||
/// 输出信号类
|
||
/// </summary>
|
||
public class OutputSignal : NotificationObject
|
||
{
|
||
/// <summary>
|
||
/// 链接返回的句柄,可以作为卡号 众为兴控制卡
|
||
/// </summary>
|
||
public IntPtr g_handle;
|
||
|
||
/// <summary>
|
||
/// 对应的运行控制卡
|
||
/// </summary>
|
||
public FeiYuCard MyCard { get; set; }
|
||
|
||
public int ID { get; set; }
|
||
|
||
private ushort cardID;
|
||
/// <summary>
|
||
/// 卡ID
|
||
/// </summary>
|
||
public ushort CardID
|
||
{
|
||
get { return cardID; }
|
||
set { cardID = value; }
|
||
}
|
||
|
||
/// <summary>
|
||
/// 端口号
|
||
/// </summary>
|
||
public ushort IoNumber { get; set; }
|
||
|
||
/// <summary>
|
||
/// IO打开的时间
|
||
/// </summary>
|
||
public DateTime SwitchsOpenTime { get; set; }
|
||
|
||
|
||
private bool switchs;
|
||
/// <summary>
|
||
/// 开关
|
||
/// </summary>
|
||
public bool Switchs
|
||
{
|
||
get { return switchs; }
|
||
set
|
||
{
|
||
switchs = value;
|
||
|
||
if (ToRunControlCard && MyCard != null)
|
||
{
|
||
switch (MyCard.Brand)
|
||
{
|
||
case 1:
|
||
if (value)
|
||
{
|
||
LevelState = 0;
|
||
SwitchsOpenTime = DateTime.Now;
|
||
}
|
||
else
|
||
{
|
||
LevelState = 1;
|
||
}
|
||
break;
|
||
case 2:
|
||
if (value)
|
||
{
|
||
LevelState = 0;
|
||
SwitchsOpenTime = DateTime.Now;
|
||
}
|
||
else
|
||
{
|
||
LevelState = 1;
|
||
}
|
||
break;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if (value)
|
||
{
|
||
LevelState = 1;
|
||
SwitchsOpenTime = DateTime.Now;
|
||
}
|
||
else
|
||
{
|
||
LevelState = 0;
|
||
SwitchsOpenTime = DateTime.Now;
|
||
}
|
||
|
||
}
|
||
|
||
this.RaisePropertyChanged("Switchs");
|
||
}
|
||
}
|
||
|
||
|
||
private int myType;
|
||
/// <summary>
|
||
/// 输出信号类型 0:机架信号 1:点胶模块信号 2:锁螺丝模块信号
|
||
/// </summary>
|
||
public int MyType
|
||
{
|
||
get { return myType; }
|
||
set
|
||
{
|
||
myType = value;
|
||
this.RaisePropertyChanged("MyType");
|
||
}
|
||
}
|
||
|
||
|
||
|
||
private ushort levelState;
|
||
/// <summary>
|
||
/// 输出端口电平状态
|
||
/// </summary>
|
||
public ushort LevelState
|
||
{
|
||
get { return levelState; }
|
||
set
|
||
{
|
||
levelState = value;
|
||
|
||
if (ToRunControlCard && MyCard != null)
|
||
{
|
||
switch (MyCard.Brand)
|
||
{
|
||
case 1:
|
||
if (value == 1)
|
||
{
|
||
this.OutputColor = ColorStr.Green;
|
||
}
|
||
else
|
||
{
|
||
this.OutputColor = ColorStr.Red;
|
||
}
|
||
break;
|
||
case 2:
|
||
if (value == 0)
|
||
{
|
||
this.OutputColor = ColorStr.Red;
|
||
}
|
||
else
|
||
{
|
||
this.OutputColor = ColorStr.Green;
|
||
}
|
||
break;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if (value == 0)
|
||
{
|
||
|
||
this.OutputColor = ColorStr.Green;
|
||
}
|
||
else
|
||
{
|
||
this.OutputColor = ColorStr.Red;
|
||
}
|
||
}
|
||
|
||
OutputSwitch(value);
|
||
this.RaisePropertyChanged("LevelStart");
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// 输入信号的含义
|
||
/// </summary>
|
||
public string OutputMeaning { get; set; }
|
||
|
||
/// <summary>
|
||
/// 是否属于运动控制卡
|
||
/// </summary>
|
||
public bool ToRunControlCard { get; set; }
|
||
|
||
private string outputColor;
|
||
/// <summary>
|
||
/// 表示显色
|
||
/// </summary>
|
||
public string OutputColor
|
||
{
|
||
get { return outputColor; }
|
||
set
|
||
{
|
||
outputColor = value;
|
||
this.RaisePropertyChanged("OutputColor");
|
||
}
|
||
}
|
||
|
||
|
||
public OutputSignal()
|
||
{
|
||
ToRunControlCard = false;
|
||
Switchs = false;
|
||
}
|
||
|
||
|
||
#region 控制卡输出信号开关
|
||
|
||
|
||
/// <summary>
|
||
/// 控制卡输出信号开关
|
||
/// </summary>
|
||
public void OutputSwitch(ushort onoff)
|
||
{
|
||
|
||
if (ToRunControlCard && MyCard != null)
|
||
{
|
||
switch (MyCard.Brand)
|
||
{
|
||
case 1:
|
||
if (MyCard.InterfaceType == 2)
|
||
{
|
||
LTSMC.smc_write_outbit(MyCard.CardID, IoNumber, onoff);
|
||
}
|
||
else
|
||
{
|
||
LTDMC.dmc_write_outbit(MyCard.CardID, IoNumber, onoff);
|
||
}
|
||
break;
|
||
case 2:
|
||
onoff = onoff == (ushort)0 ? (ushort)1 : (ushort)0;
|
||
if (MyCard.InterfaceType == 2)
|
||
{
|
||
zmcaux.ZAux_Direct_SetOp(g_handle, IoNumber, onoff);
|
||
}
|
||
else if (MyCard.InterfaceType==0)
|
||
{
|
||
adt8949.adt8949_write_bit(MyCard.CardID, IoNumber, onoff);
|
||
}
|
||
else
|
||
{
|
||
ADTMC.adt_write_outbit(MyCard.CardID, IoNumber, onoff);
|
||
}
|
||
break;
|
||
|
||
}
|
||
|
||
|
||
|
||
|
||
}
|
||
else
|
||
{
|
||
//雷赛IO卡
|
||
//IOC0640.ioc_write_outbit(CardID, IoNumber, onoff);
|
||
//众为兴沙雕IO卡
|
||
adtIO3224.adtIO3224_write_bit(CardID, IoNumber, onoff);
|
||
}
|
||
}
|
||
|
||
public void OutputSwitch(ushort IoNumber, ushort onoff)
|
||
{
|
||
|
||
if (ToRunControlCard && MyCard != null)
|
||
{
|
||
switch (MyCard.Brand)
|
||
{
|
||
case 1:
|
||
if (MyCard.InterfaceType == 2)
|
||
{
|
||
LTSMC.smc_write_outbit(MyCard.CardID, IoNumber, onoff);
|
||
}
|
||
else
|
||
{
|
||
LTDMC.dmc_write_outbit(MyCard.CardID, IoNumber, onoff);
|
||
}
|
||
break;
|
||
case 2:
|
||
onoff = onoff == (ushort)0 ? (ushort)1 : (ushort)0;
|
||
if (MyCard.InterfaceType == 2)
|
||
{
|
||
zmcaux.ZAux_Direct_SetOp(g_handle, IoNumber, onoff);
|
||
}
|
||
else
|
||
{
|
||
ADTMC.adt_write_outbit(MyCard.CardID, IoNumber, onoff);
|
||
}
|
||
break;
|
||
|
||
}
|
||
|
||
|
||
|
||
|
||
}
|
||
else
|
||
{
|
||
//雷赛IO卡
|
||
//IOC0640.ioc_write_outbit(CardID, IoNumber, onoff);
|
||
//众为兴沙雕IO卡
|
||
adtIO3224.adtIO3224_write_bit(CardID, IoNumber, onoff);
|
||
}
|
||
}
|
||
#endregion
|
||
}
|
||
}
|