liteon/Model/OutputSignal.cs
2025-07-12 14:05:35 +08:00

250 lines
6.5 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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; }
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;
}
else
{
LevelState = 1;
}
break;
case 2:
if (value)
{
LevelState = 0;
}
else
{
LevelState = 1;
}
break;
}
}
else
{
if (value)
{
LevelState = 1;
}
else
{
LevelState = 0;
}
}
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
{
ADTMC.adt_write_outbit(MyCard.CardID, IoNumber, onoff);
}
break;
}
}
else
{
IOC0640.ioc_write_outbit(CardID, IoNumber, onoff);
}
}
#endregion
}
}