135 lines
3.8 KiB
C#
135 lines
3.8 KiB
C#
using Community;
|
||
using Model;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.Linq;
|
||
using System.Text.RegularExpressions;
|
||
using System.Windows;
|
||
using System.Windows.Controls;
|
||
using System.Windows.Input;
|
||
using Model.MotionControl;
|
||
|
||
|
||
namespace ViewModel
|
||
{
|
||
/// <summary>
|
||
/// 帮助类
|
||
/// </summary>
|
||
public class HelperTxp
|
||
{
|
||
#region 屏蔽非法输入
|
||
/// <summary>
|
||
/// 屏蔽非法输入
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
public static void ShieldingIllegalInput(object sender, TextCompositionEventArgs e)
|
||
{
|
||
TextBox tet = sender as TextBox;
|
||
Regex re = new Regex("[^0-9.]+");
|
||
if (tet.Text.Contains(".") && e.Text == ".")
|
||
{
|
||
e.Handled = true;
|
||
return;
|
||
}
|
||
e.Handled = re.IsMatch(e.Text);
|
||
|
||
}
|
||
#endregion
|
||
|
||
#region 获取控制卡集合 +List<CardClass> GetCardList()
|
||
/// <summary>
|
||
/// 获取控制卡集合
|
||
/// </summary>
|
||
public static List<LeiSaiCard> GetCardList()
|
||
{
|
||
try
|
||
{
|
||
//控制卡集合
|
||
List<LeiSaiCard> cardList = new List<LeiSaiCard>();
|
||
|
||
short num = LTDMC.dmc_board_init(); //初始化控制卡 使用与DMC3800等控制卡
|
||
|
||
if (num > 8 || num < 0)
|
||
{
|
||
MessageBox.Show("初始卡失败", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
|
||
return null;
|
||
}
|
||
else if (num == 0)
|
||
{
|
||
MessageBox.Show("有两张控制卡的硬件设置卡号相同", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
|
||
return null;
|
||
}
|
||
|
||
ushort _num = 0; //初始化成功的卡数
|
||
ushort[] cardids = new ushort[8];// 卡固件类型数组
|
||
uint[] cardtypes = new uint[8]; //卡ID数组
|
||
short res = LTDMC.dmc_get_CardInfList(ref _num, cardtypes, cardids); //读取卡信息,读取成功返回0
|
||
|
||
if (res != 0)
|
||
{
|
||
MessageBox.Show("获取卡信息失败!~");
|
||
return null;
|
||
}
|
||
|
||
//产生卡对象实体集合
|
||
for (int i = 0; i < cardtypes.Count(); i++)
|
||
{
|
||
if (cardtypes[i] != 0)
|
||
{
|
||
LeiSaiCard card = new LeiSaiCard();
|
||
card.CardID = cardids[i];
|
||
card.GetCradInfo(); //初始卡信息
|
||
cardList.Add(card);
|
||
|
||
}
|
||
}
|
||
|
||
return cardList;
|
||
}
|
||
catch (Exception)
|
||
{
|
||
|
||
return null;
|
||
}
|
||
|
||
}
|
||
#endregion
|
||
|
||
#region 获取IO卡集合
|
||
/// <summary>
|
||
/// 获取IO卡集合
|
||
/// </summary>
|
||
public static List<ushort> GetIoCard()
|
||
{
|
||
try
|
||
{
|
||
List<ushort> list = new List<ushort>();
|
||
int nCard = 0;
|
||
nCard = IOC0640.ioc_board_init();
|
||
if (nCard <= 0)//控制卡初始化
|
||
{
|
||
MessageBox.Show("未找到IO控制卡!", "警告");
|
||
return null;
|
||
}
|
||
else
|
||
{
|
||
for (int i = 0; i < nCard; i++)
|
||
{
|
||
list.Add(decimal.ToUInt16(i));
|
||
}
|
||
return list;
|
||
}
|
||
}
|
||
catch (Exception)
|
||
{
|
||
|
||
return null;
|
||
}
|
||
|
||
}
|
||
#endregion
|
||
|
||
}
|
||
}
|