資源簡介
C#調用MOXA公司的PComm.dll類庫PComm(線程安全)
接口函數:
1、public int InitComm(Hashtable Ht_CommParam)
2、 public int SendFrame(string Str_SendFrame, ref string Str_RecFrame, int i_NewBaudrate = 0)
3、public int CloseComm()
4、public string GetCommErrMsg(int i_ErrCode)

代碼片段和文件信息
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.Collections;
namespace?PCommApp
{
????public?partial?class?Form1?:?Form
????{
????????public?Form1()
????????{
????????????InitializeComponent();
????????}
????????private?void?btnSend_Click(object?sender?EventArgs?e)
????????{
????????????btnSend.Enabled?=?false;
????????????try
????????????{
????????????????Hashtable?Ht?=?new?Hashtable();
????????????????Ht.Add(“Port“?txbPort.Text.ToString());
????????????????Ht.Add(“Baud_Rate“?“9600“);
????????????????Ht.Add(“Parity“?“None“);
????????????????Ht.Add(“Byte_Size“?“8“);
????????????????Ht.Add(“Stop_Bits“?“1“);
????????????????Ht.Add(“Before_Delay“?“0“);
????????????????Ht.Add(“Byte_Delay“?“50“);
????????????????Ht.Add(“Read_Interval_Timeout“?“50“);
????????????????Ht.Add(“After_Delay“?“3000“);
????????????????string?Str_Sendframe?=?txbSendframe.Text.Trim();
????????????????string?Str_Recframe?=?string.Empty;
????????????????PComm?SP?=?new?PComm();
????????????????//初始化串口
????????????????int?i_RtnCode?=?SP.InitComm(Ht);
????????????????if?(i_RtnCode?!=?0)
????????????????{
????????????????????MessageBox.Show(SP.GetCommErrMsg(i_RtnCode));
????????????????????return;
????????????????}
????????????????try
????????????????{
????????????????????//發送數據
????????????????????ShowDebugMsg(“發送:?“?+?Str_Sendframe?true);
????????????????????i_RtnCode?=?SP.Sendframe(Str_Sendframe?ref?Str_Recframe?0);
????????????????????if?(i_RtnCode?!=?0)
????????????????????{
????????????????????????ShowDebugMsg(SP.GetCommErrMsg(i_RtnCode)?false);
????????????????????????return;
????????????????????}
????????????????????ShowDebugMsg(“接收:?“?+?Str_Recframe?true);
????????????????}
????????????????finally
????????????????{
????????????????????//關閉串口
????????????????????SP.CloseComm();
????????????????}
????????????}
????????????finally
????????????{
????????????????btnSend.Enabled?=?true;
????????????}
????????}
????????///?
????????///?顯示調試消息
????????///?
????????///?
????????///?ame“>
????????private?void?ShowDebugMsg(string?Str_ShowMsgBoolean?B_Isframe)
????????{
????????????if?(B_Isframe)
????????????{
????????????????Str_ShowMsg?=?DateTime.Now.ToString()+?“?“?+?Str_ShowMsg;
????????????}
????????????txtDebug.AppendText(Str_ShowMsg+“\r\n“);
????????????txtDebug.ScrollToCaret();
????????????txtDebug.Refresh();
????????}
????}
}
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件??????82520??2010-08-17?18:30??PCommClass\PCommApp\PCommApp\bin\Debug\PCOMM.DLL
?????文件??????16384??2017-02-28?11:36??PCommClass\PCommApp\PCommApp\bin\Debug\PCommApp.exe
?????文件??????32256??2017-02-28?11:36??PCommClass\PCommApp\PCommApp\bin\Debug\PCommApp.pdb
?????文件??????11600??2017-02-28?13:25??PCommClass\PCommApp\PCommApp\bin\Debug\PCommApp.vshost.exe
?????文件????????490??2014-09-19?01:53??PCommClass\PCommApp\PCommApp\bin\Debug\PCommApp.vshost.exe.manifest
?????文件???????2724??2017-02-28?11:36??PCommClass\PCommApp\PCommApp\Form1.cs
?????文件???????3975??2017-02-28?10:36??PCommClass\PCommApp\PCommApp\Form1.Designer.cs
?????文件???????5817??2017-02-28?10:36??PCommClass\PCommApp\PCommApp\Form1.resx
?????文件???????5359??2017-02-27?15:28??PCommClass\PCommApp\PCommApp\obj\x86\Debug\DesignTimeResolveAssemblyReferences.cache
?????文件???????6262??2017-02-28?11:36??PCommClass\PCommApp\PCommApp\obj\x86\Debug\DesignTimeResolveAssemblyReferencesInput.cache
?????文件????????722??2017-02-28?13:25??PCommClass\PCommApp\PCommApp\obj\x86\Debug\PCommApp.csproj.FileListAbsolute.txt
?????文件????????975??2017-02-28?10:39??PCommClass\PCommApp\PCommApp\obj\x86\Debug\PCommApp.csproj.GenerateResource.Cache
?????文件???????9040??2017-02-27?16:27??PCommClass\PCommApp\PCommApp\obj\x86\Debug\PCommApp.csprojResolveAssemblyReference.cache
?????文件??????16384??2017-02-28?11:36??PCommClass\PCommApp\PCommApp\obj\x86\Debug\PCommApp.exe
?????文件????????180??2017-02-28?10:39??PCommClass\PCommApp\PCommApp\obj\x86\Debug\PCommApp.Form1.resources
?????文件??????32256??2017-02-28?11:36??PCommClass\PCommApp\PCommApp\obj\x86\Debug\PCommApp.pdb
?????文件????????180??2017-02-28?10:21??PCommClass\PCommApp\PCommApp\obj\x86\Debug\PCommApp.Properties.Resources.resources
?????文件??????15438??2017-02-28?11:32??PCommClass\PCommApp\PCommApp\PComm.cs
?????文件???????3711??2017-02-28?10:16??PCommClass\PCommApp\PCommApp\PCommApp.csproj
?????文件????????489??2017-02-27?15:14??PCommClass\PCommApp\PCommApp\Program.cs
?????文件???????1352??2017-02-27?15:14??PCommClass\PCommApp\PCommApp\Properties\AssemblyInfo.cs
?????文件???????2868??2017-02-27?15:14??PCommClass\PCommApp\PCommApp\Properties\Resources.Designer.cs
?????文件???????5612??2017-02-27?15:14??PCommClass\PCommApp\PCommApp\Properties\Resources.resx
?????文件???????1095??2017-02-27?15:14??PCommClass\PCommApp\PCommApp\Properties\Settings.Designer.cs
?????文件????????249??2017-02-27?15:14??PCommClass\PCommApp\PCommApp\Properties\Settings.settings
?????文件????????866??2017-02-27?15:14??PCommClass\PCommApp\PCommApp.sln
????..A..H.?????20992??2017-02-28?13:27??PCommClass\PCommApp\PCommApp.suo
?????目錄??????????0??2017-02-27?15:14??PCommClass\PCommApp\PCommApp\obj\x86\Debug\TempPE
?????目錄??????????0??2017-02-28?11:36??PCommClass\PCommApp\PCommApp\obj\x86\Debug
?????目錄??????????0??2017-02-27?16:29??PCommClass\PCommApp\PCommApp\bin\Debug
............此處省略10個文件信息
- 上一篇:C#AE最短路徑網絡分析
- 下一篇:asp.net多線程日志記錄源碼
評論
共有 條評論