Skip to content

Commit

Permalink
Optimize receiving data from COM-port
Browse files Browse the repository at this point in the history
  • Loading branch information
VNovytskyi committed Apr 1, 2020
1 parent 186f225 commit 397a187
Show file tree
Hide file tree
Showing 25 changed files with 28 additions and 69 deletions.
Binary file modified WpfApp1/.vs/WpfApp1/v16/.suo
Binary file not shown.
Binary file modified WpfApp1/.vs/WpfApp1/v16/Server/sqlite3/storage.ide
Binary file not shown.
3 changes: 1 addition & 2 deletions WpfApp1/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApp1"
mc:Ignorable="d"
Title="Port monitor v0.0" Height="519.6" Width="853.6">
Title="Port monitor v0.1" Height="519.6" Width="853.6">
<Grid Margin="0,0,-0.4,3">
<GroupBox Header="Display" HorizontalAlignment="Left" Height="178" Margin="672,10,0,0" VerticalAlignment="Top" Width="156" FontSize="14"/>
<RichTextBox FontSize="14" Padding="0 3 0 0" x:Name="outputField" HorizontalAlignment="Left" Height="404" Margin="226,63,0,0" VerticalAlignment="Top" Width="437">
Expand Down Expand Up @@ -46,6 +46,5 @@
<CheckBox x:Name="ClearInputFieldAfterSendCheckBox" Content="Clear after send" HorizontalAlignment="Left" Margin="691,302,0,0" VerticalAlignment="Top" FontSize="14"/>
<CheckBox x:Name="AutoConnectToPortCheckBox" IsChecked="True" Content="Auto connect" HorizontalAlignment="Left" Margin="691,325,0,0" VerticalAlignment="Top" FontSize="14"/>
<CheckBox x:Name="ColorOutputCheckBox" IsChecked="True" Content="Color RX output" HorizontalAlignment="Left" Margin="691,348,0,0" VerticalAlignment="Top" FontSize="14"/>
<Button Content="Привет" HorizontalAlignment="Left" Margin="719,393,0,0" VerticalAlignment="Top" Width="75" Click="Button_Click_3"/>
</Grid>
</Window>
54 changes: 23 additions & 31 deletions WpfApp1/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ private void RefreshCurrentComPortStateFunc()
StopConnection();
WriteSystemLog("Connection is broken");
}

Thread.Sleep(100);
}
}

Expand Down Expand Up @@ -369,9 +371,7 @@ private void ConnectToComPortFunc()

WriteSystemLog("Connection successful");

ReceiverData = new Thread(ReceiverDataFunc);
ReceiverData.IsBackground = true;
ReceiverData.Start();
serialPort.DataReceived += new SerialDataReceivedEventHandler(ReceiverDataFunc);
}

private void DisconnectToComPortButton_Click(object sender, RoutedEventArgs e)
Expand Down Expand Up @@ -463,40 +463,32 @@ private void TransiverDataFunc(object str)

}

private void ReceiverDataFunc()
private void ReceiverDataFunc(object sender, SerialDataReceivedEventArgs e)
{
SerialPort sp = (SerialPort)sender;
string str = String.Empty;

while (true)
try
{
str = String.Empty;

try
{
//str += serialPort.ReadExisting();
str += serialPort.ReadLine();
}
catch (Exception e)
{
//WriteLog(e.Message);
return;
}
str = serialPort.ReadLine();
}
catch (Exception ex)
{
WriteLog(ex.Message);
return;
}

Dispatcher.Invoke(() =>
Dispatcher.Invoke(() =>
{
if (!String.IsNullOrEmpty(str) && DisplayReceiverDataCheckBox.IsChecked == true)
{
if (!String.IsNullOrEmpty(str) && DisplayReceiverDataCheckBox.IsChecked == true)
{
if (DisplaySenderCheckBox.IsChecked == true)
str = "[ Port ] " + str;
str = str.Trim(new Char[] { '\n', '\r' });
WriteLog(str);
}
});


Thread.Sleep(10);
}
if (DisplaySenderCheckBox.IsChecked == true)
str = "[ Port ] " + str;
str = str.Trim(new Char[] { '\n', '\r' });
WriteLog(str);
}
});
}

private void Button_Click_2(object sender, RoutedEventArgs e)
Expand Down
Binary file modified WpfApp1/bin/Debug/WpfApp1.exe
Binary file not shown.
Binary file modified WpfApp1/bin/Debug/WpfApp1.pdb
Binary file not shown.
Binary file modified WpfApp1/bin/Release/WpfApp1.exe
Binary file not shown.
Binary file modified WpfApp1/bin/Release/WpfApp1.pdb
Binary file not shown.
Binary file modified WpfApp1/obj/Debug/MainWindow.baml
Binary file not shown.
10 changes: 1 addition & 9 deletions WpfApp1/obj/Debug/MainWindow.g.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#pragma checksum "..\..\MainWindow.xaml" "{8829d00f-11b8-4213-878b-770e8597ac16}" "C95FAE40A185335EE666EC6816B1B5F2C5DF1F41A79CE8EBF3655EE3EA4F7D5A"
#pragma checksum "..\..\MainWindow.xaml" "{8829d00f-11b8-4213-878b-770e8597ac16}" "DACABD2A085A281E6CE2881AB8C618F358B3EAEE33E4706D76649A01C5A384F0"
//------------------------------------------------------------------------------
// <auto-generated>
// Этот код создан программой.
Expand Down Expand Up @@ -341,14 +341,6 @@ void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object
case 23:
this.ColorOutputCheckBox = ((System.Windows.Controls.CheckBox)(target));
return;
case 24:

#line 49 "..\..\MainWindow.xaml"
((System.Windows.Controls.Button)(target)).Click += new System.Windows.RoutedEventHandler(this.Button_Click_3);

#line default
#line hidden
return;
}
this._contentLoaded = true;
}
Expand Down
10 changes: 1 addition & 9 deletions WpfApp1/obj/Debug/MainWindow.g.i.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#pragma checksum "..\..\MainWindow.xaml" "{8829d00f-11b8-4213-878b-770e8597ac16}" "C95FAE40A185335EE666EC6816B1B5F2C5DF1F41A79CE8EBF3655EE3EA4F7D5A"
#pragma checksum "..\..\MainWindow.xaml" "{8829d00f-11b8-4213-878b-770e8597ac16}" "DACABD2A085A281E6CE2881AB8C618F358B3EAEE33E4706D76649A01C5A384F0"
//------------------------------------------------------------------------------
// <auto-generated>
// Этот код создан программой.
Expand Down Expand Up @@ -341,14 +341,6 @@ void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object
case 23:
this.ColorOutputCheckBox = ((System.Windows.Controls.CheckBox)(target));
return;
case 24:

#line 49 "..\..\MainWindow.xaml"
((System.Windows.Controls.Button)(target)).Click += new System.Windows.RoutedEventHandler(this.Button_Click_3);

#line default
#line hidden
return;
}
this._contentLoaded = true;
}
Expand Down
Binary file not shown.
Binary file modified WpfApp1/obj/Debug/WpfApp1.csprojAssemblyReference.cache
Binary file not shown.
Binary file modified WpfApp1/obj/Debug/WpfApp1.exe
Binary file not shown.
Binary file modified WpfApp1/obj/Debug/WpfApp1.g.resources
Binary file not shown.
Binary file modified WpfApp1/obj/Debug/WpfApp1.pdb
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified WpfApp1/obj/Release/MainWindow.baml
Binary file not shown.
10 changes: 1 addition & 9 deletions WpfApp1/obj/Release/MainWindow.g.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#pragma checksum "..\..\MainWindow.xaml" "{8829d00f-11b8-4213-878b-770e8597ac16}" "C95FAE40A185335EE666EC6816B1B5F2C5DF1F41A79CE8EBF3655EE3EA4F7D5A"
#pragma checksum "..\..\MainWindow.xaml" "{8829d00f-11b8-4213-878b-770e8597ac16}" "DACABD2A085A281E6CE2881AB8C618F358B3EAEE33E4706D76649A01C5A384F0"
//------------------------------------------------------------------------------
// <auto-generated>
// Этот код создан программой.
Expand Down Expand Up @@ -341,14 +341,6 @@ void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object
case 23:
this.ColorOutputCheckBox = ((System.Windows.Controls.CheckBox)(target));
return;
case 24:

#line 49 "..\..\MainWindow.xaml"
((System.Windows.Controls.Button)(target)).Click += new System.Windows.RoutedEventHandler(this.Button_Click_3);

#line default
#line hidden
return;
}
this._contentLoaded = true;
}
Expand Down
10 changes: 1 addition & 9 deletions WpfApp1/obj/Release/MainWindow.g.i.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#pragma checksum "..\..\MainWindow.xaml" "{8829d00f-11b8-4213-878b-770e8597ac16}" "C95FAE40A185335EE666EC6816B1B5F2C5DF1F41A79CE8EBF3655EE3EA4F7D5A"
#pragma checksum "..\..\MainWindow.xaml" "{8829d00f-11b8-4213-878b-770e8597ac16}" "DACABD2A085A281E6CE2881AB8C618F358B3EAEE33E4706D76649A01C5A384F0"
//------------------------------------------------------------------------------
// <auto-generated>
// Этот код создан программой.
Expand Down Expand Up @@ -341,14 +341,6 @@ void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object
case 23:
this.ColorOutputCheckBox = ((System.Windows.Controls.CheckBox)(target));
return;
case 24:

#line 49 "..\..\MainWindow.xaml"
((System.Windows.Controls.Button)(target)).Click += new System.Windows.RoutedEventHandler(this.Button_Click_3);

#line default
#line hidden
return;
}
this._contentLoaded = true;
}
Expand Down
Binary file modified WpfApp1/obj/Release/WpfApp1.csprojAssemblyReference.cache
Binary file not shown.
Binary file modified WpfApp1/obj/Release/WpfApp1.exe
Binary file not shown.
Binary file modified WpfApp1/obj/Release/WpfApp1.g.resources
Binary file not shown.
Binary file modified WpfApp1/obj/Release/WpfApp1.pdb
Binary file not shown.

0 comments on commit 397a187

Please sign in to comment.