C# GPIB通信

ResourceManager 类型在 Syslem . ResOurces 命名空间内,用来在运行时刻进行二进制程序集清单资源(. resources 文件)的读取,其也支持外部文件形式的读取。它和琪他资源读取类: ResourceSet 和 IResourceReader 的区别是它的功能是最强大的(内部会 用一个
 ResourceSet ),因为不因能够像 ResourceSet 一样快速读取资源数据,它可以对, NET 中程序集的附属程序集( satelite assembly )进行探素,因此支持资源散据的多文化读取。

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using NationalInstruments.VisaNS;

string[] resources = ResourceManager.GetLocalManager().FindResources("?*");
foreach(string s in resources)//availableResourcesListBox:listbox控件
{
    availableResourcesListBox.Items.Add(s);//listbox中添加端口号
}
availableResourcesListBox.Items.Add("TCPIP[board]::host address[::LAN device name][::INSTR]");
availableResourcesListBox.Items.Add("TCPIP[board]::host address::port::SOCKET");
string selectedString = (string)availableResourcesListBox.SelectedItem;
try
{
    mbSession = (MessageBasedSession)ResourceManager.GetLocalManager().Open(selectedString );
}
catch(InvalidCastException)
{
    MessageBox.Show("Resource selected must be a message-based session");
}
catch(Exception exp)
{
    MessageBox.Show(exp.Message);
}
private string ReplaceCommonEscapeSequences(string s)
{
    return s.Replace("\\n", "\n").Replace("\\r", "\r");
}
private string InsertCommonEscapeSequences(string s)
{
    return s.Replace("\n", "\\n").Replace("\r", "\\r");
}
try
{
	string textToWrite = ReplaceCommonEscapeSequences(writeTextBox.Text);//writeTextBox文本控件
	string responseString = mbSession.Query(textToWrite);
	readTextBox.Text += InsertCommonEscapeSequences(responseString) + "\r\n";//readTextBox文本控件
}
catch(Exception exp)
{

     MessageBox.Show(exp.Message);
}

猜你喜欢

转载自blog.csdn.net/lvxingzhe3/article/details/121884187