Skip to content

Commit

Permalink
feat: 实现接收区数据暂停/恢复(允许)显示
Browse files Browse the repository at this point in the history
Signed-off-by: Leven <levenchn@163.com>
  • Loading branch information
leven99 committed Sep 18, 2019
1 parent 338fb61 commit 8e8f4ac
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 30 deletions.
55 changes: 52 additions & 3 deletions Models/RecvM.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ public int RecvDataCount
}
}

/* 接收区Header中的 [保存中/已停止] 字符串 */
/// <summary>
/// 接收区Header中的 [保存中/已停止] 字符串
/// </summary>
public string _RecvAutoSave;
public string RecvAutoSave
{
Expand All @@ -50,6 +52,29 @@ public string RecvAutoSave
}
}

/// <summary>
/// 接收区Header中的 [允许/暂停] 字符串
/// </summary>
public string _EnableRecv;
public string EnableRecv
{
get
{
return _EnableRecv;
}
set
{
if (_EnableRecv != value)
{
_EnableRecv = value;
RaisePropertyChanged(nameof(EnableRecv));
}
}
}

/// <summary>
/// 接收区Header字符串
/// </summary>
public string _RecvHeader;
public string RecvHeader
{
Expand All @@ -67,6 +92,26 @@ public string RecvHeader
}
}

/// <summary>
/// 接收区 - 允许/暂停接收数据
/// </summary>
public bool _Enable_Recv;
public bool Enable_Recv
{
get
{
return _Enable_Recv;
}
set
{
if(_Enable_Recv != value)
{
_Enable_Recv = value;
RaisePropertyChanged(nameof(Enable_Recv));
}
}
}

public ITextBoxAppend _RecvData;
public ITextBoxAppend RecvData
{
Expand All @@ -84,7 +129,9 @@ public ITextBoxAppend RecvData
}
}

/* 辅助区 - 十六进制接收 */
/// <summary>
/// 辅助区 - 十六进制接收
/// </summary>
public bool _HexRecv;
public bool HexRecv
{
Expand Down Expand Up @@ -122,8 +169,10 @@ public void RecvDataContext()
RecvData = new IClassTextBoxAppend();
RecvDataCount = 0;
RecvAutoSave = "已停止";
RecvHeader = "接收区:已接收" + RecvDataCount + "字节,接收自动保存[" + RecvAutoSave + "]";
EnableRecv = "(提示:双击文本框更改接收状态)";
RecvHeader = "接收区:已接收" + RecvDataCount + "字节,接收自动保存[" + RecvAutoSave + "]" + EnableRecv;

Enable_Recv = true;
HexRecv = false;
}
}
Expand Down
31 changes: 18 additions & 13 deletions Models/SendM.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,39 @@ namespace OSDA.Models
{
public class SendModel : MainWindowBase
{
public string _SendHeader;
public string SendHeader
public int _SendDataCount;
public int SendDataCount
{
get
{
return _SendHeader;
return _SendDataCount;
}
set
{
if (_SendHeader != value)
if (_SendDataCount != value)
{
_SendHeader = value;
RaisePropertyChanged(nameof(SendHeader));
_SendDataCount = value;
RaisePropertyChanged(nameof(SendDataCount));
}
}
}

public int _SendDataCount;
public int SendDataCount
/// <summary>
/// 发送区Header字符串
/// </summary>
public string _SendHeader;
public string SendHeader
{
get
{
return _SendDataCount;
return _SendHeader;
}
set
{
if (_SendDataCount != value)
if (_SendHeader != value)
{
_SendDataCount = value;
RaisePropertyChanged(nameof(SendDataCount));
_SendHeader = value;
RaisePropertyChanged(nameof(SendHeader));
}
}
}
Expand All @@ -56,7 +59,9 @@ public string SendData
}
}

/* 辅助区 - 自送发送的时间间隔 */
/// <summary>
/// 辅助区 - 自送发送的时间间隔
/// </summary>
public int _AutoSendNum;
public int AutoSendNum
{
Expand Down
4 changes: 3 additions & 1 deletion Models/TimerM.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ namespace OSDA.Models
{
public class TimerModel : MainWindowBase
{
/* 状态栏 - 系统时间 */
/// <summary>
/// 状态栏 - 系统时间
/// </summary>
string _SystemTime;
public string SystemTime
{
Expand Down
46 changes: 35 additions & 11 deletions ViewModels/MainWindowVM.cs
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,10 @@ public bool OpenSP()
SerialPortModel.SPStopBitsEnable = false;
SerialPortModel.SPParityEnable = false;

RecvModel.EnableRecv = "允许";
RecvModel.RecvHeader = "接收区:已接收" + RecvModel.RecvDataCount +
"字节,接收自动保存[" + RecvModel.RecvAutoSave + "],接收状态[" + RecvModel.EnableRecv + "]";

return true;
}
else
Expand Down Expand Up @@ -547,7 +551,7 @@ public bool CloseSP()

RecvModel.RecvAutoSave = "已停止";
RecvModel.RecvHeader = "接收区:已接收" + RecvModel.RecvDataCount +
"字节,接收自动保存[" + RecvModel.RecvAutoSave + "]";
"字节,接收自动保存[" + RecvModel.RecvAutoSave + "],接收状态[" + RecvModel.EnableRecv + "]";

return SPserialPort.IsOpen;
}
Expand Down Expand Up @@ -771,7 +775,8 @@ public void ClearSendData()
public void ClearCount()
{
RecvModel.RecvDataCount = 0;
RecvModel.RecvHeader = "接收区:已接收" + RecvModel.RecvDataCount + "字节,接收自动保存[" + RecvModel.RecvAutoSave + "]";
RecvModel.RecvHeader = "接收区:已接收" + RecvModel.RecvDataCount +
"字节,接收自动保存[" + RecvModel.RecvAutoSave + "],接收状态[" + RecvModel.EnableRecv + "]";

SendModel.SendDataCount = 0;
}
Expand All @@ -787,16 +792,19 @@ public void SerialPort_DataReceived(object sender, SerialDataReceivedEventArgs e

_SerialPort.Read(recvData, 0, _bytesToRead);

if (RecvModel.HexRecv)
if (RecvModel.Enable_Recv)
{
foreach (var tmp in recvData)
if (RecvModel.HexRecv)
{
RecvModel.RecvData.Append(string.Format("{0:X2} ", tmp));
foreach (var tmp in recvData)
{
RecvModel.RecvData.Append(string.Format("{0:X2} ", tmp));
}
}
else
{
RecvModel.RecvData.Append(_SerialPort.Encoding.GetString(recvData));
}
}
else
{
RecvModel.RecvData.Append(_SerialPort.Encoding.GetString(recvData));
}

if (SaveRecv)
Expand All @@ -813,7 +821,7 @@ public void SerialPort_DataReceived(object sender, SerialDataReceivedEventArgs e
RecvModel.RecvDataCount += recvData.Length;

RecvModel.RecvHeader = "接收区:已接收" + RecvModel.RecvDataCount +
"字节,接收自动保存[" + RecvModel.RecvAutoSave + "]";
"字节,接收自动保存[" + RecvModel.RecvAutoSave + "],接收状态[" + RecvModel.EnableRecv + "]";

if (RecvModel.RecvDataCount > (32768 * RecvModel.RecvDataDeleteCount))
{
Expand Down Expand Up @@ -852,7 +860,23 @@ public async void SaveRecvData(string ReceData)

RecvModel.RecvAutoSave = "已停止";
RecvModel.RecvHeader = "接收区:已接收" + RecvModel.RecvDataCount +
"字节,接收自动保存[" + RecvModel.RecvAutoSave + "]";
"字节,接收自动保存[" + RecvModel.RecvAutoSave + "],接收状态[" + RecvModel.EnableRecv + "]";
}
}
#endregion

#region RecvTextBox Mouse Double Support
public void Enable_Recv()
{
RecvModel.Enable_Recv = !RecvModel.Enable_Recv;

if(RecvModel.Enable_Recv)
{
RecvModel.EnableRecv = "允许";
}
else
{
RecvModel.EnableRecv = "暂停";
}
}
#endregion
Expand Down
2 changes: 1 addition & 1 deletion Views/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
<GroupBox x:Name="ReceDataGroupBox" Header="{Binding RecvModel.RecvHeader}" Grid.Row="0" Margin="5,0,2,0"
BorderBrush="#FF007ACD">
<TextBox x:Name="RecvTextBox" Style="{StaticResource RSTextBox}"
TextChanged="RecvTextBox_TextChanged"
TextChanged="RecvTextBox_TextChanged" MouseDoubleClick="RecvTextBox_MouseDoubleClick"
local:MvvmTextBox.Buffer="{Binding RecvModel.RecvData}" IsReadOnly="True"
Width="466" Height="288"/>
</GroupBox>
Expand Down
9 changes: 8 additions & 1 deletion Views/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public MainWindow()
DataContext = mainWindowViewModel;
}

#region Mouse move Support
#region Menu Mouse movement Support
private void MouseMove_Click(object sender, System.Windows.Input.MouseEventArgs e)
{
if (e.LeftButton == MouseButtonState.Pressed)
Expand Down Expand Up @@ -221,6 +221,13 @@ private void ClearCount(object sender, RoutedEventArgs e)
}
#endregion

#region RecvTextBox Mouse Double Support
private void RecvTextBox_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{
mainWindowViewModel.Enable_Recv();
}
#endregion

#region RecvTextBox ScrollToEnd Support
private void RecvTextBox_TextChanged(object sender, TextChangedEventArgs e)
{
Expand Down

0 comments on commit 8e8f4ac

Please sign in to comment.