資源簡(jiǎn)介
用C#些的串口與歐姆龍PLC之間的通信,自動(dòng)計(jì)算校驗(yàn)碼,使用hostlink協(xié)議進(jìn)行通信.用計(jì)算機(jī)做串口通信的朋友也可以借鑒其中關(guān)于串口操作的代碼

代碼片段和文件信息
using?System;
using?System.Collections.Generic;
using?System.ComponentModel;
using?System.Data;
using?System.Drawing;
using?System.Text;
using?System.Windows.Forms;
namespace?ascii碼串口調(diào)試
{
????public?partial?class?Form1?:?Form
????{
????????int?intFcs;
????????string?received;
????????public?Form1()
????????{
????????????InitializeComponent();
????????}
????????//SEND
????????private?void?button1_Click(object?sender?EventArgs?e)
????????{
????????????string?str?=?textBox1.Text;
????????????int?n;
????????????int?l?=?str.Length;
????????????char?m?=?‘\0‘;
????????????for?(int?i?=?0;?i?????????????{
????????????????n?=?str[i]?^?m;
????????????????m?=?(char)(n);
????????????}
????????????n?=?(int)(m);
????????????textBox3.Text?=?““;
????????????textBox3.Text?=?textBox1.Text?+?String.Format(“{0:x}“?n)?+?“*\r“;
????????????try
????????????{
????????????????if?(serialPort1.IsOpen)
????????????????{
????????????????????serialPort1.Close();
????????????????????serialPort1.Open();?//打開串口
????????????????}
????????????????else
????????????????{
????????????????????serialPort1.Open();//打開串口
????????????????}
????????????}
????????????catch
????????????{
????????????????MessageBox.Show(“串口不存在或被占用“);
????????????}
????????????received?=?““;
????????????string?strSend?=?textBox3.Text;
????????????serialPort1.Write(strSend);?//接收串口數(shù)據(jù)方法:事件serialport_datareceived、readExisting、read(byte[]intint)、readbyte()
????????????
????????}
????????private?void?serialPort1_DataReceived(object?sender?System.IO.Ports.SerialDataReceivedEventArgs?e)
????????{
????????????received?=?received+serialPort1.ReadExisting();
????????}
????????//RECEIVED
????????private?void?button2_Click(object?sender?EventArgs?e)
????????{
????????????textBox2.Text?=?received;
????????????received?=?““;
????????}
????????//CLose
????????private?void?button3_Click(object?sender?EventArgs?e)
????????{
????????????serialPort1.Close();
????????????this.Close();
????????}
????????//FCS
????????private?void?button4_Click(object?sender?EventArgs?e)
????????{
????????????string?str?=?textBox1.Text;
????????????int?n;
????????????int?l?=?str.Length;
????????????char?m?=?‘\0‘;
????????????for?(int?i?=?0;?i?????????????{
????????????????n?=?str[i]?^?m;
????????????????m?=?(char)(n);
????????????}
????????????n?=?(int)(m);
????????????textBox3.Text?=?““;
????????????textBox3.Text?=?textBox1.Text+?String.Format(“{0:x}“n)+“*\r“;
????????}
????????private?void?Form1_Load(object?sender?EventArgs?e)
????????{
????????????this.ControlBox?=?false;
????????}
????}
}
?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
?????文件???????5612??2009-03-21?10:25??ascii碼串口調(diào)試\ascii碼串口調(diào)試\Properties\Resources.resx
?????文件????????249??2009-03-21?10:25??ascii碼串口調(diào)試\ascii碼串口調(diào)試\Properties\Settings.settings
?????文件???????1312??2009-03-21?10:25??ascii碼串口調(diào)試\ascii碼串口調(diào)試\Properties\AssemblyInfo.cs
?????文件???????2867??2009-03-21?10:25??ascii碼串口調(diào)試\ascii碼串口調(diào)試\Properties\Resources.Designer.cs
?????文件???????1103??2009-03-21?10:25??ascii碼串口調(diào)試\ascii碼串口調(diào)試\Properties\Settings.Designer.cs
?????文件???????7834??2009-04-10?16:55??ascii碼串口調(diào)試\ascii碼串口調(diào)試\Form1.Designer.cs
?????文件???????4710??2009-04-09?10:39??ascii碼串口調(diào)試\ascii碼串口調(diào)試\04.ico
?????文件???????6013??2009-04-10?16:55??ascii碼串口調(diào)試\ascii碼串口調(diào)試\Form1.resx
?????文件???????3359??2009-04-09?10:39??ascii碼串口調(diào)試\ascii碼串口調(diào)試\ascii碼串口調(diào)試.csproj
?????文件???????5632??2005-09-23?06:56??ascii碼串口調(diào)試\ascii碼串口調(diào)試\bin\Debug\ascii碼串口調(diào)試.vshost.exe
?????文件??????28672??2009-04-10?16:55??ascii碼串口調(diào)試\ascii碼串口調(diào)試\bin\Debug\ascii碼串口調(diào)試.exe
?????文件??????28160??2009-04-10?16:55??ascii碼串口調(diào)試\ascii碼串口調(diào)試\bin\Debug\ascii碼串口調(diào)試.pdb
?????文件????????180??2009-04-10?16:55??ascii碼串口調(diào)試\ascii碼串口調(diào)試\obj\Debug\ascii碼串口調(diào)試.Form1.resources
?????文件????????180??2009-03-21?10:31??ascii碼串口調(diào)試\ascii碼串口調(diào)試\obj\Debug\ascii碼串口調(diào)試.Properties.Resources.resources
?????文件??????28672??2009-04-10?16:55??ascii碼串口調(diào)試\ascii碼串口調(diào)試\obj\Debug\ascii碼串口調(diào)試.exe
?????文件??????28160??2009-04-10?16:55??ascii碼串口調(diào)試\ascii碼串口調(diào)試\obj\Debug\ascii碼串口調(diào)試.pdb
?????文件????????842??2009-04-10?16:55??ascii碼串口調(diào)試\ascii碼串口調(diào)試\obj\Debug\ascii碼串口調(diào)試.csproj.GenerateResource.Cache
?????文件????????359??2009-04-13?21:12??ascii碼串口調(diào)試\ascii碼串口調(diào)試\obj\ascii碼串口調(diào)試.csproj.FileList.txt
?????文件???????2771??2009-04-10?16:55??ascii碼串口調(diào)試\ascii碼串口調(diào)試\Form1.cs
?????文件????????490??2009-03-21?10:25??ascii碼串口調(diào)試\ascii碼串口調(diào)試\Program.cs
?????文件????????949??2009-03-21?10:25??ascii碼串口調(diào)試\ascii碼串口調(diào)試.sln
????..A..H.?????14336??2009-04-13?21:58??ascii碼串口調(diào)試\ascii碼串口調(diào)試.suo
?????目錄??????????0??2009-03-21?10:25??ascii碼串口調(diào)試\ascii碼串口調(diào)試\obj\Debug\TempPE
?????目錄??????????0??2009-03-21?10:25??ascii碼串口調(diào)試\ascii碼串口調(diào)試\bin\Debug
?????目錄??????????0??2009-03-21?10:25??ascii碼串口調(diào)試\ascii碼串口調(diào)試\obj\Debug
?????目錄??????????0??2009-03-21?10:25??ascii碼串口調(diào)試\ascii碼串口調(diào)試\Properties
?????目錄??????????0??2009-03-21?10:25??ascii碼串口調(diào)試\ascii碼串口調(diào)試\bin
?????目錄??????????0??2009-03-21?10:25??ascii碼串口調(diào)試\ascii碼串口調(diào)試\obj
?????目錄??????????0??2009-03-21?10:25??ascii碼串口調(diào)試\ascii碼串口調(diào)試
?????目錄??????????0??2009-03-21?10:25??ascii碼串口調(diào)試
............此處省略3個(gè)文件信息
評(píng)論
共有 條評(píng)論