91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

  • 大小: 53KB
    文件類(lèi)型: .rar
    金幣: 2
    下載: 0 次
    發(fā)布日期: 2021-06-16
  • 語(yǔ)言: C#
  • 標(biāo)簽: C#??串口??通信??圖片??

資源簡(jiǎn)介

通過(guò)串口進(jìn)行圖片的傳遞,圖片是以byte[]形式傳遞的,并能顯示出傳遞后的圖片

資源截圖

代碼片段和文件信息

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;??
using?System.Text.Regularexpressions;

namespace?WindowsFormsApplication21
{
????public?partial?class?Form1?:?Form
????{

????????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;//是否沒(méi)有執(zhí)行完invoke相關(guān)操作???
????????private?bool?closing?=?false;//是否正在關(guān)閉串口,執(zhí)行Application.DoEvents,并阻止再次invoke

????????string?curFileName;
????????static?int?width;
????????static?int?height;
????????Bitmap?bmp1?=?null;
????????byte[]?d?=null;//設(shè)置緩存區(qū)用來(lái)接收完整的傳送數(shù)據(jù)
????????public?static?int?x?=?0;//與d配套使用,用來(lái)記錄每次接收緩存區(qū)里數(shù)據(jù)的個(gè)數(shù)
????????
????????public?Form1()
????????{
????????????InitializeComponent();
????????}

????????private?void?Form1_Load(object?sender?EventArgs?e)
????????{
????????????//初始化下拉串口名稱(chēng)列表框???
????????????string[]?ports?=?SerialPort.GetPortNames();
????????????Array.Sort(ports);
????????????comboBox1.Items.AddRange(ports);
????????????comboBox1.SelectedIndex?=?comboBox1.Items.Count?>?0???0?:?-1;
????????????comboBox2.SelectedIndex?=?comboBox2.Items.IndexOf(“9600“);
????????????//初始化SerialPort對(duì)象??????
????????????serialPort1.NewLine?=?“/r/n“;
????????????serialPort1.RtsEnable?=?true;//設(shè)置是否啟用發(fā)送請(qǐng)求信號(hào)
????????}
????????//該事件在一次傳送過(guò)程中會(huì)觸發(fā)多次,每次都把系統(tǒng)分配的緩存區(qū)里數(shù)據(jù)讀至buf數(shù)組里
????????private?void?serialPort1_DataReceived(object?sender?SerialDataReceivedEventArgs?e)
????????{

????????????if?(closing)?return;//如果正在關(guān)閉,忽略操作,直接返回,盡快的完成串口監(jiān)聽(tīng)線(xiàn)程的一次循環(huán)???
????????????try
????????????{
????????????????Listening?=?true;//設(shè)置標(biāo)記,說(shuō)明我已經(jīng)開(kāi)始處理數(shù)據(jù),一會(huì)兒要使用系統(tǒng)UI的。?
????????????????int?n?=?serialPort1.BytesToRead;//先記錄下來(lái),避免某種原因,人為的原因,操作幾次之間時(shí)間長(zhǎng),緩存不一致???
????????????????byte[]?buf?=?new?byte[n];//聲明一個(gè)臨時(shí)數(shù)組存儲(chǔ)當(dāng)前來(lái)的串口數(shù)據(jù)???
????????????????received_count?+=?n;//增加接收計(jì)數(shù)???
????????????????serialPort1.Read(buf?0?n);//讀取緩沖數(shù)據(jù)???
????????????????builder.Remove(0?builder.Length);//清除字符串構(gòu)造器的內(nèi)容???
????????????????//因?yàn)橐L(fǎng)問(wèn)ui資源,所以需要使用invoke方式同步ui。???
????????????????this.Invoke((EventHandler)(delegate
????????????????{
????????????????????for?(int?i?=?0;?i?????????????????????{
????????????????????????//richTextBox2.Text?=?richTextBox2.Text?+?buf[i].ToString()?+?““;
????????????????????????d[x?+?i]?=?buf[i];
????????????????????}
????????????????????x?=?x?+?n;
????????????????}));
????????????}
????????????finally
????????????{
????????????????Listening?=?false;//我用完了,ui可以關(guān)閉串口了。???
????????????}

????????}

????????private?void?button1_Click(object?sender?EventArgs?e)//打開(kāi)串口
????????{
????????????button1.Enabled?=?false;
????????????button2.Enabled?=?true;
????????????button3.Enabled?=?true;

????????????
????????????serialPort1.PortName?=?comboBox1.Tex

?屬性????????????大小?????日期????時(shí)間???名稱(chēng)
-----------?---------??----------?-----??----

?????文件????????965??2011-09-02?14:45??通過(guò)串口傳送圖片實(shí)例\WindowsFormsApplication21.sln

????..A..H.?????34304??2012-02-23?08:49??通過(guò)串口傳送圖片實(shí)例\WindowsFormsApplication21.suo

?????文件????????506??2011-09-02?14:45??通過(guò)串口傳送圖片實(shí)例\WindowsFormsApplication21\Program.cs

?????文件???????3796??2011-09-02?15:18??通過(guò)串口傳送圖片實(shí)例\WindowsFormsApplication21\WindowsFormsApplication21.csproj

?????文件???????1406??2011-09-02?14:45??通過(guò)串口傳送圖片實(shí)例\WindowsFormsApplication21\Properties\AssemblyInfo.cs

?????文件???????2900??2011-09-02?14:45??通過(guò)串口傳送圖片實(shí)例\WindowsFormsApplication21\Properties\Resources.Designer.cs

?????文件???????5612??2011-09-02?14:45??通過(guò)串口傳送圖片實(shí)例\WindowsFormsApplication21\Properties\Resources.resx

?????文件???????1110??2011-09-02?14:45??通過(guò)串口傳送圖片實(shí)例\WindowsFormsApplication21\Properties\Settings.Designer.cs

?????文件????????249??2011-09-02?14:45??通過(guò)串口傳送圖片實(shí)例\WindowsFormsApplication21\Properties\Settings.settings

?????文件???????5690??2012-02-23?08:49??通過(guò)串口傳送圖片實(shí)例\WindowsFormsApplication21\obj\Debug\WindowsFormsApplication21.csproj.FileListAbsolute.txt

?????文件??????15360??2012-02-23?08:49??通過(guò)串口傳送圖片實(shí)例\WindowsFormsApplication21\obj\Debug\WindowsFormsApplication21.exe

?????文件????????180??2012-02-23?08:49??通過(guò)串口傳送圖片實(shí)例\WindowsFormsApplication21\obj\Debug\WindowsFormsApplication21.Form1.resources

?????文件????????180??2011-09-02?15:24??通過(guò)串口傳送圖片實(shí)例\WindowsFormsApplication21\obj\Debug\WindowsFormsApplication21.Properties.Resources.resources

?????文件????????847??2012-02-23?08:49??通過(guò)串口傳送圖片實(shí)例\WindowsFormsApplication21\obj\Debug\WindowsFormsApplication21.csproj.GenerateResource.Cache

?????文件??????28160??2012-02-23?08:49??通過(guò)串口傳送圖片實(shí)例\WindowsFormsApplication21\obj\Debug\WindowsFormsApplication21.pdb

?????文件??????15360??2012-02-23?08:49??通過(guò)串口傳送圖片實(shí)例\WindowsFormsApplication21\bin\Debug\WindowsFormsApplication21.exe

?????文件??????28160??2012-02-23?08:49??通過(guò)串口傳送圖片實(shí)例\WindowsFormsApplication21\bin\Debug\WindowsFormsApplication21.pdb

?????文件??????14328??2012-02-23?08:49??通過(guò)串口傳送圖片實(shí)例\WindowsFormsApplication21\bin\Debug\WindowsFormsApplication21.vshost.exe

?????文件????????490??2007-07-21?01:33??通過(guò)串口傳送圖片實(shí)例\WindowsFormsApplication21\bin\Debug\WindowsFormsApplication21.vshost.exe.manifest

?????文件???????6217??2012-02-23?08:49??通過(guò)串口傳送圖片實(shí)例\WindowsFormsApplication21\Form1.resx

?????文件??????11625??2012-02-23?08:49??通過(guò)串口傳送圖片實(shí)例\WindowsFormsApplication21\Form1.Designer.cs

?????文件???????7758??2012-02-23?08:49??通過(guò)串口傳送圖片實(shí)例\WindowsFormsApplication21\Form1.cs

?????文件????????189??2012-02-23?08:51??通過(guò)串口傳送圖片實(shí)例\使用說(shuō)明.txt

?????目錄??????????0??2012-02-23?08:45??通過(guò)串口傳送圖片實(shí)例\WindowsFormsApplication21\obj\Debug\TempPE

?????目錄??????????0??2012-02-23?08:45??通過(guò)串口傳送圖片實(shí)例\WindowsFormsApplication21\obj\Debug\Refactor

?????目錄??????????0??2012-02-23?08:45??通過(guò)串口傳送圖片實(shí)例\WindowsFormsApplication21\obj\Debug

?????目錄??????????0??2012-02-23?08:45??通過(guò)串口傳送圖片實(shí)例\WindowsFormsApplication21\bin\Debug

?????目錄??????????0??2012-02-23?08:45??通過(guò)串口傳送圖片實(shí)例\WindowsFormsApplication21\Properties

?????目錄??????????0??2012-02-23?08:45??通過(guò)串口傳送圖片實(shí)例\WindowsFormsApplication21\obj

?????目錄??????????0??2012-02-23?08:45??通過(guò)串口傳送圖片實(shí)例\WindowsFormsApplication21\bin

............此處省略5個(gè)文件信息

評(píng)論

共有 條評(píng)論