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

  • 大小: 68KB
    文件類型: .zip
    金幣: 1
    下載: 0 次
    發(fā)布日期: 2021-06-02
  • 語(yǔ)言: C#
  • 標(biāo)簽: 菱PLC??

資源簡(jiǎn)介

c#與三菱FX2N系列PLC進(jìn)行COM口通訊進(jìn)行配置,實(shí)現(xiàn)數(shù)據(jù)讀寫

資源截圖

代碼片段和文件信息

/*
?*?由SharpDevelop創(chuàng)建。
?*?用戶:?hp
?*?日期:?2015/6/4
?*?時(shí)間:?15:20
?*?
?*?要改變這種模板請(qǐng)點(diǎn)擊?工具|選項(xiàng)|代碼編寫|編輯標(biāo)準(zhǔn)頭文件
?*/
using?System;
using?System.Collections.Generic;
using?System.ComponentModel;
using?System.Data;
using?System.Drawing;
using?System.Text;
using?System.Windows.Forms;
using?System.IO.Ports;


namespace?串口通信程序1
{
///?
///?Description?of?MainForm.
///?

public?partial?class?MainForm?:?Form
{
public?MainForm()
{

InitializeComponent();

}

public?void?ComboBox1SelectedIndexChanged(object?sender?EventArgs?e)
{

}


public??void?Button1Click(object?sender?EventArgs?e)//點(diǎn)擊按鈕獲取串口
{
try?{
{
serialPort1.DataBits=7;
serialPort1.BaudRate=Convert.ToInt16(?textBox1.Text.ToString());
if?(serialPort1.PortName==comboBox1.Text)//判斷計(jì)算機(jī)端口是否等于設(shè)定端口

{??serialPort1.Open();
this.button1.Text=“關(guān)閉端口“;

}

else
{serialPort1.Close();
this.button1.Text=“打開(kāi)端口“;
}

}
}

catch
{
MessageBox.Show(“請(qǐng)?jiān)O(shè)定波特率“);

}
}

/////以上是打開(kāi)端口的程序
private?bool??timerIsActive=?false;//最好初始化

public?void?MainFormLoad(object?sender?EventArgs?e)//獲取計(jì)算機(jī)的端口與設(shè)定端口
{

string[]?ports?=?SerialPort.GetPortNames();//獲取計(jì)算的可用串口
foreach(string?port?in?ports)
{this.textBox4.Text=port.ToString();
this?.comboBox1.Text=port.ToString();
serialPort1.PortName=textBox4.Text;
}

for?(int?i=0;i<=20;i++)//for循環(huán)增加串口
{
comboBox1.Items.Add(“COM“+i.ToString());//下拉框中出現(xiàn)串口
comboBox1.SelectedItem=1;

}

for?(int?q=0;q<=20;q++)//for循環(huán)增加發(fā)送的數(shù)據(jù)

{???string?str=Convert.ToString(q16);
if?(str.Length==1)
{str=“0“+str;
str?=“0x“+str;
comboBox2.Items.Add(str);//下拉框中出現(xiàn)串口

}

}

}
public?static?int?Asc(string?character)//字符串轉(zhuǎn)為ASCII碼
{
if?(character.Length?==?1)
{
System.Text.ASCIIEncoding?asciiEncoding?=?new?System.Text.ASCIIEncoding();
int?intAsciiCode?=?(int)asciiEncoding.GetBytes(character)[0];
return?(intAsciiCode);
}
else
{
throw?new?Exception(“Character?is?not?valid.“);
}

}


public?void?Button3Click(object?sender?EventArgs?e)//發(fā)送數(shù)據(jù)的按鈕
{??byte[]date=new?byte[1];
string?rtu;
try?{
rtu=comboBox2.Text;//發(fā)送的數(shù)據(jù)在下拉框中顯示
rtu=rtu.Substring(22);
date[0]=Convert.ToByte(rtu16);}
catch
{
MessageBox.Show?(“請(qǐng)使用正確的字符串“);

}
date[0]=1;
if(serialPort1.IsOpen)
{
try?{
serialPort1.Write(date01);
this.textBox2.Text=date[0]+““;


}

catch
{
MessageBox.Show?(“端口沒(méi)有打開(kāi),請(qǐng)檢查端口“);


}
}

else
{
MessageBox.Show?(“端口沒(méi)有打開(kāi),請(qǐng)檢查端口“);
}
}



public?void?Button4Click(object?sender?EventArgs?e)//發(fā)送代碼
{
//02h30h30h30h38h30h39h32h03h35h44h
//STX00080

?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2015-08-16?14:54??串口通信程序1\
?????目錄???????????0??2015-07-09?15:17??串口通信程序1\串口通信程序1\
?????文件???????25372??2015-06-22?17:52??串口通信程序1\串口通信程序1\MainForm.Designer.cs
?????文件???????12204??2015-06-22?19:21??串口通信程序1\串口通信程序1\MainForm.cs
?????文件????????6579??2015-06-22?17:52??串口通信程序1\串口通信程序1\MainForm.resx
?????文件?????????648??2015-06-04?15:20??串口通信程序1\串口通信程序1\Program.cs
?????目錄???????????0??2015-06-04?15:20??串口通信程序1\串口通信程序1\Properties\
?????文件????????1095??2015-06-04?15:20??串口通信程序1\串口通信程序1\Properties\AssemblyInfo.cs
?????目錄???????????0??2015-06-04?15:20??串口通信程序1\串口通信程序1\bin\
?????目錄???????????0??2015-08-16?14:53??串口通信程序1\串口通信程序1\bin\Debug\
?????文件???????21504??2015-08-16?14:53??串口通信程序1\串口通信程序1\bin\Debug\串口通信程序1.exe
?????文件???????34304??2015-08-16?14:53??串口通信程序1\串口通信程序1\bin\Debug\串口通信程序1.pdb
?????文件???????23168??2015-08-16?14:53??串口通信程序1\串口通信程序1\bin\Debug\串口通信程序1.vshost.exe
?????文件?????????490??2010-03-17?22:39??串口通信程序1\串口通信程序1\bin\Debug\串口通信程序1.vshost.exe.manifest
?????目錄???????????0??2015-06-04?15:20??串口通信程序1\串口通信程序1\obj\
?????目錄???????????0??2015-08-16?14:53??串口通信程序1\串口通信程序1\obj\Debug\
?????文件????????2861??2015-08-16?14:53??串口通信程序1\串口通信程序1\obj\Debug\DesignTimeResolveAssemblyReferences.cache
?????文件????????6694??2015-08-16?14:53??串口通信程序1\串口通信程序1\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache
?????目錄???????????0??2015-08-16?14:54??串口通信程序1\串口通信程序1\obj\Debug\TempPE\
?????文件?????????180??2015-08-16?14:53??串口通信程序1\串口通信程序1\obj\Debug\串口通信程序1.MainForm.resources
?????文件?????????816??2015-08-16?14:53??串口通信程序1\串口通信程序1\obj\Debug\串口通信程序1.csproj.FileListAbsolute.txt
?????文件?????????907??2015-08-16?14:53??串口通信程序1\串口通信程序1\obj\Debug\串口通信程序1.csproj.GenerateResource.Cache
?????文件????????7562??2015-08-16?14:53??串口通信程序1\串口通信程序1\obj\Debug\串口通信程序1.csprojResolveAssemblyReference.cache
?????文件???????21504??2015-08-16?14:53??串口通信程序1\串口通信程序1\obj\Debug\串口通信程序1.exe
?????文件???????34304??2015-08-16?14:53??串口通信程序1\串口通信程序1\obj\Debug\串口通信程序1.pdb
?????文件????????2719??2015-08-16?14:53??串口通信程序1\串口通信程序1\串口通信程序1.csproj
?????文件?????????870??2015-06-04?15:20??串口通信程序1\串口通信程序1.sln
?????文件???????14848??2015-08-16?14:54??串口通信程序1\串口通信程序1.v12.suo

評(píng)論

共有 條評(píng)論