316 lines
8.6 KiB
C#
316 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>
|
||
/// <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;
|
||
// }
|
||
|
||
//}
|
||
|
||
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;
|
||
// }
|
||
//}
|
||
|
||
if (value == 1)
|
||
{
|
||
this.OutputColor = ColorStr.Red;
|
||
}
|
||
else
|
||
{
|
||
this.OutputColor = ColorStr.Green;
|
||
}
|
||
|
||
OutputSwitch(value);
|
||
this.RaisePropertyChanged("LevelStart");
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// 输入信号的含义
|
||
/// </summary>
|
||
public string OutputMeaning { get; set; }
|
||
|
||
/// <summary>
|
||
/// 是否属于运动控制卡
|
||
/// </summary>
|
||
public bool ToRunControlCard { get; set; }
|
||
|
||
/// <summary>
|
||
/// 空信号
|
||
/// </summary>
|
||
public bool EmptySignal { 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 OutputSwitch1(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);
|
||
|
||
//雷赛IO模块
|
||
MS_MB_API.Outputs[IoNumber] = (byte)levelState;
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 控制卡输出信号开关
|
||
/// </summary>
|
||
public void OutputSwitch(ushort onoff)
|
||
{
|
||
if (ToRunControlCard)
|
||
{
|
||
// LTDMC.dmc_write_outbit(CardID, IoNumber, onoff);
|
||
// LTSMC.smc_write_outbit(CardID, IoNumber, onoff);
|
||
// zmcaux.ZAux_Direct_SetOp(g_handle, IoNumber, onoff);
|
||
}
|
||
else
|
||
{
|
||
// IOC0640.ioc_write_outbit(CardID, IoNumber, onoff);
|
||
}
|
||
MS_MB_API.Outputs[IoNumber] = (byte)levelState;
|
||
}
|
||
#endregion
|
||
|
||
/// <summary>
|
||
/// 将八进制整数转换为十进制整数
|
||
/// </summary>
|
||
/// <param name="octal">八进制整数</param>
|
||
/// <returns>十进制整数</returns>
|
||
public int OctalToDecimal(int octal)
|
||
{
|
||
int decimalValue = 0;
|
||
int baseValue = 1;
|
||
int temp = octal;
|
||
while (temp > 0)
|
||
{
|
||
int lastDigit = temp % 10;
|
||
decimalValue += lastDigit * baseValue;
|
||
baseValue *= 8;
|
||
temp /= 10;
|
||
}
|
||
return decimalValue;
|
||
}
|
||
}
|
||
}
|