|
@@ -6,6 +6,7 @@ using System.Collections.Generic;
|
|
|
using System.IO;
|
|
|
using System.Linq;
|
|
|
using System.Text;
|
|
|
+using System.Text.RegularExpressions;
|
|
|
using System.Threading.Tasks;
|
|
|
using System.Windows;
|
|
|
using System.Windows.Controls;
|
|
@@ -28,6 +29,10 @@ namespace MV485.uc
|
|
|
private static readonly string LogFilePath =
|
|
|
Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Documents", "runConfig_log.txt");
|
|
|
|
|
|
+ private static readonly string ImageFilePath =
|
|
|
+ Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Documents", "runConfig_read.jpg");
|
|
|
+
|
|
|
+
|
|
|
private RWRunConfig _rwRunConfig; // = new RWRunConfig();
|
|
|
private List<LogEntry> _logEntries = new List<LogEntry>();
|
|
|
|
|
@@ -103,7 +108,7 @@ namespace MV485.uc
|
|
|
{
|
|
|
cmbMeterType.ItemsSource = Tools.MeterTypeList;
|
|
|
cmbFlowRate.ItemsSource = Tools.FlowRateList;
|
|
|
- cmbLastUnit.ItemsSource = Tools.UnitList;
|
|
|
+ cmbLastUnit.ItemsSource = Tools.LastUnitMap; //.UnitList;
|
|
|
cmbNumCount.ItemsSource = Tools.NumList;
|
|
|
cmbIndCount.ItemsSource = Tools.NumList;
|
|
|
cmbBrightVal.ItemsSource = Tools.BrightList;
|
|
@@ -162,11 +167,65 @@ namespace MV485.uc
|
|
|
}
|
|
|
|
|
|
//读取水表图像
|
|
|
- private void BtnReadImage_Click(object sender, RoutedEventArgs e)
|
|
|
+ private async void BtnReadImage_Click(object sender, RoutedEventArgs e)
|
|
|
{
|
|
|
+ if (!GetSerialParameter(out string portName, out byte devId, out int baudrate))
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
- }
|
|
|
+ ushort imageSize = _rwRunConfig.ReadImageSize(portName, baudrate, devId);
|
|
|
|
|
|
+ if(imageSize == 0)
|
|
|
+ {
|
|
|
+ MessageBox.Show(Application.Current.MainWindow, "没有获取到照片文件的大小", "提示",
|
|
|
+ MessageBoxButton.OK, MessageBoxImage.Warning);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ //开始通过xModem协议读取照片
|
|
|
+ string titleInfo = "开始接收采样时照片";
|
|
|
+ WaitWindow waitWindow = new WaitWindow(titleInfo)
|
|
|
+ {
|
|
|
+ Owner = Application.Current.MainWindow,
|
|
|
+ WindowStartupLocation = WindowStartupLocation.CenterOwner
|
|
|
+ };
|
|
|
+ waitWindow.Show();
|
|
|
+
|
|
|
+ XModemReceiver receiver = new XModemReceiver();
|
|
|
+ receiver.OnProgress += (receiveSize, fileSize) =>
|
|
|
+ {
|
|
|
+ waitWindow.Dispatcher.Invoke(() =>
|
|
|
+ {
|
|
|
+ waitWindow.TitleInfo = $"已接受{receiveSize}/{fileSize}";
|
|
|
+ });
|
|
|
+ };
|
|
|
+ receiver.RWLog += message =>
|
|
|
+ {
|
|
|
+ AppendLog(message);
|
|
|
+ };
|
|
|
+
|
|
|
+ receiver.SerialConnected += blConnected =>
|
|
|
+ {
|
|
|
+
|
|
|
+ };
|
|
|
+ receiver.SerialStatusChanged += blStatusChanged =>
|
|
|
+ {
|
|
|
+
|
|
|
+ };
|
|
|
+ try
|
|
|
+ {
|
|
|
+ bool blRecv = await Task.Run(() =>
|
|
|
+ {
|
|
|
+ return receiver.StartReceiveFile(portName, baudrate, ImageFilePath, imageSize);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ catch { }
|
|
|
+ finally
|
|
|
+ {
|
|
|
+ waitWindow.Close();
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
//---配置
|
|
|
//选择水表类型
|
|
@@ -174,17 +233,17 @@ namespace MV485.uc
|
|
|
{
|
|
|
if(cmbMeterType.SelectedValue != null)
|
|
|
{
|
|
|
- int meterType = (int)cmbMeterType.SelectedValue;
|
|
|
+ byte meterType = (byte)cmbMeterType.SelectedValue;
|
|
|
ChangeInfoByMeterType(meterType);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private void ChangeInfoByMeterType(int meterType)
|
|
|
+ private void ChangeInfoByMeterType(byte meterType)
|
|
|
{
|
|
|
- if (meterType == 1 || meterType == 3)
|
|
|
+ if (meterType == Constant.METER_TYPE_NUM_IND || meterType == Constant.METER_TYPE_NUM)
|
|
|
{
|
|
|
txtLastUnitTitle.Text = "数字区\n最小单位";
|
|
|
- txtFeatureRegionTitle.Text = "数字区范围";
|
|
|
+ txtFeatureRegionTitle.Text = "数字区域\n范围坐标";
|
|
|
if (meterType == 1)
|
|
|
{
|
|
|
grdIndCount.Visibility = Visibility.Visible;
|
|
@@ -196,7 +255,7 @@ namespace MV485.uc
|
|
|
grdNumCount.Visibility = Visibility.Visible;
|
|
|
}
|
|
|
}
|
|
|
- else if (meterType == 2)
|
|
|
+ else if (meterType == Constant.METER_TYPE_IND)
|
|
|
{
|
|
|
txtLastUnitTitle.Text = "尾指针的\n单位";
|
|
|
txtFeatureRegionTitle.Text = "首位指针\n同刻度坐标";
|
|
@@ -264,6 +323,25 @@ namespace MV485.uc
|
|
|
//图片标注按照
|
|
|
private void BtnMarkMeter_Click(object sender, RoutedEventArgs e)
|
|
|
{
|
|
|
+ //做测试
|
|
|
+ if (!string.IsNullOrWhiteSpace(txtMeterRegion.Text))
|
|
|
+ {
|
|
|
+ txtMeterRegion.Text = "";
|
|
|
+ txtFeatureRegion.Text = "";
|
|
|
+ }
|
|
|
+ else if(cmbMeterType.SelectedValue != null)
|
|
|
+ {
|
|
|
+ byte meterType = (byte)cmbMeterType.SelectedValue;
|
|
|
+ txtMeterRegion.Text = "0,0 319,239";
|
|
|
+ if (meterType == Constant.METER_TYPE_NUM_IND || meterType == Constant.METER_TYPE_NUM)
|
|
|
+ {
|
|
|
+ txtFeatureRegion.Text = "122,23 122,53 249,55 249,25";
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ txtFeatureRegion.Text = "132,74 129,186";
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
|
|
@@ -320,6 +398,7 @@ namespace MV485.uc
|
|
|
if(runConfig != null)
|
|
|
{
|
|
|
//加载数据到页面视图
|
|
|
+ LoadRunConfigView(runConfig);
|
|
|
AppendLog("已成功读取设备运行参数");
|
|
|
}
|
|
|
else
|
|
@@ -334,12 +413,251 @@ namespace MV485.uc
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- //设置配置按钮
|
|
|
- private void BtnSetConfig_Click(object sender, RoutedEventArgs e)
|
|
|
+
|
|
|
+ private void LoadRunConfigView(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();
|
|
|
+ }
|
|
|
+
|
|
|
+ if (runConfig.DigitCountWRFlag &&
|
|
|
+ (runConfig.MeterType == Constant.METER_TYPE_NUM_IND || runConfig.MeterType == Constant.METER_TYPE_NUM))
|
|
|
+ {
|
|
|
+ cmbNumCount.Text = runConfig.DigitCount.ToString();
|
|
|
+ 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();
|
|
|
+ grdIndCount.Visibility = Visibility.Visible;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (runConfig.BrightValueWRFlag)
|
|
|
+ {
|
|
|
+ cmbBrightVal.Text = runConfig.BrightValue.ToString();
|
|
|
+ }
|
|
|
+ if (runConfig.LastUnitLevelWRFlag)
|
|
|
+ {
|
|
|
+ cmbLastUnit.SelectedValue = runConfig.LastUnitLevel;
|
|
|
+ }
|
|
|
+
|
|
|
+ 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");
|
|
|
+ //runConfig.LatestTimeStr;
|
|
|
+ }
|
|
|
+
|
|
|
+ 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 async void BtnSetConfig_Click(object sender, RoutedEventArgs e)
|
|
|
+ {
|
|
|
+ //串口号
|
|
|
+ if (cmbPortNames.SelectedItem == null)
|
|
|
+ {
|
|
|
+ MessageBox.Show(Application.Current.MainWindow, "请选择串口", "提示",
|
|
|
+ MessageBoxButton.OK, MessageBoxImage.Warning);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ var portName = cmbPortNames.SelectedValue.ToString();
|
|
|
+ ConfigManager.Instance.UpdateConfig(ConfigKey.ConfigPortName, portName);
|
|
|
+
|
|
|
+ //波特率
|
|
|
+ if (cmbBaudrate.SelectedItem == null)
|
|
|
+ {
|
|
|
+ MessageBox.Show(Application.Current.MainWindow, "请选择波特率", "提示",
|
|
|
+ MessageBoxButton.OK, MessageBoxImage.Warning);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ var sBaudrate = cmbBaudrate.SelectedValue.ToString();
|
|
|
+ ConfigManager.Instance.UpdateConfig(ConfigKey.ConfigBaudrate, sBaudrate);
|
|
|
+
|
|
|
+ if (!byte.TryParse(cmbDevId.Text, out byte devid) || devid < 0 || devid > 247)
|
|
|
+ {
|
|
|
+ MessageBox.Show(Application.Current.MainWindow, "请输入正确的设备地址", "提示",
|
|
|
+ MessageBoxButton.OK, MessageBoxImage.Warning);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ ConfigManager.Instance.UpdateConfig(ConfigKey.ConfigDevId, devid.ToString());
|
|
|
+
|
|
|
+ int baudrate = int.Parse(sBaudrate);
|
|
|
+
|
|
|
+ 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(cmbFlowRate.SelectedItem != null)
|
|
|
+ {
|
|
|
+ runConfig.DnValueWRFlag = true;
|
|
|
+ runConfig.DnValue = (ushort)cmbFlowRate.SelectedValue;
|
|
|
+ }
|
|
|
+ else if(ushort.TryParse(cmbFlowRate.Text.Trim(),out ushort dnValue))
|
|
|
+ {
|
|
|
+ runConfig.DnValueWRFlag = true;
|
|
|
+ runConfig.DnValue = dnValue;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ MessageBox.Show(Application.Current.MainWindow, "请输入水表口径对应的每小时最大水流", "提示",
|
|
|
+ MessageBoxButton.OK, MessageBoxImage.Warning);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (runConfig.MeterType == Constant.METER_TYPE_NUM_IND || runConfig.MeterType == Constant.METER_TYPE_NUM)
|
|
|
+ {
|
|
|
+ if (string.IsNullOrWhiteSpace(cmbNumCount.Text) ||
|
|
|
+ !byte.TryParse(cmbNumCount.Text, out byte digitCount) ||
|
|
|
+ !(digitCount >0 && digitCount <= 10))
|
|
|
+ {
|
|
|
+ MessageBox.Show(Application.Current.MainWindow, "请输入数字个数", "提示",
|
|
|
+ MessageBoxButton.OK, MessageBoxImage.Warning);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ runConfig.DigitCountWRFlag = true;
|
|
|
+ runConfig.DigitCount = digitCount;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(runConfig.MeterType == Constant.METER_TYPE_NUM_IND || runConfig.MeterType == Constant.METER_TYPE_IND)
|
|
|
+ {
|
|
|
+ if(string.IsNullOrWhiteSpace(cmbIndCount.Text) ||
|
|
|
+ !byte.TryParse(cmbIndCount.Text,out byte indCount) ||
|
|
|
+ !(indCount >0 && indCount <=10))
|
|
|
+ {
|
|
|
+ MessageBox.Show(Application.Current.MainWindow, "请输入指针个数", "提示",
|
|
|
+ MessageBoxButton.OK, MessageBoxImage.Warning);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ runConfig.IndCountWRFlag = true;
|
|
|
+ runConfig.IndCount = indCount;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (string.IsNullOrEmpty(cmbBrightVal.Text.Trim()) ||
|
|
|
+ !float.TryParse(cmbBrightVal.Text.Trim(),out float brightValue) ||
|
|
|
+ !(brightValue >= 0.8 && brightValue <= 2.0))
|
|
|
+ {
|
|
|
+ MessageBox.Show(Application.Current.MainWindow, "请输入正确的亮度系数", "提示",
|
|
|
+ MessageBoxButton.OK, MessageBoxImage.Warning);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ runConfig.BrightValueWRFlag = true;
|
|
|
+ runConfig.BrightValue = brightValue;
|
|
|
+
|
|
|
+ if(cmbLastUnit.SelectedItem == null)
|
|
|
+ {
|
|
|
+ MessageBox.Show(Application.Current.MainWindow, "请选择正确的尾数单位", "提示",
|
|
|
+ MessageBoxButton.OK, MessageBoxImage.Warning);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ runConfig.LastUnitLevelWRFlag = true;
|
|
|
+ runConfig.LastUnitLevel = (byte)cmbLastUnit.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.Text,out DateTime dtLatestTime))
|
|
|
+ {
|
|
|
+ MessageBox.Show(Application.Current.MainWindow, "请输入表底读数对应的时间", "提示",
|
|
|
+ MessageBoxButton.OK, MessageBoxImage.Warning);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ runConfig.LatestTimeWRFlag = true;
|
|
|
+ runConfig.LatestTime = dtLatestTime;
|
|
|
+
|
|
|
+ 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);
|
|
|
+ });
|
|
|
+ MessageBox.Show(Application.Current.MainWindow, $"设置设备运行参数{(blResult ? "成功" : "失败")}","提示",
|
|
|
+ MessageBoxButton.OK, blResult ? MessageBoxImage.Information: MessageBoxImage.Warning);
|
|
|
+ }
|
|
|
+ catch { }
|
|
|
+ finally
|
|
|
+ {
|
|
|
+ waitWindow.Close();
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
private void TextBox_PreviewTextInput(object sender, TextCompositionEventArgs e)
|
|
|
{
|
|
@@ -354,6 +672,62 @@ namespace MV485.uc
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ // 正则:匹配正整数或正小数(可只输入数字或带一个小数点)
|
|
|
+ private static readonly Regex _numberRegex = new Regex(@"^\d*\.?\d*$");
|
|
|
+ private void CmbBrightVal_PreviewTextInput(object sender, TextCompositionEventArgs e)
|
|
|
+ {
|
|
|
+ //ComboBox comboBox = sender as ComboBox;
|
|
|
+
|
|
|
+ //// 构造输入后的完整字符串
|
|
|
+ //string newText = comboBox.Text
|
|
|
+ // .Remove(comboBox.SelectionStart, comboBox.SelectionLength)
|
|
|
+ // .Insert(comboBox.SelectionStart, e.Text);
|
|
|
+
|
|
|
+ //// 验证规则:允许数字、最多一个小数点,且不能以多个小数点开头
|
|
|
+ //bool isValid = Regex.IsMatch(newText, @"^(\d+\.?\d*|\.\d+)$")
|
|
|
+ // && newText.Count(c => c == '.') <= 1;
|
|
|
+
|
|
|
+ //// 特殊处理:允许删除操作(空字符串)
|
|
|
+ //if (string.IsNullOrEmpty(newText))
|
|
|
+ //{
|
|
|
+ // e.Handled = false;
|
|
|
+ // return;
|
|
|
+ //}
|
|
|
+
|
|
|
+ //e.Handled = !isValid;
|
|
|
+ string fullText = GetProposedText((ComboBox)sender, e.Text);
|
|
|
+ e.Handled = !_numberRegex.IsMatch(fullText);
|
|
|
+ }
|
|
|
+ // 组合当前文本和新输入文本
|
|
|
+ private string GetProposedText(ComboBox comboBox, string newText)
|
|
|
+ {
|
|
|
+ var textBox = (comboBox.Template.FindName("PART_EditableTextBox", comboBox) as TextBox);
|
|
|
+ if (textBox == null) return newText;
|
|
|
+
|
|
|
+ string currentText = textBox.Text;
|
|
|
+ int selectionStart = textBox.SelectionStart;
|
|
|
+ int selectionLength = textBox.SelectionLength;
|
|
|
+
|
|
|
+ return currentText.Remove(selectionStart, selectionLength).Insert(selectionStart, newText);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void CmbBrightVal_Pasting(object sender, DataObjectPastingEventArgs e)
|
|
|
+ {
|
|
|
+ if (e.DataObject.GetDataPresent(typeof(string)))
|
|
|
+ {
|
|
|
+ string pasteText = (string)e.DataObject.GetData(typeof(string));
|
|
|
+ string fullText = GetProposedText((ComboBox)sender, pasteText);
|
|
|
+ if (!_numberRegex.IsMatch(fullText))
|
|
|
+ {
|
|
|
+ e.CancelCommand();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ e.CancelCommand();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
private void UserControl_SizeChanged(object sender, SizeChangedEventArgs e)
|
|
|
{
|
|
|
double totalWidth = lvLogs.ActualWidth;
|
|
@@ -383,6 +757,50 @@ namespace MV485.uc
|
|
|
File.AppendAllText(LogFilePath, $"{logEntry.Time} - {logEntry.Message}\n");
|
|
|
});
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ private bool GetSerialParameter(out string sPortName,out byte bDevId,out int iBaudrate)
|
|
|
+ {
|
|
|
+ sPortName = "";
|
|
|
+ bDevId = 0;
|
|
|
+ iBaudrate = 0;
|
|
|
+ //串口号
|
|
|
+ if (cmbPortNames.SelectedItem == null)
|
|
|
+ {
|
|
|
+ MessageBox.Show(Application.Current.MainWindow, "请选择串口", "提示",
|
|
|
+ MessageBoxButton.OK, MessageBoxImage.Warning);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ var portName = cmbPortNames.SelectedValue.ToString();
|
|
|
+ ConfigManager.Instance.UpdateConfig(ConfigKey.ConfigPortName, portName);
|
|
|
+
|
|
|
+ //波特率
|
|
|
+ if (cmbBaudrate.SelectedItem == null)
|
|
|
+ {
|
|
|
+ MessageBox.Show(Application.Current.MainWindow, "请选择波特率", "提示",
|
|
|
+ MessageBoxButton.OK, MessageBoxImage.Warning);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ var sBaudrate = cmbBaudrate.SelectedValue.ToString();
|
|
|
+ ConfigManager.Instance.UpdateConfig(ConfigKey.ConfigBaudrate, sBaudrate);
|
|
|
+
|
|
|
+ if (!byte.TryParse(cmbDevId.Text, out byte devid) || devid < 0 || devid > 247)
|
|
|
+ {
|
|
|
+ MessageBox.Show(Application.Current.MainWindow, "请输入正确的设备地址", "提示",
|
|
|
+ MessageBoxButton.OK, MessageBoxImage.Warning);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ ConfigManager.Instance.UpdateConfig(ConfigKey.ConfigDevId, devid.ToString());
|
|
|
+
|
|
|
+ int baudrate = int.Parse(sBaudrate);
|
|
|
+
|
|
|
+
|
|
|
+ sPortName = portName;
|
|
|
+ bDevId = devid;
|
|
|
+ iBaudrate = baudrate;
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
//------------------------------------------------------------------
|
|
|
}
|
|
|
}
|