Feiyu/Model/InputSignal.cs
2026-01-27 21:04:52 +08:00

347 lines
11 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;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.StartPanel;
namespace Model
{
/// <summary>
/// 数入信号类
/// </summary>
public class InputSignal : NotificationObject
{
/// <summary>
/// 链接返回的句柄,可以作为卡号 众为兴控制卡
/// </summary>
public IntPtr g_handle;
/// <summary>
/// 对应的运行控制卡
/// </summary>
public FeiYuCard MyCard { get; set; }
public int ID { get; set; }
/// <summary>
/// 卡ID
/// </summary>
public ushort CardID { get; set; }
/// <summary>
/// 输入端口号
/// </summary>
public ushort IoNumber { get; set; }
private int myType;
/// <summary>
/// 输出信号类型 0:机架信号 1:点胶模块信号 2:锁螺丝模块信号
/// </summary>
public int MyType
{
get { return myType; }
set
{
myType = value;
this.RaisePropertyChanged("MyType");
}
}
private int levelState;
/// <summary>
/// 输入端口电平输入状态
/// </summary>
public int LevelState
{
get
{
return levelState;
}
set
{
//levelState = value;
//if (ToRunControlCard)
//{
// if (MyCard == null)
// {
// this.InputColor = ColorStr.Gray;
// return;
// }
// switch (MyCard.Brand)
// {
// case 1:
// if (HightEff)
// {
// if (value == 0)
// {
// this.InputColor = ColorStr.Gray;
// }
// else
// {
// this.InputColor = ColorStr.Green;
// }
// }
// else
// {
// if (value == 1)
// {
// this.InputColor = ColorStr.Gray;
// }
// else
// {
// this.InputColor = ColorStr.Green;
// }
// }
// break;
// case 2:
// if (HightEff)
// {
// if (value == 0)
// {
// this.InputColor = ColorStr.Green;
// }
// else
// {
// this.InputColor = ColorStr.Gray;
// }
// }
// else
// {
// if (value == 1)
// {
// this.InputColor = ColorStr.Green;
// }
// else
// {
// this.InputColor = ColorStr.Gray;
// }
// }
// break;
// }
//}
//else
//{
// if (HightEff)
// {
// if (value == 0)
// {
// this.InputColor = ColorStr.Gray;
// }
// else if (value >= 0)
// {
// this.InputColor = ColorStr.Green;
// }
// }
// else
// {
// if (value == 1)
// {
// this.InputColor = ColorStr.Gray;
// }
// else if (value >= 0)
// {
// this.InputColor = ColorStr.Green;
// }else
// {
// this.InputColor = ColorStr.Red;
// }
// }
//}
levelState = value;
if (g_handle == (IntPtr)0)
{
if (HightEff)
{
if (value == 1)
{
this.InputColor = ColorStr.Gray;
}
else
{
this.InputColor = ColorStr.Green;
}
}
else
{
if (value == 0)
{
this.InputColor = ColorStr.Gray;
}
else
{
this.InputColor = ColorStr.Green;
}
}
}
else
{
if (HightEff)
{
if (value == 1)
{
this.InputColor = ColorStr.Green;
}
else
{
this.InputColor = ColorStr.Gray;
}
}
else
{
if (value == 0)
{
this.InputColor = ColorStr.Green;
}
else
{
this.InputColor = ColorStr.Gray;
}
}
}
}
}
/// <summary>
/// 输入信号的含义
/// </summary>
public string InputMeaning { get; set; }
/// <summary>
/// 是否属于运动控制卡
/// </summary>
public bool ToRunControlCard { get; set; }
/// <summary>
/// 空信号
/// </summary>
public bool EmptySignal { get; set; }
private string inputColor;
/// <summary>
/// 表示显色
/// </summary>
public string InputColor
{
get { return inputColor; }
set
{
inputColor = value;
LightUp = value == ColorStr.Green ? true : false;
this.RaisePropertyChanged("InputColor");
}
}
/// <summary>
/// 信号是否点亮
/// </summary>
public bool LightUp { get; set; }
/// <summary>
/// 高电平有效
/// </summary>
public bool HightEff { get; set; }
public InputSignal()
{
LevelState = 0;
ToRunControlCard = false;
}
/// <summary>
/// 获取输入电平状态
/// </summary>
public void GetInputLever()
{
if (this.ToRunControlCard)
{
//获取运动控制卡输入电平
//LevelState = LTDMC.dmc_read_inbit(CardID, IoNumber);
//LevelState = LTSMC.smc_read_inbit(CardID, IoNumber);
//if (MyCard != null)
//{
// //确认运动控制的品牌
// switch (MyCard.Brand)
// {
// case 1:
// //根据品牌的不同,选择相应的状态获取方式
// if (MyCard.InterfaceType == 2)
// {
// LevelState = LTSMC.smc_read_inbit(MyCard.CardID, IoNumber);
// }
// else
// {
// LevelState = LTSMC.smc_read_inbit(MyCard.CardID, IoNumber);
// }
// break;
// case 2:
// if (MyCard.InterfaceType == 2)
// {
// uint state = 0;
// zmcaux.ZAux_Direct_GetIn(MyCard.g_handle, IoNumber, ref state);
// LevelState = Convert.ToInt32(state);
// }
// else
// {
// int state = 100;
// ADTMC.adt_read_inbit(MyCard.CardID, IoNumber, out state);
// LevelState = state;
// }
// break;
// }
//}
if (MS_MB_API.Connect())
{
LevelState = MS_MB_API.Inputs[IoNumber];
}
else
{
LevelState = 0;
}
}
else
{
//获取独立IO卡输入电平
// LevelState = IOC0640.ioc_read_inbit(CardID, IoNumber);
//众为兴的沙雕IO卡
LevelState = adtIO3224.adtIO3224_read_bit(CardID, IoNumber);
}
}
/// <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;
}
}
}