資源簡介
本資料是杜洋工作室所出版的上位機教程的講義資料,包括課上所用到的各種歷程。

代碼片段和文件信息
using?System;
using?System.Collections.Generic;
using?System.ComponentModel;
using?System.Data;
using?System.Drawing;
using?System.Linq;
using?System.Text;
using?System.Windows.Forms;
using?System.IO.Ports;
namespace?串口控制
{
????public?partial?class?Form1?:?Form
????{
????????//device?1
????????const?byte?DeviceOpen1?=?0x01;
????????const?byte?DeviceClose1?=?0x81;
????????//device?2
????????const?byte?DeviceOpen2?=?0x02;
????????const?byte?DeviceClose2?=?0x82;
????????//device?3
????????const?byte?DeviceOpen3?=?0x03;
????????const?byte?DeviceClose3?=?0x83;
????????//SerialPort?Write?Buffer
????????bool?Button1Statue;
????????byte[]?SerialPortDataBuffer?=?new?byte[1];
????????public?Form1()
????????{
????????????InitializeComponent();??????????????????????????????????????//窗口構造
????????}
????????private?void?button1_Click(object?sender?EventArgs?e)
????????{
????????????if?(serialPort1.IsOpen)?????????????????????????????????????//串口打開就關閉
????????????{
????????????????try
????????????????{
????????????????????serialPort1.Close();
????????????????}
????????????????catch?{?}???????????????????????????????????????????????//確保萬無一失
????????????????//button1.Text?=?“打開串口“;
????????????????button1.BackgroundImage?=?Properties.Resources.Image2;??//滅
????????????????Button1Statue?=?false;??????????????????????????????????//按鈕狀態
????????????}
????????????else
????????????{
????????????????try
????????????????{
????????????????????serialPort1.PortName?=?comboBox1.Text;??????????????//端口號
????????????????????serialPort1.Open();?????????????????????????????????//打開端口
????????????????????//button1.Text?=?“關閉串口“;
????????????????????button1.BackgroundImage?=?Properties.Resources.Image1;//亮
????????????????????Button1Statue?=?true;????????????????????????????????//按鈕狀態
????????????????}
????????????????catch
????????????????{
????????????????????MessageBox.Show(“串口打開失敗““錯誤“);
????????????????}
????????????}
????????}
????????private?void?Form1_Load(object?sender?EventArgs?e)
????????{
????????????SearchAndAddSerialToComboBox(serialPort1?comboBox1);
????????}
????????private?void?WriteByteToSerialPort(byte?data)???????????????????//單字節寫入串口
????????{
????????????byte[]?Buffer?=?new?byte?[2]{0x00?data?};???????????????????????//定義數組
????????????if?(serialPort1.IsOpen)?????????????????????????????????????//傳輸數據的前提是端口已打開
????????????{
????????????????try
????????????????{
????????????????????serialPort1.Write(Buffer?0?2);????????????????????//寫數據
????????????????}
????????????????catch?
????????????????{
????????????????????MessageBox.Show(“串口數據發送出錯,請檢查.““錯誤“);//錯誤處理
????????????????}
????????????}
????????}
????????private?void?SearchAndAddSerialToComboBox(SerialPort?MyPortComboBox?MyBox)
????????{???????????????????????????????????????????????????????????????//將可用端口號添加到ComboBox
????????????string[]?MyString?=?new?string[20];?????????????????????????//最多容納20個,太多會影響調試效率
?
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件????????962??2013-07-16?00:16??杜洋C#資料\第2、3集:C#軟件項目\WindowsFormsApplication1\WindowsFormsApplication1.sln
????..A..H.?????43520??2013-07-31?11:42??杜洋C#資料\第2、3集:C#軟件項目\WindowsFormsApplication1\WindowsFormsApplication1.v11.suo
?????文件???????1843??2013-12-05?09:47??杜洋C#資料\第2、3集:C#軟件項目\WindowsFormsApplication1\WindowsFormsApplication1\Form1.cs
?????文件???????5391??2013-07-17?00:45??杜洋C#資料\第2、3集:C#軟件項目\WindowsFormsApplication1\WindowsFormsApplication1\Form1.Designer.cs
?????文件???????6011??2013-07-17?00:47??杜洋C#資料\第2、3集:C#軟件項目\WindowsFormsApplication1\WindowsFormsApplication1\Form1.resx
?????文件????????505??2013-07-16?00:16??杜洋C#資料\第2、3集:C#軟件項目\WindowsFormsApplication1\WindowsFormsApplication1\Program.cs
?????文件???????3761??2013-07-16?00:22??杜洋C#資料\第2、3集:C#軟件項目\WindowsFormsApplication1\WindowsFormsApplication1\WindowsFormsApplication1.csproj
?????文件???????3072??2013-12-05?11:39??杜洋C#資料\第2、3集:C#軟件項目\WindowsFormsApplication1\WindowsFormsApplication1\WindowsFormsApplication1.suo
?????文件???????1368??2013-07-16?00:16??杜洋C#資料\第2、3集:C#軟件項目\WindowsFormsApplication1\WindowsFormsApplication1\Properties\AssemblyInfo.cs
?????文件???????2900??2013-07-16?00:16??杜洋C#資料\第2、3集:C#軟件項目\WindowsFormsApplication1\WindowsFormsApplication1\Properties\Resources.Designer.cs
?????文件???????5612??2013-07-16?00:16??杜洋C#資料\第2、3集:C#軟件項目\WindowsFormsApplication1\WindowsFormsApplication1\Properties\Resources.resx
?????文件???????1111??2013-07-16?00:16??杜洋C#資料\第2、3集:C#軟件項目\WindowsFormsApplication1\WindowsFormsApplication1\Properties\Settings.Designer.cs
?????文件????????249??2013-07-16?00:16??杜洋C#資料\第2、3集:C#軟件項目\WindowsFormsApplication1\WindowsFormsApplication1\Properties\Settings.settings
?????文件???????6868??2013-07-16?00:22??杜洋C#資料\第2、3集:C#軟件項目\WindowsFormsApplication1\WindowsFormsApplication1\obj\Release\DesignTimeResolveAssemblyReferencesInput.cache
?????文件???????1415??2013-07-16?22:15??杜洋C#資料\第2、3集:C#軟件項目\WindowsFormsApplication1\WindowsFormsApplication1\obj\Debug\DesignTimeResolveAssemblyReferences.cache
?????文件???????6250??2013-12-05?13:33??杜洋C#資料\第2、3集:C#軟件項目\WindowsFormsApplication1\WindowsFormsApplication1\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache
?????文件???????2901??2013-12-05?13:33??杜洋C#資料\第2、3集:C#軟件項目\WindowsFormsApplication1\WindowsFormsApplication1\obj\Debug\WindowsFormsApplication1.csproj.FileListAbsolute.txt
?????文件????????975??2013-07-17?00:47??杜洋C#資料\第2、3集:C#軟件項目\WindowsFormsApplication1\WindowsFormsApplication1\obj\Debug\WindowsFormsApplication1.csproj.GenerateResource.Cache
?????文件???????2143??2013-07-16?00:22??杜洋C#資料\第2、3集:C#軟件項目\WindowsFormsApplication1\WindowsFormsApplication1\obj\Debug\WindowsFormsApplication1.csprojResolveAssemblyReference.cache
?????文件??????10240??2013-12-05?09:47??杜洋C#資料\第2、3集:C#軟件項目\WindowsFormsApplication1\WindowsFormsApplication1\obj\Debug\WindowsFormsApplication1.exe
?????文件????????180??2013-12-05?09:46??杜洋C#資料\第2、3集:C#軟件項目\WindowsFormsApplication1\WindowsFormsApplication1\obj\Debug\WindowsFormsApplication1.Form1.resources
?????文件??????34304??2013-12-05?09:47??杜洋C#資料\第2、3集:C#軟件項目\WindowsFormsApplication1\WindowsFormsApplication1\obj\Debug\WindowsFormsApplication1.pdb
?????文件????????180??2013-12-05?09:46??杜洋C#資料\第2、3集:C#軟件項目\WindowsFormsApplication1\WindowsFormsApplication1\obj\Debug\WindowsFormsApplication1.Properties.Resources.resources
?????文件????????512??2013-12-05?09:46??杜洋C#資料\第2、3集:C#軟件項目\WindowsFormsApplication1\WindowsFormsApplication1\obj\Debug\GenerateResource.read.1.tlog
?????文件???????1174??2013-12-05?09:46??杜洋C#資料\第2、3集:C#軟件項目\WindowsFormsApplication1\WindowsFormsApplication1\obj\Debug\GenerateResource.write.1.tlog
?????文件??????22472??2013-07-16?00:22??杜洋C#資料\第2、3集:C#軟件項目\WindowsFormsApplication1\WindowsFormsApplication1\bin\Release\WindowsFormsApplication1.vshost.exe
?????文件????????490??2009-08-31?00:40??杜洋C#資料\第2、3集:C#軟件項目\WindowsFormsApplication1\WindowsFormsApplication1\bin\Release\WindowsFormsApplication1.vshost.exe.manifest
?????文件??????10240??2013-12-05?09:47??杜洋C#資料\第2、3集:C#軟件項目\WindowsFormsApplication1\WindowsFormsApplication1\bin\Debug\WindowsFormsApplication1.exe
?????文件??????34304??2013-12-05?09:47??杜洋C#資料\第2、3集:C#軟件項目\WindowsFormsApplication1\WindowsFormsApplication1\bin\Debug\WindowsFormsApplication1.pdb
?????文件??????11592??2013-12-05?13:33??杜洋C#資料\第2、3集:C#軟件項目\WindowsFormsApplication1\WindowsFormsApplication1\bin\Debug\WindowsFormsApplication1.vshost.exe
............此處省略555個文件信息
- 上一篇:c#+sql人事工資管理系統
- 下一篇:C#登錄注冊文檔教程驗證碼.
評論
共有 條評論