master
phkim 3 years ago
parent 245071c98f
commit d6b046c8cb
  1. 22
      RS232Test.sln
  2. 6
      RS232Test/App.config
  3. 184
      RS232Test/Form1.Designer.cs
  4. 220
      RS232Test/Form1.cs
  5. 1922
      RS232Test/Form1.resx
  6. 22
      RS232Test/Program.cs
  7. 36
      RS232Test/Properties/AssemblyInfo.cs
  8. 71
      RS232Test/Properties/Resources.Designer.cs
  9. 117
      RS232Test/Properties/Resources.resx
  10. 30
      RS232Test/Properties/Settings.Designer.cs
  11. 7
      RS232Test/Properties/Settings.settings
  12. 89
      RS232Test/RS232Test.csproj
  13. 52
      RS232Test/Temp.cs

@ -0,0 +1,22 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013
VisualStudioVersion = 12.0.31101.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RS232Test", "RS232Test\RS232Test.csproj", "{A1EA117E-75DC-4434-9AD3-F2A57B0AD891}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{A1EA117E-75DC-4434-9AD3-F2A57B0AD891}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A1EA117E-75DC-4434-9AD3-F2A57B0AD891}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A1EA117E-75DC-4434-9AD3-F2A57B0AD891}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A1EA117E-75DC-4434-9AD3-F2A57B0AD891}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
</configuration>

@ -0,0 +1,184 @@
namespace RS232Test
{
partial class Form1
{
/// <summary>
/// 필수 디자이너 변수입니다.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// 사용 중인 모든 리소스를 정리합니다.
/// </summary>
/// <param name="disposing">관리되는 리소스를 삭제해야 하면 true이고, 그렇지 않으면 false입니다.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form 디자이너에서 생성한 코드
/// <summary>
/// 디자이너 지원에 필요한 메서드입니다.
/// 이 메서드의 내용을 코드 편집기로 수정하지 마십시오.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1));
this.serialPort = new System.IO.Ports.SerialPort(this.components);
this.portComboBox = new System.Windows.Forms.ComboBox();
this.Connect = new System.Windows.Forms.Button();
this.printText = new System.Windows.Forms.TextBox();
this.commandText = new System.Windows.Forms.TextBox();
this.Send = new System.Windows.Forms.Button();
this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel();
this.tableLayoutPanel2 = new System.Windows.Forms.TableLayoutPanel();
this.tableLayoutPanel3 = new System.Windows.Forms.TableLayoutPanel();
this.tableLayoutPanel1.SuspendLayout();
this.tableLayoutPanel2.SuspendLayout();
this.tableLayoutPanel3.SuspendLayout();
this.SuspendLayout();
//
// serialPort
//
this.serialPort.DataReceived += new System.IO.Ports.SerialDataReceivedEventHandler(this.serialPort_DataReceived);
//
// portComboBox
//
this.portComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.portComboBox.FormattingEnabled = true;
this.portComboBox.Location = new System.Drawing.Point(3, 3);
this.portComboBox.Name = "portComboBox";
this.portComboBox.Size = new System.Drawing.Size(121, 20);
this.portComboBox.TabIndex = 0;
this.portComboBox.SelectedIndexChanged += new System.EventHandler(this.portComboBox_SelectedIndexChanged);
//
// Connect
//
this.Connect.Dock = System.Windows.Forms.DockStyle.Fill;
this.Connect.Location = new System.Drawing.Point(297, 3);
this.Connect.Name = "Connect";
this.Connect.Size = new System.Drawing.Size(94, 23);
this.Connect.TabIndex = 1;
this.Connect.Text = "연결";
this.Connect.UseVisualStyleBackColor = true;
this.Connect.Click += new System.EventHandler(this.Connect_Click);
//
// printText
//
this.printText.Dock = System.Windows.Forms.DockStyle.Fill;
this.printText.Location = new System.Drawing.Point(3, 38);
this.printText.Multiline = true;
this.printText.Name = "printText";
this.printText.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
this.printText.Size = new System.Drawing.Size(394, 366);
this.printText.TabIndex = 2;
//
// commandText
//
this.commandText.Dock = System.Windows.Forms.DockStyle.Fill;
this.commandText.Location = new System.Drawing.Point(3, 3);
this.commandText.Name = "commandText";
this.commandText.Size = new System.Drawing.Size(288, 21);
this.commandText.TabIndex = 3;
//
// Send
//
this.Send.Dock = System.Windows.Forms.DockStyle.Fill;
this.Send.Location = new System.Drawing.Point(297, 3);
this.Send.Name = "Send";
this.Send.Size = new System.Drawing.Size(94, 23);
this.Send.TabIndex = 4;
this.Send.Text = "전송";
this.Send.UseVisualStyleBackColor = true;
this.Send.Click += new System.EventHandler(this.Send_Click);
//
// tableLayoutPanel1
//
this.tableLayoutPanel1.BackColor = System.Drawing.Color.White;
this.tableLayoutPanel1.ColumnCount = 1;
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F));
this.tableLayoutPanel1.Controls.Add(this.tableLayoutPanel2, 0, 0);
this.tableLayoutPanel1.Controls.Add(this.tableLayoutPanel3, 0, 2);
this.tableLayoutPanel1.Controls.Add(this.printText, 0, 1);
this.tableLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill;
this.tableLayoutPanel1.Location = new System.Drawing.Point(0, 0);
this.tableLayoutPanel1.Name = "tableLayoutPanel1";
this.tableLayoutPanel1.RowCount = 3;
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 35F));
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F));
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 35F));
this.tableLayoutPanel1.Size = new System.Drawing.Size(400, 442);
this.tableLayoutPanel1.TabIndex = 5;
//
// tableLayoutPanel2
//
this.tableLayoutPanel2.BackColor = System.Drawing.Color.White;
this.tableLayoutPanel2.ColumnCount = 2;
this.tableLayoutPanel2.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F));
this.tableLayoutPanel2.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 100F));
this.tableLayoutPanel2.Controls.Add(this.Connect, 1, 0);
this.tableLayoutPanel2.Controls.Add(this.portComboBox, 0, 0);
this.tableLayoutPanel2.Dock = System.Windows.Forms.DockStyle.Fill;
this.tableLayoutPanel2.Location = new System.Drawing.Point(3, 3);
this.tableLayoutPanel2.Name = "tableLayoutPanel2";
this.tableLayoutPanel2.RowCount = 1;
this.tableLayoutPanel2.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F));
this.tableLayoutPanel2.Size = new System.Drawing.Size(394, 29);
this.tableLayoutPanel2.TabIndex = 6;
//
// tableLayoutPanel3
//
this.tableLayoutPanel3.BackColor = System.Drawing.Color.White;
this.tableLayoutPanel3.ColumnCount = 2;
this.tableLayoutPanel3.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F));
this.tableLayoutPanel3.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 100F));
this.tableLayoutPanel3.Controls.Add(this.Send, 1, 0);
this.tableLayoutPanel3.Controls.Add(this.commandText, 0, 0);
this.tableLayoutPanel3.Dock = System.Windows.Forms.DockStyle.Fill;
this.tableLayoutPanel3.Location = new System.Drawing.Point(3, 410);
this.tableLayoutPanel3.Name = "tableLayoutPanel3";
this.tableLayoutPanel3.RowCount = 1;
this.tableLayoutPanel3.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F));
this.tableLayoutPanel3.Size = new System.Drawing.Size(394, 29);
this.tableLayoutPanel3.TabIndex = 6;
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BackColor = System.Drawing.Color.White;
this.ClientSize = new System.Drawing.Size(400, 442);
this.Controls.Add(this.tableLayoutPanel1);
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.Name = "Form1";
this.Text = "RS232테스트";
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.Form1_FormClosing);
this.tableLayoutPanel1.ResumeLayout(false);
this.tableLayoutPanel1.PerformLayout();
this.tableLayoutPanel2.ResumeLayout(false);
this.tableLayoutPanel3.ResumeLayout(false);
this.tableLayoutPanel3.PerformLayout();
this.ResumeLayout(false);
}
#endregion
private System.IO.Ports.SerialPort serialPort;
private System.Windows.Forms.Button Connect;
private System.Windows.Forms.TextBox printText;
private System.Windows.Forms.ComboBox portComboBox;
private System.Windows.Forms.TextBox commandText;
private System.Windows.Forms.Button Send;
private System.Windows.Forms.TableLayoutPanel tableLayoutPanel1;
private System.Windows.Forms.TableLayoutPanel tableLayoutPanel2;
private System.Windows.Forms.TableLayoutPanel tableLayoutPanel3;
}
}

@ -0,0 +1,220 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO.Ports;
namespace RS232Test
{
public partial class Form1 : Form
{
private string portName;
private const char STX = (char)0x02;
private const char CR = (char)0x0D;
private const char LF = (char)0x0A;
private string inStream = "";
private object receiveLock = new object();
public Form1()
{
InitializeComponent();
InitInstance();
}
private void InitInstance()
{
GetPortNames();
}
private void GetPortNames()
{
DataTable portTable = new DataTable();
portTable.Columns.Add("VALUE", typeof(string));
string[] portNames = SerialPort.GetPortNames();
if (portNames.Length < 1)
return;
for (int i = 0; i < portNames.Length; i++)
{
portTable.Rows.Add(portNames[i]);
}
portComboBox.DataSource = portTable.DefaultView;
portComboBox.ValueMember = "VALUE";
}
private void PortOpen()
{
if (!serialPort.IsOpen)
serialPort.Open();
Print(string.Format("\t[CMD] {0} {1}", DateTime.Now.ToString("yyyy.MM.dd HH:mm:ss"), portName + "포트 연결"));
}
private void PortClose()
{
if (serialPort.IsOpen)
serialPort.Close();
Print(string.Format("\t[CMD] {0} {1}", DateTime.Now.ToString("yyyy.MM.dd HH:mm:ss"), portName + "포트 해제"));
}
private void Connect_Click(object sender, EventArgs e)
{
try
{
if (string.IsNullOrEmpty(portName))
{
MessageBox.Show("포트를 선택해주십시오.");
return;
}
if (Connect.Text == "연결")
{
PortOpen();
Connect.Text = "해제";
}
else
{
PortClose();
Connect.Text = "연결";
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void Print(string message)
{
printText.AppendText(message + Environment.NewLine);
}
private void serialPort_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
{
try
{
lock(receiveLock)
{
this.Invoke(new EventHandler(DataReceived));
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
private void DataReceived(object sender, EventArgs e)
{
string data = serialPort.ReadExisting();
if (data.Length < 1)
return;
inStream = String.Concat(inStream, data);
string message = EqTocReceive(inStream);
EqTocPrint(message);
}
private string EqTocReceive(string stream)
{
int etxIndex = inStream.IndexOf("\r\n");
if (etxIndex < 0)
return null;
string message = inStream.Substring(0, etxIndex);
inStream = inStream.Substring(etxIndex + 2, inStream.Length - etxIndex - 2);
return message;
}
private void EqTocPrint(string message)
{
if (string.IsNullOrEmpty(message))
return;
if (commandText.Text.ToUpper() != "RD")
{
Print(message);
return;
}
string[] tmp = message.Split(' ');
if (tmp.Length < 4)
{
Print(message);
return;
}
List<string> values = new List<string>();
for (int i = 0; i < tmp.Length; i++)
{
if (string.IsNullOrEmpty(tmp[i]))
continue;
values.Add(tmp[i]);
}
// 시간 "yyyy-MM-dd HH:mm:ss"
DateTime now = DateTime.Now;
string timeString = string.Format("{0}.{1}.{2} ", now.Year, now.Month.ToString("D2"), now.Day.ToString("D2")) + values[0];
DateTime timeStamp = DateTime.ParseExact(timeString, "yyyy.MM.dd HH:mm:ss", null);
// TOC
double toc = double.Parse(values[1]);
// 전기저항값
double res = double.Parse(values[2]);
// 온도
double temp = double.Parse(values[3]);
string formatted = string.Format(@"시간: {0}
TOC: {1} ppb
: {2} ·cm
: {3} ", timeStamp.ToString(), toc, res, temp);
Print(formatted);
}
private void portComboBox_SelectedIndexChanged(object sender, EventArgs e)
{
DataRowView rowView = portComboBox.SelectedItem as DataRowView;
if (rowView == null)
return;
portName = rowView.Row["VALUE"].ToString();
serialPort.PortName = portName;
}
private void Send_Click(object sender, EventArgs e)
{
string command = commandText.Text + "\r\n";
if (!serialPort.IsOpen)
{
MessageBox.Show("포트가 열려있지 않습니다.");
return;
}
Print(string.Format("\t[CMD] {0} {1}", DateTime.Now.ToString("yyyy.MM.dd HH:mm:ss"), commandText.Text));
serialPort.Write(command);
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
if (serialPort.IsOpen)
serialPort.Close();
}
}
}

File diff suppressed because it is too large Load Diff

@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace RS232Test
{
static class Program
{
/// <summary>
/// 해당 응용 프로그램의 주 진입점입니다.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}

@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// 어셈블리의 일반 정보는 다음 특성 집합을 통해 제어됩니다.
// 어셈블리와 관련된 정보를 수정하려면
// 이 특성 값을 변경하십시오.
[assembly: AssemblyTitle("RS232Test")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("RS232Test")]
[assembly: AssemblyCopyright("Copyright © 2022")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// ComVisible을 false로 설정하면 이 어셈블리의 형식이 COM 구성 요소에
// 표시되지 않습니다. COM에서 이 어셈블리의 형식에 액세스하려면
// 해당 형식에 대해 ComVisible 특성을 true로 설정하십시오.
[assembly: ComVisible(false)]
// 이 프로젝트가 COM에 노출되는 경우 다음 GUID는 typelib의 ID를 나타냅니다.
[assembly: Guid("81fe9e40-1f12-4275-ba5b-867be8fd7ffa")]
// 어셈블리의 버전 정보는 다음 네 가지 값으로 구성됩니다.
//
// 주 버전
// 부 버전
// 빌드 번호
// 수정 버전
//
// 모든 값을 지정하거나 아래와 같이 '*'를 사용하여 빌드 번호 및 수정 버전이 자동으로
// 지정되도록 할 수 있습니다.
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

@ -0,0 +1,71 @@
//------------------------------------------------------------------------------
// <auto-generated>
// 이 코드는 도구를 사용하여 생성되었습니다.
// 런타임 버전:4.0.30319.42000
//
// 파일 내용을 변경하면 잘못된 동작이 발생할 수 있으며, 코드를 다시 생성하면
// 이러한 변경 내용이 손실됩니다.
// </auto-generated>
//------------------------------------------------------------------------------
namespace RS232Test.Properties
{
/// <summary>
/// 지역화된 문자열 등을 찾기 위한 강력한 형식의 리소스 클래스입니다.
/// </summary>
// 이 클래스는 ResGen 또는 Visual Studio와 같은 도구를 통해 StronglyTypedResourceBuilder
// 클래스에서 자동으로 생성되었습니다.
// 멤버를 추가하거나 제거하려면 .ResX 파일을 편집한 다음 /str 옵션을 사용하여
// ResGen을 다시 실행하거나 VS 프로젝트를 다시 빌드하십시오.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resources
{
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal Resources()
{
}
/// <summary>
/// 이 클래스에서 사용하는 캐시된 ResourceManager 인스턴스를 반환합니다.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager
{
get
{
if ((resourceMan == null))
{
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("RS232Test.Properties.Resources", typeof(Resources).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
/// <summary>
/// 이 강력한 형식의 리소스 클래스를 사용하여 모든 리소스 조회에 대한 현재 스레드의 CurrentUICulture
/// 속성을 재정의합니다.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture
{
get
{
return resourceCulture;
}
set
{
resourceCulture = value;
}
}
}
}

@ -0,0 +1,117 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

@ -0,0 +1,30 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace RS232Test.Properties
{
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")]
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase
{
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
public static Settings Default
{
get
{
return defaultInstance;
}
}
}
}

@ -0,0 +1,7 @@
<?xml version='1.0' encoding='utf-8'?>
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)">
<Profiles>
<Profile Name="(Default)" />
</Profiles>
<Settings />
</SettingsFile>

@ -0,0 +1,89 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{A1EA117E-75DC-4434-9AD3-F2A57B0AD891}</ProjectGuid>
<OutputType>WinExe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>RS232Test</RootNamespace>
<AssemblyName>RS232Test</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Deployment" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Form1.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Form1.Designer.cs">
<DependentUpon>Form1.cs</DependentUpon>
</Compile>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Temp.cs" />
<EmbeddedResource Include="Form1.resx">
<DependentUpon>Form1.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
<SubType>Designer</SubType>
</EmbeddedResource>
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None>
<Compile Include="Properties\Settings.Designer.cs">
<AutoGen>True</AutoGen>
<DependentUpon>Settings.settings</DependentUpon>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
</Compile>
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

@ -0,0 +1,52 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO.Ports;
namespace RS232Test
{
class Temp
{
private const char STX = (char)0x02;
private const char ETX1 = (char)0x0D;
private const char ETX2 = (char)0x0A;
private string inStream = "";
private SerialPort serialPort = new SerialPort();
private void DataReceived(object sender, EventArgs e)
{
string data = serialPort.ReadExisting();
//printText.AppendText(data);
char[] startCheckArr = data.ToCharArray();
if (startCheckArr.Length < 1)
return;
if (startCheckArr[0] == STX)
inStream = data;
string[] splited = inStream.Split(STX);
foreach (string content in splited)
{
char[] endCheckArr = content.ToCharArray();
if (endCheckArr.Length < 1)
continue;
int etxIndex = Array.IndexOf(endCheckArr, ETX1);
if (etxIndex < 1)
continue;
etxIndex = Array.IndexOf(endCheckArr, ETX2);
if (etxIndex < 1)
continue;
string message = content.Substring(0, etxIndex);
//DoWork(message);
}
}
}
}
Loading…
Cancel
Save