資源簡介
這是一個對串口發(fā)送printf("pitch:%.2f roll:%.2f yaw:%.2f\n",Pitch,Roll,Yaw);進(jìn)行接收的上位機(jī),并分離出相應(yīng)的歐拉角數(shù)據(jù)

代碼片段和文件信息
using?System;
using?System.Configuration;
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;
using?System.Text.Regularexpressions;
namespace?SerialportSample
{?
????public?partial?class?SerialportSampleForm?:?Form
????{
????????int?i;
????????string?data1data2data3;
????????private?SerialPort?comm?=?new?SerialPort();
????????private?StringBuilder?builder?=?new?StringBuilder();//避免在事件處理方法中反復(fù)的創(chuàng)建,定義到外面。
????????private?long?received_count?=?0;//接收計(jì)數(shù)
????????private?long?send_count?=?0;//發(fā)送計(jì)數(shù)
????????private?bool?Listening?=?false;//是否沒有執(zhí)行完invoke相關(guān)操作
????????private?bool?Closing?=?false;//是否正在關(guān)閉串口,執(zhí)行Application.DoEvents,并阻止再次invoke
????????private?List?buffer?=?new?List(4096);//默認(rèn)分配1頁內(nèi)存,并始終限制不允許超過
????????private?byte[]?binary_data_1?=?new?byte[20];
????????private?byte[]?binary_data_2?=?new?byte[20];
????????private?byte[]?binary_data_3?=?new?byte[20];
????????public?SerialportSampleForm()
????????{
????????????InitializeComponent();
????????}
????????//窗體初始化
????????private?void?Form1_Load(object?sender?EventArgs?e)
????????{
????????????//初始化下拉串口名稱列表框
????????????string[]?ports?=?SerialPort.GetPortNames();
????????????Array.Sort(ports);
????????????comboPortName.Items.AddRange(ports);
????????????comboPortName.SelectedIndex?=?comboPortName.Items.Count?>?0???0?:?-1;
????????????comboBaudrate.SelectedIndex?=?comboBaudrate.Items.IndexOf(“115200“);
????????????this.KeyPreview?=?true;
????????????//初始化SerialPort對象
????????????comm.NewLine?=?“\r\n“;
????????????comm.RtsEnable?=?true;//根據(jù)實(shí)際情況吧。
????????????comboPortName.Text?=?“COM16“;
????????????//添加事件注冊
????????????comm.DataReceived?+=?comm_DataReceived;
????????????chart1.ChartAreas[“ChartArea1“].AxisX.Minimum?=100;
????????????chart1.ChartAreas[“ChartArea1“].AxisX.Maximum?=?0;
????????????chart1.ChartAreas[“ChartArea1“].AxisY.Minimum?=?-100;
????????????chart1.ChartAreas[“ChartArea1“].AxisY.Maximum?=?100;
????????????chart1.ChartAreas[“ChartArea1“].AxisX.Interval?=?1;//設(shè)置每個刻度的跨度
????????????chart1.ChartAreas[“ChartArea1“].AxisY.Interval?=?10;//設(shè)置每個刻度的跨度
????????????i?=?0;
????????/*????DataTable?dt?=?default(DataTable);
????????????dt?=?CreateDataTable();
????????????//設(shè)置圖表的數(shù)據(jù)源
????????????Chart1.DataSource?=?dt;
????????????//設(shè)置圖表Y軸對應(yīng)項(xiàng)
????????????Chart1.Series[0].YValueMembers?=?“Volume1“;
????????????Chart1.Series[1].YValueMembers?=?“Volume2“;
????????????//設(shè)置圖表X軸對應(yīng)項(xiàng)
????????????Chart1.Series[0].XValueMember?=?“Date“;
????????????//綁定數(shù)據(jù)
????????????Chart1.DataBind();*/
//????????????MessageBox.Show(“你很狡猾嗎?“);
????????}
????????Random?rnd?=?new?Random();
?/*???????private?DataTable?CreateDataTable()
????????{
????????????//Create?a?DataTable?as?the?data?source?of?the?Chart?control
????????????DataTable?dt?=?new?DataTable();
????????????//Add?three?c
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件??????48128??2014-04-13?22:17??SerialportSample(3)\SerialportSample\SerialportSample\bin\Debug\SerialportSample.exe
?????文件??????36352??2014-04-13?22:17??SerialportSample(3)\SerialportSample\SerialportSample\bin\Debug\SerialportSample.pdb
?????文件??????11600??2014-04-13?22:18??SerialportSample(3)\SerialportSample\SerialportSample\bin\Debug\SerialportSample.vshost.exe
?????文件????????490??2010-03-18?12:39??SerialportSample(3)\SerialportSample\SerialportSample\bin\Debug\SerialportSample.vshost.exe.manifest
?????文件??????18656??2014-04-13?22:17??SerialportSample(3)\SerialportSample\SerialportSample\Form1.cs
?????文件??????22814??2014-04-13?22:17??SerialportSample(3)\SerialportSample\SerialportSample\Form1.Designer.cs
?????文件??????25609??2014-04-13?22:17??SerialportSample(3)\SerialportSample\SerialportSample\Form1.resx
?????文件??????12862??2014-04-02?20:29??SerialportSample(3)\SerialportSample\SerialportSample\MY_first_PS.ico
?????文件??????62976??2014-04-04?00:51??SerialportSample(3)\SerialportSample\SerialportSample\obj\x86\Debug\AxInterop.TeeChart.dll
?????文件??????14101??2014-04-05?14:29??SerialportSample(3)\SerialportSample\SerialportSample\obj\x86\Debug\DesignTimeResolveAssemblyReferences.cache
?????文件???????6697??2014-04-13?22:17??SerialportSample(3)\SerialportSample\SerialportSample\obj\x86\Debug\DesignTimeResolveAssemblyReferencesInput.cache
?????文件????????642??2010-05-27?09:08??SerialportSample(3)\SerialportSample\SerialportSample\obj\x86\Debug\GenerateResource.read.1.tlog
?????文件???????1614??2010-05-27?09:08??SerialportSample(3)\SerialportSample\SerialportSample\obj\x86\Debug\GenerateResource.write.1.tlog
?????文件?????244224??2014-04-04?00:51??SerialportSample(3)\SerialportSample\SerialportSample\obj\x86\Debug\Interop.TeeChart.dll
?????文件???????3172??2014-04-13?22:18??SerialportSample(3)\SerialportSample\SerialportSample\obj\x86\Debug\SerialportSample.csproj.FileListAbsolute.txt
?????文件????????975??2014-04-13?22:17??SerialportSample(3)\SerialportSample\SerialportSample\obj\x86\Debug\SerialportSample.csproj.GenerateResource.Cache
?????文件????????770??2014-04-04?00:51??SerialportSample(3)\SerialportSample\SerialportSample\obj\x86\Debug\SerialportSample.csproj.ResolveComReference.cache
?????文件???????9174??2014-04-02?20:43??SerialportSample(3)\SerialportSample\SerialportSample\obj\x86\Debug\SerialportSample.csprojResolveAssemblyReference.cache
?????文件??????48128??2014-04-13?22:17??SerialportSample(3)\SerialportSample\SerialportSample\obj\x86\Debug\SerialportSample.exe
?????文件??????36352??2014-04-13?22:17??SerialportSample(3)\SerialportSample\SerialportSample\obj\x86\Debug\SerialportSample.pdb
?????文件????????180??2014-04-04?10:20??SerialportSample(3)\SerialportSample\SerialportSample\obj\x86\Debug\SerialportSample.Properties.Resources.resources
?????文件??????13428??2014-04-13?22:17??SerialportSample(3)\SerialportSample\SerialportSample\obj\x86\Debug\SerialportSample.SerialportSampleForm.resources
?????文件????????523??2010-05-16?03:24??SerialportSample(3)\SerialportSample\SerialportSample\Program.cs
?????文件???????1468??2010-05-16?02:19??SerialportSample(3)\SerialportSample\SerialportSample\Properties\AssemblyInfo.cs
?????文件???????2858??2010-05-16?02:19??SerialportSample(3)\SerialportSample\SerialportSample\Properties\Resources.Designer.cs
?????文件???????5612??2010-05-16?02:19??SerialportSample(3)\SerialportSample\SerialportSample\Properties\Resources.resx
?????文件???????1099??2010-05-16?02:19??SerialportSample(3)\SerialportSample\SerialportSample\Properties\Settings.Designer.cs
?????文件????????249??2010-05-16?02:19??SerialportSample(3)\SerialportSample\SerialportSample\Properties\Settings.settings
?????文件???????3928??2014-04-04?10:20??SerialportSample(3)\SerialportSample\SerialportSample\SerialportSample.csproj
?????文件????????890??2010-05-16?02:19??SerialportSample(3)\SerialportSample\SerialportSample.sln
............此處省略15個文件信息
- 上一篇:C#md5加密解密
- 下一篇:把其它應(yīng)用嵌入到C#窗口 源代碼
評論
共有 條評論