using Community; using Model.MotionControl; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Model { /// /// 输出信号类 /// public class OutputSignal : NotificationObject { /// /// 链接返回的句柄,可以作为卡号 众为兴控制卡 /// public IntPtr g_handle; /// /// 对应的运行控制卡 /// public FeiYuCard MyCard { get; set; } public int ID { get; set; } private ushort cardID; /// /// 卡ID /// public ushort CardID { get { return cardID; } set { cardID = value; } } /// /// 端口号 /// public ushort IoNumber { get; set; } /// /// IO打开的时间 /// public DateTime SwitchsOpenTime { get; set; } private bool switchs; /// /// 开关 /// 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; /// /// 输出信号类型 0:机架信号 1:点胶模块信号 2:锁螺丝模块信号 /// public int MyType { get { return myType; } set { myType = value; this.RaisePropertyChanged("MyType"); } } private ushort levelState; /// /// 输出端口电平状态 /// 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"); } } /// /// 输入信号的含义 /// public string OutputMeaning { get; set; } /// /// 是否属于运动控制卡 /// public bool ToRunControlCard { get; set; } private string outputColor; /// /// 表示显色 /// public string OutputColor { get { return outputColor; } set { outputColor = value; this.RaisePropertyChanged("OutputColor"); } } public OutputSignal() { ToRunControlCard = false; Switchs = false; } #region 控制卡输出信号开关 /// /// 控制卡输出信号开关 /// 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 { 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 } }