Skip to content

Commit

Permalink
修复当串口接收指定个数与实际个数对应不上的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
cnxy committed May 17, 2021
1 parent 8c715fd commit dfb2859
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 15 deletions.
22 changes: 11 additions & 11 deletions VISAInstrument/FrmMain.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 19 additions & 2 deletions VISAInstrument/FrmMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,13 @@ private void radioButton_CheckedChanged(object sender, EventArgs e)
{
if(rbtRS232 == sender as RadioButton)
{
rdoSpecifiedCount.Text = "读取指定字节数量";
this.tableLayoutPanel.RowStyles[2].Height = 35F;
this.tableLayoutPanel.RowStyles[3].Height = 0F;
this.tableLayoutPanel.RowStyles[3].Height = 0F;

return;
}
rdoSpecifiedCount.Text = "读取指定字节数量或收到结束符";
if (rbtLAN == sender as RadioButton)
{
this.tableLayoutPanel.RowStyles[2].Height = 0F;
Expand Down Expand Up @@ -375,7 +378,10 @@ private void btnOpen_Click(object sender, EventArgs e)
chkRealTimeReceive.Enabled = true;
BindOrRemoveDataReceivedEvent();
}
else chkRealTimeReceive.Enabled = false;
else
{
chkRealTimeReceive.Enabled = false;
}

EnableControl(false);
chkStartCycle_CheckedChanged(null, null);
Expand Down Expand Up @@ -583,6 +589,17 @@ private void rdoAsciiByte_CheckedChanged(object sender, EventArgs e)

private void rdoUntilNewLineSpecifiedCount_CheckedChanged(object sender, EventArgs e)
{
if (_portOperatorBase is RS232PortOperator portOperator)
{
if (rdoUntilNewLine.Checked)
{
portOperator.SetReadTerminationCharacterEnabled(true);
}
else
{
portOperator.SetReadTerminationCharacterEnabled(false);
}
}
nudSpecifiedCount.Enabled = !rdoUntilNewLine.Checked;
}

Expand Down
5 changes: 5 additions & 0 deletions VISAInstrument/Port/PortOperator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ public RS232PortOperator(string address,int baudRate,SerialParity parity, Serial
serialSession = (SerialSession)Session;
}

public void SetReadTerminationCharacterEnabled(bool enabled)
{
serialSession.ReadTermination = enabled?SerialTerminationMethod.TerminationCharacter: SerialTerminationMethod.None;
}

public override void Open()
{
base.Open();
Expand Down
4 changes: 2 additions & 2 deletions VISAInstrument/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号
// 方法是按如下所示使用“*”: :
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.3.0.4")]
[assembly: AssemblyFileVersion("1.3.0.4")]
[assembly: AssemblyVersion("1.3.0.5")]
[assembly: AssemblyFileVersion("1.3.0.5")]

0 comments on commit dfb2859

Please sign in to comment.