我已经设法在视觉 C# express 中识别驱动器和串行端口,但我仍然无法访问特定设备(RepRap 打印机)。我想向它发送一个字符串数组,但首先我需要找到它,我该怎么做?我正在使用 Windows 7。
要获取驱动器:
using System.Linq;
using System.IO;
using System;
class Program
{
static void Main(string[] args)
{
var drives = DriveInfo.GetDrives();
DriveInfo[] allDrives = DriveInfo.GetDrives();
foreach(DriveInfo dv in drives)
{
Console.WriteLine("drive Name:{0}", dv.Name);
}
Console.ReadLine();
}
}
获取串口:
using System;
using System.IO.Ports;
namespace SerialPortExample
{
class SerialPortExample
{
public static void Main()
{
string[] ports = SerialPort.GetPortNames();
Console.WriteLine("The following serial ports were found:");
foreach (string port in ports)
{
Console.WriteLine(port);
}
Console.ReadLine();
}
}
}
提前谢谢了!