wenxiangchao
4 天以前 559890c482f5973f06aafdfec9550fee5ba3c7f2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
<UserControl x:Class="Plugin.DeviceDebug.Panels.PlcDebugPanel"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:ui="clr-namespace:HMI.UI;assembly=HMI.UI"
             xmlns:dp="clr-namespace:HMI.UI.DpUtil;assembly=HMI.UI"
             mc:Ignorable="d" 
             d:DesignHeight="500" d:DesignWidth="600">
    <UserControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="/HMI.UI;component/Style/PanuonListView.xaml"/>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </UserControl.Resources>
 
    <Grid dp:GridHelper.Space="12" Margin="12">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
 
        <!-- 标题 -->
        <Border Grid.Row="0" Background="#9C27B0" CornerRadius="4" Padding="12,8">
            <TextBlock Text="PLC 调试面板" FontSize="16" FontWeight="Bold" Foreground="White"/>
        </Border>
 
        <!-- IO 控制区 -->
        <Border Grid.Row="1" BorderBrush="#DDD" BorderThickness="1" CornerRadius="4" Padding="12">
            <Grid dp:GridHelper.Space="10">
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="80"/>
                    <ColumnDefinition Width="*"/>
                </Grid.ColumnDefinitions>
 
                <!-- 地址 -->
                <TextBlock Grid.Row="0" Grid.Column="0" Text="地址:" VerticalAlignment="Center" FontWeight="Bold"/>
                <TextBox Grid.Row="0" Grid.Column="1" x:Name="addressInput"
                         IsEnabled="{Binding IsMaintenanceMode, RelativeSource={RelativeSource AncestorType=UserControl}}"
                         VerticalContentAlignment="Center" Padding="6,4" Text="M0.0"/>
 
                <!-- 值 -->
                <TextBlock Grid.Row="1" Grid.Column="0" Text="值:" VerticalAlignment="Center" FontWeight="Bold"/>
                <ComboBox Grid.Row="1" Grid.Column="1" x:Name="valueSelect"
                          IsEnabled="{Binding IsMaintenanceMode, RelativeSource={RelativeSource AncestorType=UserControl}}"
                          VerticalContentAlignment="Center" Padding="6,4">
                    <ComboBoxItem Content="True" IsSelected="True"/>
                    <ComboBoxItem Content="False"/>
                </ComboBox>
 
                <!-- 写入按钮 -->
                <Button Grid.Row="2" Grid.ColumnSpan="2" x:Name="writeBtn" Content="写入" Padding="20,6"
                        IsEnabled="{Binding IsMaintenanceMode, RelativeSource={RelativeSource AncestorType=UserControl}}"
                        Click="WriteBtn_Click" HorizontalAlignment="Left"
                        Background="#9C27B0" Foreground="White" BorderThickness="0" Cursor="Hand"/>
            </Grid>
        </Border>
 
        <!-- IO 状态显示区 -->
        <Border Grid.Row="2" BorderBrush="#DDD" BorderThickness="1" CornerRadius="4">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                </Grid.RowDefinitions>
 
                <Border Grid.Row="0" Background="#F5F5F5" Padding="8,6">
                    <TextBlock Text="IO 点位状态" FontWeight="Bold" FontSize="14"/>
                </Border>
 
                <ListView Grid.Row="1" x:Name="ioStatusList" Height="180"
                          Style="{StaticResource DefaultListTable}"
                          VirtualizingPanel.IsVirtualizing="True"
                          VirtualizingPanel.VirtualizationMode="Standard">
                    <ListView.View>
                        <GridView AllowsColumnReorder="False">
                            <GridViewColumn Width="120" Header="地址">
                                <GridViewColumn.CellTemplate>
                                    <DataTemplate>
                                        <Border Style="{StaticResource CellBorder}">
                                            <TextBlock Style="{StaticResource ListTableTextBlock}" 
                                                       Text="{Binding Address}" FontFamily="Consolas"/>
                                        </Border>
                                    </DataTemplate>
                                </GridViewColumn.CellTemplate>
                            </GridViewColumn>
                            <GridViewColumn Width="80" Header="值">
                                <GridViewColumn.CellTemplate>
                                    <DataTemplate>
                                        <Border Style="{StaticResource CellBorder}">
                                            <TextBlock Text="{Binding Value}">
                                                <TextBlock.Style>
                                                    <Style TargetType="TextBlock" BasedOn="{StaticResource ListTableTextBlock}">
                                                        <Style.Triggers>
                                                            <DataTrigger Binding="{Binding Value}" Value="True">
                                                                <Setter Property="Foreground" Value="#4CAF50"/>
                                                                <Setter Property="FontWeight" Value="Bold"/>
                                                            </DataTrigger>
                                                            <DataTrigger Binding="{Binding Value}" Value="False">
                                                                <Setter Property="Foreground" Value="#999"/>
                                                            </DataTrigger>
                                                        </Style.Triggers>
                                                    </Style>
                                                </TextBlock.Style>
                                            </TextBlock>
                                        </Border>
                                    </DataTemplate>
                                </GridViewColumn.CellTemplate>
                            </GridViewColumn>
                            <GridViewColumn Width="150" Header="更新时间">
                                <GridViewColumn.CellTemplate>
                                    <DataTemplate>
                                        <Border Style="{StaticResource CellBorder}">
                                            <TextBlock Style="{StaticResource ListTableTextBlock}" 
                                                       Text="{Binding LastUpdate, StringFormat=HH:mm:ss}"/>
                                        </Border>
                                    </DataTemplate>
                                </GridViewColumn.CellTemplate>
                            </GridViewColumn>
                        </GridView>
                    </ListView.View>
                </ListView>
            </Grid>
        </Border>
 
        <!-- 互锁状态区 -->
        <Border Grid.Row="3" BorderBrush="#DDD" BorderThickness="1" CornerRadius="4">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="*"/>
                </Grid.RowDefinitions>
 
                <Border Grid.Row="0" Background="#FFF3E0" Padding="8,6">
                    <TextBlock Text="互锁状态" FontWeight="Bold" FontSize="14" Foreground="#E65100"/>
                </Border>
 
                <ScrollViewer Grid.Row="1" VerticalScrollBarVisibility="Auto">
                    <ItemsControl x:Name="interlockList" Margin="8">
                        <ItemsControl.ItemTemplate>
                            <DataTemplate>
                                <Border BorderBrush="#EEE" BorderThickness="0,0,0,1" Padding="4,6">
                                    <StackPanel Orientation="Horizontal">
                                        <TextBlock Text="{Binding Name}" FontWeight="Bold" Width="150"/>
                                        <TextBlock Text="{Binding Status}" Margin="10,0,0,0">
                                            <TextBlock.Style>
                                                <Style TargetType="TextBlock">
                                                    <Style.Triggers>
                                                        <DataTrigger Binding="{Binding Status}" Value="满足">
                                                            <Setter Property="Foreground" Value="#4CAF50"/>
                                                        </DataTrigger>
                                                        <DataTrigger Binding="{Binding Status}" Value="不满足">
                                                            <Setter Property="Foreground" Value="#F44336"/>
                                                        </DataTrigger>
                                                    </Style.Triggers>
                                                </Style>
                                            </TextBlock.Style>
                                        </TextBlock>
                                    </StackPanel>
                                </Border>
                            </DataTemplate>
                        </ItemsControl.ItemTemplate>
                    </ItemsControl>
                </ScrollViewer>
            </Grid>
        </Border>
    </Grid>
</UserControl>