Browse Source

调整一些配置方式

djs 2 months ago
parent
commit
7803205e8a
3 changed files with 976 additions and 56 deletions
  1. 292 2
      MV485/helper/RWRunConfig.cs
  2. 93 43
      MV485/uc/UCRunConfig.xaml
  3. 591 11
      MV485/uc/UCRunConfig.xaml.cs

+ 292 - 2
MV485/helper/RWRunConfig.cs

@@ -47,7 +47,8 @@ namespace MV485.helper
 
         }
 
-        public RunConfig ReadRunConfig(string portName, int baudrate, byte devId)
+        //cfgType 1:AI参数;2:图像参数; 3:采样时间参数
+        public RunConfig ReadRunConfig(string portName, int baudrate, byte devId,int cfgType)
         {
             RunConfig runConfig = null;
             _portName = portName;
@@ -55,12 +56,301 @@ namespace MV485.helper
             _address = devId;
             if (OpenSerial(portName, baudrate))
             {
-                runConfig = GetRunConfig(devId);
+                if (cfgType == 1)
+                {
+                    runConfig = GetAIConfig(devId);
+                }
+                else if (cfgType == 2)
+                {
+                    runConfig = GetRegionConfig(devId);
+                }
+                else if (cfgType == 3)
+                {
+                    runConfig = GetSampleConfig(devId);
+                }
+                else
+                {
+                    runConfig = GetRunConfig(devId);
+                }
             }
             CloseSerial();
             return runConfig;
         }
 
+        private RunConfig GetAIConfig(byte devId)
+        {
+            string readName = "";
+            try
+            {
+                RunConfig runConfig = new RunConfig();
+
+                ushort[] readRegisters;
+
+                readName = "水表类型";
+                readRegisters = _modbusMaster.ReadHoldingRegisters(devId,
+                    Constant.MB_REGISTER_ADD_METER_TYPE, Constant.MB_REGISTER_NUM_METER_TYPE);
+                byte meterType = (byte)(readRegisters[0] & 0xFF);
+                runConfig.MeterTypeWRFlag = true;
+                runConfig.MeterType = meterType;
+                GenerateSendAndRecvHexLog(true, readName);
+                _message = $"{readName}: {meterType}";
+                RWLog?.Invoke(_message);
+
+                readName = "每小时最大流量";
+                readRegisters = _modbusMaster.ReadHoldingRegisters(devId,
+                    Constant.MB_REGISTER_ADD_DN_VALUE, Constant.MB_REGISTER_NUM_DN_VALUE);
+                ushort dnValue = readRegisters[0];
+                runConfig.DnValueWRFlag = true;
+                runConfig.DnValue = dnValue;
+                GenerateSendAndRecvHexLog(true, readName);
+                _message = $"{readName}: {dnValue}";
+                RWLog?.Invoke(_message);
+
+                if (meterType == Constant.METER_TYPE_NUM_IND || meterType == Constant.METER_TYPE_NUM)
+                {
+                    readName = "数字个数";
+                    readRegisters = _modbusMaster.ReadHoldingRegisters(devId,
+                        Constant.MB_REGISTER_ADD_DIGIT_COUNT, Constant.MB_REGISTER_NUM_DIGIT_COUNT);
+                    byte digitCount = (byte)(readRegisters[0] & 0xFF);
+                    runConfig.DigitCountWRFlag = true;
+                    runConfig.DigitCount = digitCount;
+                    GenerateSendAndRecvHexLog(true, readName);
+                    GenerateValueLog(readName, digitCount);
+                }
+
+                if (meterType == Constant.METER_TYPE_NUM_IND || meterType == Constant.METER_TYPE_IND)
+                {
+                    readName = "指针个数";
+                    readRegisters = _modbusMaster.ReadHoldingRegisters(devId,
+                        Constant.MB_REGISTER_ADD_INDICATOR_COUNT, Constant.MB_REGISTER_NUM_INDICATOR_COUNT);
+                    byte indCount = (byte)(readRegisters[0] & 0xFF);
+                    runConfig.IndCountWRFlag = true;
+                    runConfig.IndCount = indCount;
+                    GenerateSendAndRecvHexLog(true, readName);
+                    GenerateValueLog(readName, indCount);
+                }
+
+                //此项已经不需要了
+                /*readName = "照片亮度放大倍率";
+                readRegisters = _modbusMaster.ReadHoldingRegisters(devId,
+                    Constant.MB_REGISTER_ADD_BRIGHT_VALUE, Constant.MB_REGISTER_NUM_BRIGHT_VALUE);
+                byte birghtValue = (byte)(readRegisters[0] & 0xFF);  // 10f;
+                runConfig.BrightValueWRFlag = true;
+                runConfig.BrightValue = birghtValue / 10f;
+                GenerateSendAndRecvHexLog(true, readName);
+                GenerateValueLog(readName, birghtValue);*/
+
+                readName = "尾数单位等级";
+                readRegisters = _modbusMaster.ReadHoldingRegisters(devId,
+                    Constant.MB_REGISTER_ADD_LAST_UNIT_LEVEL, Constant.MB_REGISTER_NUM_LAST_UNIT_LEVEL);
+                byte lastUnitLevel = (byte)(readRegisters[0] & 0xFF);
+                runConfig.LastUnitLevelWRFlag = true;
+                runConfig.LastUnitLevel = lastUnitLevel;
+                GenerateSendAndRecvHexLog(true, readName);
+                GenerateValueLog(readName, lastUnitLevel);
+
+                readName = "上传红色指针读数";
+                readRegisters = _modbusMaster.ReadHoldingRegisters(devId,
+                    Constant.MB_REGISTER_ADD_UPLOAD_REDIND, Constant.MB_REGISTER_NUM_UPLOAD_REDIND);
+                byte uploadRedind = (byte)(readRegisters[0] & 0xFF);
+                runConfig.UploadRedindWRFlag = true;
+                runConfig.UploadRedind = uploadRedind;
+                GenerateSendAndRecvHexLog(true, readName);
+                GenerateValueLog(readName, uploadRedind);
+
+                readName = "表底读数";
+                readRegisters = _modbusMaster.ReadHoldingRegisters(devId,
+                    Constant.MB_REGISTER_ADD_LATEST_VALUE, Constant.MB_REGISTER_NUM_LATEST_VALUE);
+                //4个寄存器
+                ulong latestValue = ((ulong)readRegisters[0] << 48) | ((ulong)readRegisters[1] << 32) |
+                    ((ulong)readRegisters[2] << 16) | readRegisters[3];
+                runConfig.LatestValueWRFlag = true;
+                runConfig.LatestValue = latestValue;
+                GenerateSendAndRecvHexLog(true, readName);
+                GenerateValueLog(readName, latestValue);
+
+                readName = "表底读数时间";
+                readRegisters = _modbusMaster.ReadHoldingRegisters(devId,
+                    Constant.MB_REGISTER_ADD_LATEST_TIME, Constant.MB_REGISTER_NUM_LATEST_TIME);
+                //6个寄存器
+                int year = (byte)(readRegisters[0] & 0xFF);
+                int month = (byte)(readRegisters[1] & 0xFF);
+                int day = (byte)(readRegisters[2] & 0xFF);
+                int hour = (byte)(readRegisters[3] & 0xFF);
+                int minute = (byte)(readRegisters[4] & 0xFF);
+                int second = (byte)(readRegisters[5] & 0xFF);
+                //DateTime dtLatestTime = new DateTime(2000 + year, month, day, hour, minute, second);
+                //string latestTime = dtLatestTime.ToString("yyyy-MM-dd HH:mm:ss");
+                string latestTime = $"{2000 + year}-{month.ToString("D2")}-{day.ToString("D2")} " +
+                    $"{hour.ToString("D2")}:{minute.ToString("D2")}:{second.ToString("D2")}";
+                if (DateTime.TryParse(latestTime, out DateTime dtLatestTime))
+                {
+                    runConfig.LatestTimeWRFlag = true;
+                    runConfig.LatestTime = dtLatestTime;
+                }
+                GenerateSendAndRecvHexLog(true, readName);
+                GenerateValueLog(readName, latestTime);
+           
+                return runConfig;
+            }
+            catch (TimeoutException ex)
+            {
+                GenerateSendHexLog(readName);
+                _message = $"读取{readName}超时,{ex.Message}";
+                RWLog?.Invoke(_message);
+                return null;
+            }
+            catch (SlaveException ex)
+            {
+                GenerateSendHexLog(readName);
+                _message = $"读取{readName}Modbus错误,{ex.Message}";
+                RWLog?.Invoke(_message);
+                return null;
+            }
+            catch (Exception ex)
+            {
+                GenerateSendHexLog(readName);
+                _message = $"读取{readName}错误,{ex.Message}";
+                RWLog?.Invoke(_message);
+                return null;
+            }
+        }
+
+        private RunConfig GetRegionConfig(byte devId)
+        {
+            string readName = "";
+            try
+            {
+                RunConfig runConfig = new RunConfig();
+
+                ushort[] readRegisters;
+
+                readName = "水表类型";
+                readRegisters = _modbusMaster.ReadHoldingRegisters(devId,
+                    Constant.MB_REGISTER_ADD_METER_TYPE, Constant.MB_REGISTER_NUM_METER_TYPE);
+                byte meterType = (byte)(readRegisters[0] & 0xFF);
+                runConfig.MeterTypeWRFlag = true;
+                runConfig.MeterType = meterType;
+                GenerateSendAndRecvHexLog(true, readName);
+                _message = $"{readName}: {meterType}";
+                RWLog?.Invoke(_message);
+
+                readName = "表盘区域坐标";
+                readRegisters = _modbusMaster.ReadHoldingRegisters(devId,
+                    Constant.MB_REGISTER_ADD_METER_REGION, Constant.MB_REGISTER_NUM_METER_REGION);
+                //4个寄存器
+                string meterRegion = $"{readRegisters[0]},{readRegisters[1]} {readRegisters[2]},{readRegisters[3]}";
+                runConfig.MeterRegionWRFlag = true;
+                runConfig.MeterRegion = meterRegion;
+                GenerateSendAndRecvHexLog(true, readName);
+                GenerateValueLog(readName, meterRegion);
+
+
+                if (meterType == Constant.METER_TYPE_NUM_IND || meterType == Constant.METER_TYPE_NUM)
+                {
+                    readName = "数字区域坐标";
+                    readRegisters = _modbusMaster.ReadHoldingRegisters(devId,
+                        Constant.MB_REGISTER_ADD_DIGIT_REGION, Constant.MB_REGISTER_NUM_DIGIT_REGION);
+                    //8个寄存器
+                    string digitRegion = $"{readRegisters[0]},{readRegisters[1]} {readRegisters[2]},{readRegisters[3]} " +
+                        $"{readRegisters[4]},{readRegisters[5]} {readRegisters[6]},{readRegisters[7]}";
+                    runConfig.DigitRegionWRFlag = true;
+                    runConfig.DigitRegion = digitRegion;
+                    GenerateSendAndRecvHexLog(true, readName);
+                    GenerateValueLog(readName, digitRegion);
+                }
+
+                if (meterType == Constant.METER_TYPE_IND)
+                {
+                    readName = "首尾指针坐标";
+                    readRegisters = _modbusMaster.ReadHoldingRegisters(devId,
+                        Constant.MB_REGISTER_ADD_FTIND_REGION, Constant.MB_REGISTER_NUM_FTIND_REGION);
+                    //4个寄存器
+                    string ftIndRegion = $"{readRegisters[0]},{readRegisters[1]} {readRegisters[2]},{readRegisters[3]}";
+                    runConfig.FTIndRegionWRFlag = true;
+                    runConfig.FTIndRegion = ftIndRegion;
+                    GenerateSendAndRecvHexLog(true, readName);
+                    GenerateValueLog(readName, ftIndRegion);
+                }
+
+                return runConfig;
+            }
+            catch (TimeoutException ex)
+            {
+                GenerateSendHexLog(readName);
+                _message = $"读取{readName}超时,{ex.Message}";
+                RWLog?.Invoke(_message);
+                return null;
+            }
+            catch (SlaveException ex)
+            {
+                GenerateSendHexLog(readName);
+                _message = $"读取{readName}Modbus错误,{ex.Message}";
+                RWLog?.Invoke(_message);
+                return null;
+            }
+            catch (Exception ex)
+            {
+                GenerateSendHexLog(readName);
+                _message = $"读取{readName}错误,{ex.Message}";
+                RWLog?.Invoke(_message);
+                return null;
+            }
+        }
+
+        private RunConfig GetSampleConfig(byte devId)
+        {
+            string readName = "";
+            try
+            {
+                RunConfig runConfig = new RunConfig();
+
+                ushort[] readRegisters;
+
+                readName = "采样识别时间间隔(分)";
+                readRegisters = _modbusMaster.ReadHoldingRegisters(devId,
+                    Constant.MB_REGISTER_ADD_SAMPLE_INTERVAL, Constant.MB_REGISTER_NUM_SAMPLE_INTERVAL);
+                ushort sampleInterval = readRegisters[0];
+                runConfig.SampleIntervalFlag = true;
+                runConfig.SampleInterval = sampleInterval;
+                GenerateSendAndRecvHexLog(true, readName);
+                GenerateValueLog(readName, sampleInterval);
+
+                readName = "首次采样整点小时";
+                readRegisters = _modbusMaster.ReadHoldingRegisters(devId,
+                    Constant.MB_REGISTER_ADD_SAMPLE_FIRST_HOUR, Constant.MB_REGISTER_NUM_SAMPLE_FIRST_HOUR);
+                byte firstHour = (byte)(readRegisters[0] & 0xFF);
+                runConfig.FirstHourFlag = true;
+                runConfig.FirstHour = firstHour;
+                GenerateSendAndRecvHexLog(true, readName);
+                GenerateValueLog(readName, firstHour);
+
+                return runConfig;
+            }
+            catch (TimeoutException ex)
+            {
+                GenerateSendHexLog(readName);
+                _message = $"读取{readName}超时,{ex.Message}";
+                RWLog?.Invoke(_message);
+                return null;
+            }
+            catch (SlaveException ex)
+            {
+                GenerateSendHexLog(readName);
+                _message = $"读取{readName}Modbus错误,{ex.Message}";
+                RWLog?.Invoke(_message);
+                return null;
+            }
+            catch (Exception ex)
+            {
+                GenerateSendHexLog(readName);
+                _message = $"读取{readName}错误,{ex.Message}";
+                RWLog?.Invoke(_message);
+                return null;
+            }
+        }
+
+
         private RunConfig GetRunConfig(byte devId)
         {
             string readName = "";

+ 93 - 43
MV485/uc/UCRunConfig.xaml

@@ -177,14 +177,14 @@
                 <ScrollViewer Grid.Column="1" VerticalScrollBarVisibility="Auto">
                     <Border Grid.Column="1" BorderBrush="DarkGray" BorderThickness="0 0 1 0" Background="White" Padding="5 0 0 0">
                         <StackPanel Orientation="Vertical" Margin="0 0 0 0">
-                            <Grid Height="35" Margin="10 0 10 0">
+                            <Grid Height="30" Margin="10 0 10 0">
                                 <StackPanel Orientation="Horizontal">
-                                    <TextBlock Text="抄表器运行参数: " FontSize="14" FontWeight="Bold"
+                                    <TextBlock Text="抄表器AI基本参数(必须配置): " FontSize="14" FontWeight="Bold"
                                                VerticalAlignment="Center" Foreground="DarkBlue" />
                                     <!--<TextBlock Text="设置参数后,抄表器需要重启,请等待1-2分钟" VerticalAlignment="Center" Foreground="Red" />-->
                                 </StackPanel>
                             </Grid>
-                            <Grid Height="50" Margin="10 0 10 0">
+                            <Grid Height="40" Margin="10 0 10 0">
                                 <Grid.ColumnDefinitions>
                                     <ColumnDefinition Width="90" />
                                     <ColumnDefinition Width="*" />
@@ -203,7 +203,7 @@
                                             Height="20" Width="60" Background="Transparent" Foreground="Blue" FontSize="14" />
                             </Grid>
 
-                            <Grid Height="50" Margin="10 0 10 0">
+                            <Grid Height="40" Margin="10 0 10 0">
                                 <Grid.ColumnDefinitions>
                                     <ColumnDefinition Width="90" />
                                     <ColumnDefinition Width="*" />
@@ -224,7 +224,7 @@
                                             Height="20" Width="60" Background="Transparent" Foreground="Blue" FontSize="14" />
                             </Grid>
 
-                            <Grid Height="50" Margin="10 0 10 0" x:Name="grdNumCount">
+                            <Grid Height="40" Margin="10 0 10 0" x:Name="grdNumCount">
                                 <Grid.ColumnDefinitions>
                                     <ColumnDefinition Width="90" />
                                     <ColumnDefinition Width="*" />
@@ -240,7 +240,7 @@
                                             Height="20" Width="60" Background="Transparent" Foreground="Blue" FontSize="14" />
                             </Grid>
 
-                            <Grid Height="50" Margin="10 0 10 0" x:Name="grdIndCount">
+                            <Grid Height="40" Margin="10 0 10 0" x:Name="grdIndCount">
                                 <Grid.ColumnDefinitions>
                                     <ColumnDefinition Width="90" />
                                     <ColumnDefinition Width="*" />
@@ -255,7 +255,7 @@
                                         Grid.Column="2" Content="说明示例" BorderThickness="0 0 0 1" BorderBrush="Blue"
                                             Height="20" Width="60" Background="Transparent" Foreground="Blue" FontSize="14" />
                             </Grid>
-                            <Grid Height="50" Margin="10 0 10 0" Visibility="Collapsed">
+                            <Grid Height="40" Margin="10 0 10 0" Visibility="Collapsed">
                                 <Grid.ColumnDefinitions>
                                     <ColumnDefinition Width="90" />
                                     <ColumnDefinition Width="*" />
@@ -270,7 +270,7 @@
                                             Height="20" Width="60" Background="Transparent" Foreground="Blue" FontSize="14" />
                             </Grid>
 
-                            <Grid Height="50" Margin="10 0 10 0">
+                            <Grid Height="40" Margin="10 0 10 0">
                                 <Grid.ColumnDefinitions>
                                     <ColumnDefinition Width="90" />
                                     <ColumnDefinition Width="*" />
@@ -286,7 +286,7 @@
                                             Height="20" Width="60" Background="Transparent" Foreground="Blue" FontSize="14" />
                             </Grid>
 
-                            <Grid Height="50" Margin="10 0 10 0" x:Name="grdRedInd">
+                            <Grid Height="40" Margin="10 0 10 0" x:Name="grdRedInd">
                                 <Grid.ColumnDefinitions>
                                     <ColumnDefinition Width="90" />
                                     <ColumnDefinition Width="*" />
@@ -302,7 +302,7 @@
                                             Height="20" Width="60" Background="Transparent" Foreground="Blue" FontSize="14" />
                             </Grid>
 
-                            <Grid Height="50" Margin="10 0 10 0">
+                            <Grid Height="40" Margin="10 0 10 0">
                                 <Grid.ColumnDefinitions>
                                     <ColumnDefinition Width="90" />
                                     <ColumnDefinition Width="*" />
@@ -318,7 +318,7 @@
                                             Height="20" Width="60" Background="Transparent" Foreground="Blue" FontSize="14" />
                             </Grid>
 
-                            <Grid Height="50" Margin="10 0 10 0">
+                            <Grid Height="40" Margin="10 0 10 0">
                                 <Grid.ColumnDefinitions>
                                     <ColumnDefinition Width="90" />
                                     <ColumnDefinition Width="*" />
@@ -332,49 +332,85 @@
                                             Height="20" Width="60" Background="Transparent" Foreground="Blue" FontSize="14" />
                             </Grid>
 
-                            <StackPanel Height="1" Background="#D3D3D3" Margin="10 0 10 0" />
-                            <Grid Height="50" Margin="10 0 10 0">
-                                <Grid.RowDefinitions>
-                                    <RowDefinition Height="30" />
-                                    <RowDefinition Height="30" />
-                                </Grid.RowDefinitions>
-                                <Button  x:Name="btnMarkMeter" Click="BtnMarkMeter_Click" 
-                                        Grid.Row="0" Content="根据水表照片标定位置(可选)" BorderThickness="0 0 0 1" BorderBrush="Blue" HorizontalAlignment="Left"
-                                            Height="20"  Background="Transparent" Foreground="Blue" FontSize="14" />
-                                <TextBlock Text="*配置以上参数后,识别结果类型为88时,需要配置。" Foreground="Red" FontSize="13"
+                            <Grid Height="35">
+                                <Grid.ColumnDefinitions>
+                                    <ColumnDefinition Width="*" />
+                                    <ColumnDefinition Width="*" />
+                                </Grid.ColumnDefinitions>
+                                <zdfflatui:FlatButton Grid.Column="0" x:Name="btnReadBasicConfig" Background="#4CAF50" Foreground="White" 
+                                                          Content="读取AI基本参数"  Click="BtnReadBasicConfig_Click" 
+                                                          Height="28" FontSize="14" Margin="10 0 10 0" />
+
+                                <zdfflatui:FlatButton Grid.Column="1" x:Name="btnSetBasicConfig" Background="#2196F3" Foreground="White" 
+                                                          Content="设置AI基本参数"  Click="BtnSetBasicConfig_Click" 
+                                                          Height="28" FontSize="14" Margin="10 0 10 0" />
+                            </Grid>
+
+                            <StackPanel Height="1" Background="DarkGray" Margin="10 5 10 5" />
+                            <Grid Height="30" Margin="10 0 10 0">
+                                <StackPanel Orientation="Horizontal">
+                                    <TextBlock Text="抄表器图像区域参数(可选配置): " FontSize="14" FontWeight="Bold"
+                                               VerticalAlignment="Center" Foreground="DarkBlue" />
+                                    <!--<TextBlock Text="设置参数后,抄表器需要重启,请等待1-2分钟" VerticalAlignment="Center" Foreground="Red" />-->
+                                </StackPanel>
+                            </Grid>
+                            <Grid Height="25" Margin="10 0 10 0">
+                                <TextBlock Text="*配置基本参数后还不能正确识别时,需要配置此项。" Foreground="Red" FontSize="13"
                                            Grid.Row="1"  Margin="0 0 0 0" />
                             </Grid>
 
-                            <Grid Height="50" Margin="10 0 10 0">
+                            <Grid Height="40" Margin="10 0 10 0">
                                 <Grid.ColumnDefinitions>
                                     <ColumnDefinition Width="90" />
                                     <ColumnDefinition Width="*" />
                                     <ColumnDefinition Width="80" />
                                 </Grid.ColumnDefinitions>
-                                <!--<TextBlock Grid.Column="0" Text="表盘范围" VerticalAlignment="Center" FontSize="14" />-->
-                                <CheckBox x:Name="chkMeterRegion" Grid.Column="0" Content="表盘范围" VerticalAlignment="Center" FontSize="14" VerticalContentAlignment="Center" />
+                                <TextBlock Grid.Column="0" Text="表盘范围" VerticalAlignment="Center" FontSize="14" />
+                                <!--<CheckBox x:Name="chkMeterRegion" Grid.Column="0" Content="表盘范围" VerticalAlignment="Center" FontSize="14" VerticalContentAlignment="Center" />-->
                                 <TextBox Grid.Column="1" x:Name="txtMeterRegion" Height="26" Padding="2" FontSize="14px" IsReadOnly="True" />
                                 <Button x:Name="btnMeterRegion" Click="BtnMeterRegion_Click" 
                                         Grid.Column="3" Content="说明示例" BorderThickness="0 0 0 1" BorderBrush="Blue"
                                             Height="20" Width="60" Background="Transparent" Foreground="Blue" FontSize="14" />
                             </Grid>
-                            <Grid Height="50" Margin="10 0 10 0">
+                            <Grid Height="40" Margin="10 0 10 0">
                                 <Grid.ColumnDefinitions>
                                     <ColumnDefinition Width="90" />
                                     <ColumnDefinition Width="*" />
                                     <ColumnDefinition Width="80" />
                                 </Grid.ColumnDefinitions>
                                 <!--<TextBlock x:Name="txtFeatureRegionTitle" Grid.Column="0" Text="数字范围" VerticalAlignment="Center" FontSize="14" TextWrapping="Wrap" />-->
-                                <CheckBox x:Name="chkFeatureRegion" Grid.Column="0"  VerticalAlignment="Center" FontSize="14" VerticalContentAlignment="Center">
+                                <!--<CheckBox x:Name="chkFeatureRegion" Grid.Column="0"  VerticalAlignment="Center" FontSize="14" VerticalContentAlignment="Center">-->
                                     <TextBlock x:Name="txtFeatureRegionTitle" Text="数字范围" VerticalAlignment="Center" FontSize="14" TextWrapping="Wrap" />
-                                </CheckBox>
+                                <!--</CheckBox>-->
                                 <TextBox Grid.Column="1" x:Name="txtFeatureRegion" Height="26" Padding="2" FontSize="14px" IsReadOnly="True" />
                                 <Button x:Name="btnFeatureRegion" Click="BtnFeatureRegion_Click" 
                                         Grid.Column="3" Content="说明示例" BorderThickness="0 0 0 1" BorderBrush="Blue"
                                             Height="20" Width="60" Background="Transparent" Foreground="Blue" FontSize="14" />
                             </Grid>
 
-                            <StackPanel Height="1" Background="#D3D3D3" Margin="10 0 10 0" />
+                            <Grid Height="25" Margin="10 0 10 0">
+                                <Button  x:Name="btnMarkMeter" Click="BtnMarkMeter_Click" 
+                                        Grid.Row="0" Content="请先读取图像,再点击我标定图像区域" BorderThickness="0 0 0 1" BorderBrush="Blue" HorizontalAlignment="Left"
+                                            Height="20"  Background="Transparent" Foreground="Blue" FontSize="14" />
+                            </Grid>
+
+                            <Grid Height="35">
+                                <Grid.ColumnDefinitions>
+                                    <ColumnDefinition Width="*" />
+                                    <ColumnDefinition Width="*" />
+                                </Grid.ColumnDefinitions>
+                                <zdfflatui:FlatButton Grid.Column="0" x:Name="btnReadImgConfig" Background="#4CAF50" Foreground="White" 
+                                                          Content="读取图像区域参数"  Click="BtnReadImgConfig_Click" 
+                                                          Height="28" FontSize="14" Margin="10 0 10 0" />
+
+                                <zdfflatui:FlatButton Grid.Column="1" x:Name="btnSetImgConfig" Background="#2196F3" Foreground="White" 
+                                                          Content="设置图像区域参数"  Click="BtnSetImgConfig_Click" 
+                                                          Height="28" FontSize="14" Margin="10 0 10 0" />
+                            </Grid>
+
+
+
+                            <StackPanel Height="1" Background="DarkGray" Margin="10 5 10 5" />
 
                             <Grid Height="40" Margin="10 0 10 0" Visibility="Collapsed">
                                 <!--<Button x:Name="btnMarkMeter" Click="BtnMarkMeter_Click" 
@@ -384,19 +420,22 @@
                             </Grid>
 
                             <Grid Height="30" Margin="10 0 10 0" >
-                                <TextBlock Text="需要改变采样间隔时,配置以下选项。" Foreground="DarkBlue" FontSize="14"
+                                <TextBlock Text="AI识别的时间间隔(默认每日0点)" Foreground="DarkBlue" FontSize="14"
                                            Grid.Row="1"  Margin="0 0 0 0"  VerticalAlignment="Center" FontWeight="Bold"/>
                             </Grid>
 
-                            <Grid Height="50" Margin="10 0 10 0">
+                            <Grid Height="40" Margin="10 0 10 0">
                                 <Grid.ColumnDefinitions>
                                     <ColumnDefinition Width="90" />
                                     <ColumnDefinition Width="*" />
                                     <!--<ColumnDefinition Width="40" />-->
                                     <ColumnDefinition Width="80" />
                                 </Grid.ColumnDefinitions>
-                                <!--<TextBlock Grid.Column="0" Text="采样周期" VerticalAlignment="Center" FontSize="14" TextWrapping="Wrap" />-->
-                                <CheckBox x:Name="chkSampleInterval" Grid.Column="0" Content="采样周期" VerticalAlignment="Center" FontSize="14" VerticalContentAlignment="Center" />
+                                <TextBlock Grid.Column="0" Text="采样周期" VerticalAlignment="Center" FontSize="14" TextWrapping="Wrap" />
+                                <!--<CheckBox x:Name="chkSampleInterval" Grid.Column="0" Content="采样周期" VerticalAlignment="Center" FontSize="14" VerticalContentAlignment="Center" />-->
+                                
+                                
+                                
                                 <TextBox Visibility="Collapsed" Grid.Column="1" x:Name="txtSampleInterval1" Height="26" Padding="2" FontSize="14px" IsReadOnly="False" />
                                 <!--<ComboBox Grid.Column="1" x:Name="cmbFlowRate"  Height="26" FontSize="14px"
                                           IsEditable="True" PreviewTextInput="TextBox_PreviewTextInput"                              
@@ -418,15 +457,17 @@
                                             Height="20" Width="60" Background="Transparent" Foreground="Blue" FontSize="14" />
                             </Grid>
 
-                            <Grid Height="50" Margin="10 0 10 0">
+                            <Grid Height="40" Margin="10 0 10 0">
                                 <Grid.ColumnDefinitions>
                                     <ColumnDefinition Width="90" />
                                     <ColumnDefinition Width="*" />
                                     <ColumnDefinition Width="30" />
                                     <ColumnDefinition Width="80" />
                                 </Grid.ColumnDefinitions>
-                                <!--<TextBlock Grid.Column="0" Text="采样周期" VerticalAlignment="Center" FontSize="14" TextWrapping="Wrap" />-->
-                                <CheckBox x:Name="chkFirstHour" Grid.Column="0" Content="首采时间" VerticalAlignment="Center" FontSize="14" VerticalContentAlignment="Center" />
+                                <TextBlock Grid.Column="0" Text="首采时间" VerticalAlignment="Center" FontSize="14" TextWrapping="Wrap" />
+                                <!--<CheckBox x:Name="chkFirstHour" Grid.Column="0" Content="首采时间" VerticalAlignment="Center" FontSize="14" VerticalContentAlignment="Center" />-->
+                                
+                                
                                 <!--<TextBox Grid.Column="1" x:Name="txtFirstHour" Height="26" Padding="2" FontSize="14px" IsReadOnly="False" />-->
                                 <ComboBox Grid.Column="1" x:Name="cmbFirstHour"  Height="26" FontSize="14px"
                                            IsTextSearchEnabled="False"
@@ -440,31 +481,38 @@
                                             Height="20" Width="60" Background="Transparent" Foreground="Blue" FontSize="14" />
                             </Grid>
 
-                            <Grid Height="40">
+                            <Grid Height="35">
                                 <Grid.ColumnDefinitions>
                                     <ColumnDefinition Width="*" />
                                     <ColumnDefinition Width="*" />
                                 </Grid.ColumnDefinitions>
-                                <zdfflatui:FlatButton Grid.Column="0" x:Name="btnReadConfig" Background="#4CAF50" Foreground="White" 
-                                                          Content="读取抄表器运行参数"  Click="BtnReadConfig_Click" 
+                                <zdfflatui:FlatButton Grid.Column="0" x:Name="btnReadSampleConfig" Background="#4CAF50" Foreground="White" 
+                                                          Content="读取采样间隔参数"  Click="BtnReadSampleConfig_Click" 
                                                           Height="28" FontSize="14" Margin="10 0 10 0" />
 
-                                <zdfflatui:FlatButton Grid.Column="1" x:Name="btnSetConfig" Background="#2196F3" Foreground="White" 
-                                                          Content="设置抄表器运行参数"  Click="BtnSetConfig_Click" 
+                                <zdfflatui:FlatButton Grid.Column="1" x:Name="btnSetSampleConfig" Background="#2196F3" Foreground="White" 
+                                                          Content="设置采样间隔参数"  Click="BtnSetSampleConfig_Click" 
                                                           Height="28" FontSize="14" Margin="10 0 10 0" />
                             </Grid>
 
-                            <Grid Height="50" Margin="10 0 10 0">
+                            <StackPanel Height="1" Background="DarkGray" Margin="10 5 10 5" />
+
+                            <Grid Height="30" Margin="10 0 10 0" >
+                                <TextBlock Text="同步设备时钟(可定时同步)" Foreground="DarkBlue" FontSize="14"
+                                           Grid.Row="1"  Margin="0 0 0 0"  VerticalAlignment="Center" FontWeight="Bold"/>
+                            </Grid>
+
+                            <Grid Height="40" Margin="10 0 10 0">
                                 <Grid.ColumnDefinitions>
                                     <ColumnDefinition Width="90" />
                                     <ColumnDefinition Width="*" />
                                     <!--<ColumnDefinition Width="80" />-->
                                 </Grid.ColumnDefinitions>
-                                <TextBlock x:Name="txtFeadtureRegionTitle" Grid.Column="0" Text="抄表器时钟" VerticalAlignment="Center" FontSize="14" TextWrapping="Wrap" />
+                                <TextBlock Grid.Column="0" Text="抄表器时钟" VerticalAlignment="Center" FontSize="14" TextWrapping="Wrap" />
                                 <TextBox Grid.Column="1" x:Name="txtDeviceTime" Height="26" Padding="2" FontSize="14px" IsReadOnly="True" />
                             </Grid>
 
-                            <Grid Height="40">
+                            <Grid Height="35">
                                 <Grid.ColumnDefinitions>
                                     <ColumnDefinition Width="*" />
                                     <ColumnDefinition Width="*" />
@@ -478,6 +526,8 @@
                                                           Height="28" FontSize="14" Margin="10 0 10 0" />
                             </Grid>
 
+                            <StackPanel Height="1" Background="Transparent" Margin="10 5 10 5" />
+                            
                         </StackPanel>
                     </Border>
                 </ScrollViewer>

+ 591 - 11
MV485/uc/UCRunConfig.xaml.cs

@@ -168,14 +168,59 @@ namespace MV485.uc
             //dtpLastValueTime.v
             txtMeterRegion.Text = "";
             txtFeatureRegion.Text = "";
-
-
             //cmbSampleInterval.Text = "";
             cmbSampleInterval.SelectedItem = null;
             //txtFirstHour.Text = "";
             cmbFirstHour.SelectedItem = null;
         }
 
+        private void InitAIConfigView()
+        {
+            cmbMeterType.SelectedItem = null;
+            //cmbFlowRate.Text = "";
+            cmbDnValue.SelectedItem = null;
+            //cmbNumCount.Text = "";
+            cmbNumCount.SelectedItem = null;
+            //cmbIndCount.Text = "";
+            cmbIndCount.SelectedItem = null;
+            //cmbBrightVal.Text = "";
+            cmbLastUnit.SelectedItem = null;
+            cmbUploadRedind.SelectedItem = null;
+
+            txtLastValue.Text = "";
+            //dtpLastValueTime.Text = "";
+            //dtpLastValueTime.Value = null;
+            //dtpLastValueTime.ClearValue(dtpLastValueTime.ValueProperty);
+            //dtpLastValueTime.SelectedDate = null;
+            //dtpLastValueTime.Value = null;  // 第一步:清空 Value 依赖属性
+            //dtpLastValueTime.SelectedDate = null;  // 清空基础类 DatePicker 的值
+
+            dtpLastValueTime.Value = null;
+
+            dtpLastValueTime.ApplyTemplate();
+            var tb = dtpLastValueTime.Template.FindName("PART_TextBox_New", dtpLastValueTime) as DatePickerTextBox;
+            var cal = dtpLastValueTime.Template.FindName("PART_Calendar", dtpLastValueTime) as Calendar;
+            if (tb != null) tb.Text = "";
+            if (cal != null) cal.SelectedDate = null;
+
+            //txtMeterRegion.Text = "";
+            //txtFeatureRegion.Text = "";
+            //cmbSampleInterval.SelectedItem = null;
+            //cmbFirstHour.SelectedItem = null;
+        }
+
+        private void InitRegionConfigView()
+        {
+            txtMeterRegion.Text = "";
+            txtFeatureRegion.Text = "";
+        }
+
+        private void InitSampleConfigView()
+        {
+            cmbSampleInterval.SelectedItem = null;
+            cmbFirstHour.SelectedItem = null;
+        }
+
         private void LoadConfigItems()
         {
             cmbMeterType.ItemsSource = Tools.MeterTypeList;
@@ -614,14 +659,23 @@ namespace MV485.uc
                 return;
             }
 
-            if(cmbMeterType.SelectedItem == null)
+            RunConfig readRunConfig = btnSetImgConfig.Tag as RunConfig;
+            if(readRunConfig == null)
             {
-                MessageBox.Show(Application.Current.MainWindow, "请先指定水表类型", "提示",
+                MessageBox.Show(Application.Current.MainWindow, "请先读取AI基本参数", "提示",
                     MessageBoxButton.OK, MessageBoxImage.Warning);
                 return;
             }
 
-            byte meterType = (byte)cmbMeterType.SelectedValue;
+           
+            //if(cmbMeterType.SelectedItem == null)
+            //{
+            //    MessageBox.Show(Application.Current.MainWindow, "请先指定水表类型", "提示",
+            //        MessageBoxButton.OK, MessageBoxImage.Warning);
+            //    return;
+            //}
+
+            byte meterType = readRunConfig.MeterType;       //(byte)cmbMeterType.SelectedValue;
             DlgMark dlgMark = new DlgMark(meterType, ImageFilePath)
             {
                 Owner = Application.Current.MainWindow,
@@ -705,7 +759,7 @@ namespace MV485.uc
             {
                 RunConfig runConfig = await Task.Run(() =>
                 {
-                    return _rwRunConfig.ReadRunConfig(portName,baudrate,devid);
+                    return _rwRunConfig.ReadRunConfig(portName,baudrate,devid,0);
                 });
                 if(runConfig != null)
                 {
@@ -821,7 +875,108 @@ namespace MV485.uc
             }
         }
 
-        //设置配置按钮
+        private void LoadAIConfigView(RunConfig runConfig)
+        {
+            grdIndCount.Visibility = Visibility.Collapsed;
+            grdNumCount.Visibility = Visibility.Collapsed;
+
+            if (runConfig.MeterTypeWRFlag)
+            {
+                cmbMeterType.SelectedValue = runConfig.MeterType;
+            }
+            if (runConfig.DnValueWRFlag)
+            {
+                //cmbFlowRate.Text = runConfig.DnValue.ToString();
+                cmbDnValue.SelectedValue = runConfig.DnValue;
+            }
+
+            if (runConfig.DigitCountWRFlag &&
+                (runConfig.MeterType == Constant.METER_TYPE_NUM_IND || runConfig.MeterType == Constant.METER_TYPE_NUM))
+            {
+                //cmbNumCount.Text = runConfig.DigitCount.ToString();
+                cmbNumCount.SelectedItem = runConfig.DigitCount;
+                grdNumCount.Visibility = Visibility.Visible;
+            }
+
+            if (runConfig.IndCountWRFlag &&
+                (runConfig.MeterType == Constant.METER_TYPE_NUM_IND || runConfig.MeterType == Constant.METER_TYPE_IND))
+            {
+                //cmbIndCount.Text = runConfig.IndCount.ToString();
+                cmbIndCount.SelectedItem = runConfig.IndCount;
+                grdIndCount.Visibility = Visibility.Visible;
+            }
+
+            //此项已经不需要了
+            /*if (runConfig.BrightValueWRFlag)
+            {
+                cmbBrightVal.Text = runConfig.BrightValue.ToString();
+            }*/
+
+            if (runConfig.LastUnitLevelWRFlag)
+            {
+                cmbLastUnit.SelectedValue = runConfig.LastUnitLevel;
+            }
+
+            if (runConfig.UploadRedindWRFlag)
+            {
+                cmbUploadRedind.SelectedValue = runConfig.UploadRedind;
+            }
+
+            if (runConfig.LatestValueWRFlag && runConfig.LatestTimeWRFlag && runConfig.LatestTime != null)
+            {
+                txtLastValue.Text = ((int)(runConfig.LatestValue / Constant.CUBE_VALUE)).ToString();
+                //dtpLastValueTime.Text = runConfig.LatestTime.ToString("yyyy-MM-dd HH:mm");
+                dtpLastValueTime.Value = runConfig.LatestTime;
+            }
+
+            if (runConfig.MeterTypeWRFlag &&
+                (runConfig.MeterType == Constant.METER_TYPE_NUM_IND || 
+                runConfig.MeterType == Constant.METER_TYPE_NUM))
+            {
+                txtFeatureRegionTitle.Text = "数字区域\n坐标";
+            }
+            else if (runConfig.MeterTypeWRFlag && (runConfig.MeterType == Constant.METER_TYPE_IND))
+            {
+                txtFeatureRegionTitle.Text = "首位指针\n同刻度坐标";
+            }
+        }
+
+        private void LoadRegionConfigView(RunConfig runConfig)
+        {
+            if (runConfig.MeterRegion != null)
+            {
+                txtMeterRegion.Text = runConfig.MeterRegion;
+            }
+
+            if (runConfig.DigitRegionWRFlag &&
+                (runConfig.MeterType == Constant.METER_TYPE_NUM_IND || runConfig.MeterType == Constant.METER_TYPE_NUM))
+            {
+                txtFeatureRegionTitle.Text = "数字区域\n坐标";
+                txtFeatureRegion.Text = runConfig.DigitRegion;
+            }
+            else if (runConfig.FTIndRegionWRFlag && (runConfig.MeterType == Constant.METER_TYPE_IND))
+            {
+                txtFeatureRegionTitle.Text = "首位指针\n同刻度坐标";
+                txtFeatureRegion.Text = runConfig.FTIndRegion;
+            }
+        }
+
+        private void LoadSampleConfigView(RunConfig runConfig)
+        {
+            if (runConfig.SampleIntervalFlag)
+            {
+                //cmbSampleInterval.Text = runConfig.SampleInterval.ToString();
+                cmbSampleInterval.SelectedValue = runConfig.SampleInterval;
+            }
+
+            if (runConfig.FirstHourFlag)
+            {
+                //txtFirstHour.Text = runConfig.FirstHour.ToString();
+                cmbFirstHour.SelectedItem = (int)runConfig.FirstHour;
+            }
+        }
+
+            //设置配置按钮
         private async void BtnSetConfig_Click(object sender, RoutedEventArgs e)
         {
             if (!LicenseMana.mIsLicensed)
@@ -993,7 +1148,7 @@ namespace MV485.uc
             runConfig.LatestTime = dtpLastValueTime.Value.GetValueOrDefault();
 
 
-            if (chkMeterRegion.IsChecked == true)
+            //if (chkMeterRegion.IsChecked == true)
             {
                 if (string.IsNullOrWhiteSpace(txtMeterRegion.Text))
                 {
@@ -1005,7 +1160,7 @@ namespace MV485.uc
                 runConfig.MeterRegion = txtMeterRegion.Text;
             }
 
-            if (chkFeatureRegion.IsChecked == true)
+            //if (chkFeatureRegion.IsChecked == true)
             {
                 string featureTitle = (runConfig.MeterType == Constant.METER_TYPE_IND) ?
                     "首尾指针同刻度坐标" : "数字区域范围坐标";
@@ -1029,7 +1184,7 @@ namespace MV485.uc
 
 
 
-            if (chkSampleInterval.IsChecked == true)
+            //if (chkSampleInterval.IsChecked == true)
             {
                 //if(string.IsNullOrWhiteSpace(cmbSampleInterval.Text) ||
                 //!ushort.TryParse(cmbSampleInterval.Text, out ushort sampleInterval))
@@ -1048,7 +1203,7 @@ namespace MV485.uc
                 runConfig.SampleInterval = (ushort)cmbSampleInterval.SelectedValue;    //sampleInterval;
             }
 
-            if (chkFirstHour.IsChecked == true)
+            //if (chkFirstHour.IsChecked == true)
             {
                 if (cmbFirstHour.SelectedItem==null)                
                 {
@@ -1380,6 +1535,431 @@ namespace MV485.uc
             }
         }
 
+        private async void BtnReadBasicConfig_Click(object sender, RoutedEventArgs e)
+        {
+            if (!GetSerialParameter(out string portName, out byte devid, out int baudrate))
+            {
+                return;
+            }
+
+            //显示等待串口
+            string titleInfo = "正在读取设备的运行参数";
+            WaitWindow waitWindow = new WaitWindow(titleInfo)
+            {
+                Owner = Application.Current.MainWindow,
+                WindowStartupLocation = WindowStartupLocation.CenterOwner
+            };
+            waitWindow.Show();
+            //InitConfigView();
+            InitAIConfigView();
+            try
+            {
+                RunConfig runConfig = await Task.Run(() =>
+                {
+                    return _rwRunConfig.ReadRunConfig(portName, baudrate, devid,1);
+                });
+                if (runConfig != null)
+                {
+                    //加载数据到页面视图
+                    //LoadRunConfigView(runConfig);
+                    LoadAIConfigView(runConfig);
+                    btnSetImgConfig.Tag = runConfig;
+                    AppendLog("已成功读取设备运行参数");
+                }
+                else
+                {
+                    AppendLog("读取设备运行参数失败");
+                }
+            }
+            catch { }
+            finally
+            {
+                waitWindow.Close();
+            }
+        }
+
+        private async void BtnSetBasicConfig_Click(object sender, RoutedEventArgs e)
+        {
+            if (!LicenseMana.mIsLicensed)
+            {
+                MessageBox.Show(Application.Current.MainWindow, "软件未注册,不能使用此功能。", "提示",
+                    MessageBoxButton.OK, MessageBoxImage.Information);
+                return;
+            }
+
+            if (!GetSerialParameter(out string portName, out byte devid, out int baudrate))
+            {
+                return;
+            }
+
+            RunConfig runConfig = new RunConfig();
+
+
+            //判断输入项的正确性
+            if (cmbMeterType.SelectedItem == null)
+            {
+                MessageBox.Show(Application.Current.MainWindow, "请选择表类型", "提示",
+                    MessageBoxButton.OK, MessageBoxImage.Warning);
+                return;
+            }
+            runConfig.MeterTypeWRFlag = true;
+            runConfig.MeterType = (byte)cmbMeterType.SelectedValue;
+
+
+            if (cmbDnValue.SelectedItem == null)
+            {
+                MessageBox.Show(Application.Current.MainWindow, "请选择水表口径", "提示",
+                    MessageBoxButton.OK, MessageBoxImage.Warning);
+                return;
+            }
+            runConfig.DnValueWRFlag = true;
+            runConfig.DnValue = (ushort)cmbDnValue.SelectedValue;
+
+            if (runConfig.MeterType == Constant.METER_TYPE_NUM_IND || runConfig.MeterType == Constant.METER_TYPE_NUM)
+            {
+                if (cmbNumCount.SelectedItem == null)
+                {
+                    MessageBox.Show(Application.Current.MainWindow, "请选择数字个数", "提示",
+                        MessageBoxButton.OK, MessageBoxImage.Warning);
+                }
+                runConfig.DigitCountWRFlag = true;
+                runConfig.DigitCount = (byte)cmbNumCount.SelectedItem;  //digitCount;
+            }
+
+            if (runConfig.MeterType == Constant.METER_TYPE_NUM_IND || runConfig.MeterType == Constant.METER_TYPE_IND)
+            {
+                if (cmbIndCount.SelectedItem == null)
+                {
+                    MessageBox.Show(Application.Current.MainWindow, "请选择指针个数", "提示",
+                        MessageBoxButton.OK, MessageBoxImage.Warning);
+                }
+                runConfig.IndCountWRFlag = true;
+                runConfig.IndCount = (byte)cmbIndCount.SelectedItem;  //indCount;
+            }
+
+
+            if (cmbLastUnit.SelectedItem == null)
+            {
+                MessageBox.Show(Application.Current.MainWindow, "请选择正确的尾数单位", "提示",
+                    MessageBoxButton.OK, MessageBoxImage.Warning);
+                return;
+            }
+            runConfig.LastUnitLevelWRFlag = true;
+            runConfig.LastUnitLevel = (byte)cmbLastUnit.SelectedValue;
+
+            if (cmbUploadRedind.SelectedItem == null)
+            {
+                MessageBox.Show(Application.Current.MainWindow, "请选择是否上传红色指针的读数", "提示",
+                    MessageBoxButton.OK, MessageBoxImage.Warning);
+                return;
+            }
+            runConfig.UploadRedindWRFlag = true;
+            runConfig.UploadRedind = (byte)cmbUploadRedind.SelectedValue;
+
+            if (string.IsNullOrWhiteSpace(txtLastValue.Text) ||
+                !ulong.TryParse(txtLastValue.Text, out ulong latestValue))
+            {
+                MessageBox.Show(Application.Current.MainWindow, "请输入正确的表底读数", "提示",
+                    MessageBoxButton.OK, MessageBoxImage.Warning);
+                return;
+            }
+            runConfig.LatestValueWRFlag = true;
+            runConfig.LatestValue = latestValue * Constant.CUBE_VALUE;
+
+            //if(string.IsNullOrWhiteSpace(dtpLastValueTime.Text) ||
+            //    !DateTime.TryParse(dtpLastValueTime.Value,out DateTime dtLatestTime))
+            if (dtpLastValueTime.Value == null)
+            {
+                MessageBox.Show(Application.Current.MainWindow, "请输入表底读数对应的时间", "提示",
+                    MessageBoxButton.OK, MessageBoxImage.Warning);
+                return;
+            }
+            runConfig.LatestTimeWRFlag = true;
+            runConfig.LatestTime = dtpLastValueTime.Value.GetValueOrDefault();
+
+            //显示等待串口
+            string titleInfo = "正在设置AI基本参数";
+            WaitWindow waitWindow = new WaitWindow(titleInfo)
+            {
+                Owner = Application.Current.MainWindow,
+                WindowStartupLocation = WindowStartupLocation.CenterOwner
+            };
+            waitWindow.Show();
+
+            try
+            {
+                bool blResult = await Task.Run(() =>
+                {
+                    return _rwRunConfig.WriteRunConfig(portName, baudrate, devid, runConfig);
+                });
+
+                string msgInfo = $"设置AI基本参数{(blResult ? "成功" : "失败")}";
+                if (blResult)
+                {
+                    msgInfo += "\n抄表器会重启,请等待1-2分钟,再尝试读取参数进行核对。";
+                    btnSetImgConfig.Tag = runConfig;
+                }
+
+                MessageBox.Show(Application.Current.MainWindow, msgInfo, "提示",
+                    MessageBoxButton.OK, blResult ? MessageBoxImage.Information : MessageBoxImage.Warning);
+            }
+            catch { }
+            finally
+            {
+                waitWindow.Close();
+            }
+
+        }
+
+        private async void BtnReadImgConfig_Click(object sender, RoutedEventArgs e)
+        {
+            if (!GetSerialParameter(out string portName, out byte devid, out int baudrate))
+            {
+                return;
+            }
+
+            //显示等待串口
+            string titleInfo = "正在读取图像区域参数";
+            WaitWindow waitWindow = new WaitWindow(titleInfo)
+            {
+                Owner = Application.Current.MainWindow,
+                WindowStartupLocation = WindowStartupLocation.CenterOwner
+            };
+            waitWindow.Show();
+            //InitConfigView();
+            InitRegionConfigView();
+            try
+            {
+                RunConfig runConfig = await Task.Run(() =>
+                {
+                    return _rwRunConfig.ReadRunConfig(portName, baudrate, devid, 2);
+                });
+                if (runConfig != null)
+                {
+                    //加载数据到页面视图
+                    //LoadRunConfigView(runConfig);
+                    //LoadAIConfigView(runConfig);
+                    LoadRegionConfigView(runConfig);
+                    AppendLog("已成功读取设备运行参数");
+                    btnSetImgConfig.Tag = runConfig;
+                }
+                else
+                {
+                    AppendLog("读取设备运行参数失败");
+                }
+            }
+            catch { }
+            finally
+            {
+                waitWindow.Close();
+            }
+        }
+
+        private async void BtnSetImgConfig_Click(object sender, RoutedEventArgs e)
+        {
+            if (!LicenseMana.mIsLicensed)
+            {
+                MessageBox.Show(Application.Current.MainWindow, "软件未注册,不能使用此功能。", "提示",
+                    MessageBoxButton.OK, MessageBoxImage.Information);
+                return;
+            }
+
+            if (!GetSerialParameter(out string portName, out byte devid, out int baudrate))
+            {
+                return;
+            }
+
+            RunConfig readRunConfig = btnSetImgConfig.Tag as RunConfig;
+            if(readRunConfig == null)
+            {
+                MessageBox.Show(Application.Current.MainWindow, "请先读取图像区域参数", "提示",
+                    MessageBoxButton.OK, MessageBoxImage.Warning);
+                return;
+            }
+            
+            //获取水表的类型
+            RunConfig runConfig = new RunConfig();
+            runConfig.MeterType = readRunConfig.MeterType;
+
+
+            if (string.IsNullOrWhiteSpace(txtMeterRegion.Text))
+            {
+                MessageBox.Show(Application.Current.MainWindow, "请输入表盘范围坐标", "提示",
+                    MessageBoxButton.OK, MessageBoxImage.Warning);
+                return;
+            }
+            runConfig.MeterRegionWRFlag = true;
+            runConfig.MeterRegion = txtMeterRegion.Text;
+
+            string featureTitle = (runConfig.MeterType == Constant.METER_TYPE_IND) ?
+                "首尾指针同刻度坐标" : "数字区域范围坐标";
+            if (string.IsNullOrEmpty(txtFeatureRegion.Text))
+            {
+                MessageBox.Show(Application.Current.MainWindow, $"请输入{featureTitle}", "提示",
+                    MessageBoxButton.OK, MessageBoxImage.Warning);
+                return;
+            }
+            if (runConfig.MeterType == Constant.METER_TYPE_IND)
+            {
+                runConfig.FTIndRegionWRFlag = true;
+                runConfig.FTIndRegion = txtFeatureRegion.Text.Trim();
+            }
+            else
+            {
+                runConfig.DigitRegionWRFlag = true;
+                runConfig.DigitRegion = txtFeatureRegion.Text.Trim();
+            }
+
+
+
+            //显示等待串口
+            string titleInfo = "正在设置图像区域参数";
+            WaitWindow waitWindow = new WaitWindow(titleInfo)
+            {
+                Owner = Application.Current.MainWindow,
+                WindowStartupLocation = WindowStartupLocation.CenterOwner
+            };
+            waitWindow.Show();
+
+            try
+            {
+                bool blResult = await Task.Run(() =>
+                {
+                    return _rwRunConfig.WriteRunConfig(portName, baudrate, devid, runConfig);
+                });
+
+                string msgInfo = $"设置图像区域参数{(blResult ? "成功" : "失败")}";
+                if (blResult)
+                {
+                    msgInfo += "\n抄表器会重启,请等待1-2分钟,再尝试读取参数进行核对。";
+                }
+
+                MessageBox.Show(Application.Current.MainWindow, msgInfo, "提示",
+                    MessageBoxButton.OK, blResult ? MessageBoxImage.Information : MessageBoxImage.Warning);
+            }
+            catch { }
+            finally
+            {
+                waitWindow.Close();
+            }
+        }
+
+        private async void BtnReadSampleConfig_Click(object sender, RoutedEventArgs e)
+        {
+            if (!GetSerialParameter(out string portName, out byte devid, out int baudrate))
+            {
+                return;
+            }
+
+            //显示等待串口
+            string titleInfo = "正在读取采样间隔参数";
+            WaitWindow waitWindow = new WaitWindow(titleInfo)
+            {
+                Owner = Application.Current.MainWindow,
+                WindowStartupLocation = WindowStartupLocation.CenterOwner
+            };
+            waitWindow.Show();
+
+            InitSampleConfigView();
+
+            try
+            {
+                RunConfig runConfig = await Task.Run(() =>
+                {
+                    return _rwRunConfig.ReadRunConfig(portName, baudrate, devid, 3);
+                });
+                if (runConfig != null)
+                {
+                    //加载数据到页面视图
+                    LoadSampleConfigView(runConfig);
+                    AppendLog("已成功读取设备运行参数");
+                }
+                else
+                {
+                    AppendLog("读取设备运行参数失败");
+                }
+            }
+            catch { }
+            finally
+            {
+                waitWindow.Close();
+            }
+        }
+
+        private async void BtnSetSampleConfig_Click(object sender, RoutedEventArgs e)
+        {
+            if (!LicenseMana.mIsLicensed)
+            {
+                MessageBox.Show(Application.Current.MainWindow, "软件未注册,不能使用此功能。", "提示",
+                    MessageBoxButton.OK, MessageBoxImage.Information);
+                return;
+            }
+
+            if (!GetSerialParameter(out string portName, out byte devid, out int baudrate))
+            {
+                return;
+            }
+
+            RunConfig runConfig = new RunConfig();
+
+
+            //if (chkSampleInterval.IsChecked == true)
+            //{
+                if (cmbSampleInterval.SelectedItem == null)
+                {
+                    MessageBox.Show(Application.Current.MainWindow, "请选择采样间隔", "提示",
+                        MessageBoxButton.OK, MessageBoxImage.Warning);
+                    return;
+                }
+                runConfig.SampleIntervalFlag = true;
+                runConfig.SampleInterval = (ushort)cmbSampleInterval.SelectedValue;    //sampleInterval;
+            //}
+
+            //if (chkFirstHour.IsChecked == true)
+            //{
+                if (cmbFirstHour.SelectedItem == null)
+                {
+                    MessageBox.Show(Application.Current.MainWindow, "请输入正确首次采样整点时(0~23)", "提示",
+                        MessageBoxButton.OK, MessageBoxImage.Warning);
+                    return;
+                }
+                runConfig.FirstHourFlag = true;
+                runConfig.FirstHour = (byte)(int)cmbFirstHour.SelectedItem;
+            //}
+
+
+            //显示等待串口
+            string titleInfo = "正在设置采样间隔参数";
+            WaitWindow waitWindow = new WaitWindow(titleInfo)
+            {
+                Owner = Application.Current.MainWindow,
+                WindowStartupLocation = WindowStartupLocation.CenterOwner
+            };
+            waitWindow.Show();
+
+            try
+            {
+                bool blResult = await Task.Run(() =>
+                {
+                    return _rwRunConfig.WriteRunConfig(portName, baudrate, devid, runConfig);
+                });
+
+                string msgInfo = $"设置采样间隔参数{(blResult ? "成功" : "失败")}";
+                if (blResult)
+                {
+                    msgInfo += "\n抄表器会重启,请等待1-2分钟,再尝试读取参数进行核对。";
+                }
+
+                MessageBox.Show(Application.Current.MainWindow, msgInfo, "提示",
+                    MessageBoxButton.OK, blResult ? MessageBoxImage.Information : MessageBoxImage.Warning);
+            }
+            catch { }
+            finally
+            {
+                waitWindow.Close();
+            }
+        }
+
 
 
         //------------------------------------------------------------------