首页 > 其他分享 >WPF上位机 - 使用转换器实现TIA Wincc中的文本列表功能

WPF上位机 - 使用转换器实现TIA Wincc中的文本列表功能

时间:2024-05-03 19:44:46浏览次数:26  
标签:ERR MC INVALID Wincc STATE using WPF TIA UNDEFINED

TIA wincc中可以根据变量的值,显示出定义的文本。

在WPF中可以通过转换器实现。

使用哈希表存储变量和文本,根据变量值返回对应的文本显示在View 中


using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;

namespace SiemensAxisControl.Model.Converter
{
    internal class StringToStatusConverter : IValueConverter
    {
        private static readonly Dictionary<string, string> StatusDic = new Dictionary<string, string>()
        {
            {"7000", "STATUS_NO_CALL" },
            {"7001", "STATUS_FB_FIRST_CALL" },
            {"7002", "STATUS_SUBSEQUENT_CALL" },
            {"8001", "ERR_INVALID_BASIC_MOTION_CMD" },
            {"8002", "ERR_INVALID_EXTENDED_CMD" },
            {"8200", "ERR_INVALID_CAM" },
            {"8201", "ERR_INVALID_JOG_MODE" },
            {"8202", "ERR_INVALID_HOMING_EXTENDED_MODE" },
            {"8203", "ERR_TORQUE_LIMITING_NOT_ALLOWED" },
            {"8204", "ERR_INVALID_JOG_DIR" },
            {"8205", "ERR_INVALID_POS_RELATIVE_DIR" },
            {"8206", "ERR_INVALID_POS_SUPERIMPOSED_DIR" },
            {"8207", "ERR_HOMING_MODE_NOT_ALLOWED" },
            {"8208", "ERR_MODULO_NOT_ALLOWED" },
            {"8209", "ERR_INVALID_TORQUE_LIMIT" },
            {"8210", "ERR_INVALID_VELOCITY" },
            {"8600", "ERR_MC_POWER" },
            {"8601", "ERR_MC_RESET" },
            {"8602", "ERR_MC_HOME" },
            {"8603", "ERR_MC_TORQUELIMITING" },
            {"8604", "ERR_MC_HALT" },
            {"8605", "ERR_MC_MOVEJOG" },
            {"8606", "ERR_MC_MOVEVELOCITY" },
            {"8607", "ERR_MC_MOVERELATIVE" },
            {"8608", "ERR_MC_MOVEABSOLUTE" },
            {"8609", "ERR_MC_MOVESUPERIMPOSED" },
            {"860A", "ERR_MC_GEARIN" },
            {"860B", "ERR_MC_PHASINGABSOLUTE"},
            {"860C", "ERR_MC_PHASINGRELATIVE" },
            {"860D", "ERR_MC_CAMIN" },
            {"860E", "ERR_MC_GEARINPOS" },
            {"860F", "ERR_MC_SYNCHRONIZEDMOTIONSIMULATION" },
            {"8700", "ERR_UNDEFINED_FB_STATE" },
            {"8701", "ERR_UNDEFINED_RESET_STATE" },
            {"8702", "ERR_UNDEFINED_BASIC_MOTION_STATE" },
            {"8703", "ERR_UNDEFINED_TORQUE_LIMITING_STATE" },
            {"8704", "ERR_UNDEFINED_INCREMENTAL_JOG_STATE" },
            {"8705", "ERR_UNDEFINED_INCREMENTAL_JOG_SUBSTATE" },
            {"8706", "ERR_UNDEFINED_EXTENDED_HOMING_STATE" },
            {"8707", "ERR_UNDEFINED_EXTENDED_HOMING_SUBSTATE" },
            {"8708", "ERR_UNDEFINED_SUPERIMPOSED_MOTION_STATE" },
            {"8709", "ERR_UNDEFINED_MOTION_SIMULATION_STATE" },
            {"8710", "ERR_UNDEFINED_MAIN_SELECTION_STATE" }
        };
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            string Status = "Last Command Ok";
            // 检查传入的值是否在指定的范围内
            if (value is string key)
            {

                if (StatusDic.ContainsKey(key))
                {
                    Status = StatusDic[key];
                }
            }

            return Status;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}

标签:ERR,MC,INVALID,Wincc,STATE,using,WPF,TIA,UNDEFINED
From: https://www.cnblogs.com/Tristan998/p/18171527

相关文章

  • WPF上位机 - 使用转换器实现TIA Wincc中的位控制可见性或外观功能
    在TIAWincc中有这样的功能,使用Trueorfalse控制控件的可见性或者外观的情况。在上位机中需要使用转换器这样对Trueorfalse值转换为需要的笔刷或者Visible属性。usingSystem;usingSystem.Collections.Generic;usingSystem.Globalization;usingSystem.Linq;using......
  • WPF上位机 - S7.NETPlus批量读取数据
    在编写上位机程序中,需要读取PLC数据。使用到了S7.NETPlus这个库。S7.NETPlus提供了很多读取和写入数据的方式。大批量读取数据的方式包括一下几个方法ReadbytesReadClassReadStructReadMultipleVarsPLC侧的数据是一个Array的UDT数据,其中UDT中还包含了很多的UDT。在使用库......
  • WPF上位机 - 轴运动控制
    最近学习WPF,写了一个WPF上位机使用S7.NETPlus库与西门子1500TPLC,控制西门子伺服的通用上位机界面。分享在写上位机过程中踩的一些坑和使用体验。上位机介绍可以看到上位机分为3个区域轴选择,使能区域控制参数设置区域诊断区域选择使能区域选择区域读取TIA中组态的轴工艺......
  • WPF TreeView HierarchicalDataTemplate
    //xaml<Windowx:Class="WpfApp87.MainWindow"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:d="http://schemas.mic......
  • WPF Text MultiBinding StringFormat
    <TextBlock.Text><MultiBindingStringFormat="R:{0:N0},G:{1:N0},B:{2:N0}"><BindingPath="Value"ElementName="_red"/><BindingPath="Value"ElementName="_green"/>......
  • WPF MultiBinding
    <Windowx:Class="WpfApp84.MainWindow"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:d="http://schemas.microsoft.......
  • WPF Slider Show integral value TickFrequency="1" IsSnapToTickEnabled="True"
    <Windowx:Class="WpfApp85.MainWindow"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:d="http://schemas.microsoft.......
  • WPF CollectionViewSource GroupDescriptions GroupStyle ItemsPanelTemplate
    <Windowx:Class="WpfApp83.MainWindow"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:d="http://schemas.microsoft.......
  • WPF CollectionViewSource GroupDescriptions PropertyGroupDescription GroupStyle
    <Windowx:Class="WpfApp83.MainWindow"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:d="http://schemas.microsoft.......
  • WPF CollectionViewSource ICollectionViewLiveShaping IsLiveSorting
    <Windowx:Class="WpfApp82.MainWindow"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:d="http://schemas.microsoft.......