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; }
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;
// }
// 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;
///
/// 输出信号类型 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;
// }
//}
if (value == 1)
{
this.OutputColor = ColorStr.Red;
}
else
{
this.OutputColor = ColorStr.Green;
}
OutputSwitch(value);
this.RaisePropertyChanged("LevelStart");
}
}
///
/// 输入信号的含义
///
public string OutputMeaning { get; set; }
///
/// 是否属于运动控制卡
///
public bool ToRunControlCard { get; set; }
///
/// 空信号
///
public bool EmptySignal { 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 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;
}
}
///
/// 控制卡输出信号开关
///
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
///
/// 将八进制整数转换为十进制整数
///
/// 八进制整数
/// 十进制整数
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;
}
}
}