Writing to a COM port with .Net
How would I go about开发者_如何学JAVA writing to a COM port, trying to convert the following example to .Net (C#), specifically the PHP part? If possible is there an easier way to write out to a USB?
Use the SerialPort class, e.g.:
SerialPort port = new SerialPort("COM1");
port.Open();
if (port.IsOpen)
{
}
port.Close();
see SerialPort class.
The easiest way to write to USB is through serial port (COMx - on windows). Here are some examples in C#:
http://msdn.microsoft.com/en-us/library/system.io.ports.serialport.open.aspx
See the System.IO.Ports
namespace docs:
The System.IO.Ports namespace contains classes for controlling serial ports. The most important class, SerialPort, provides a framework for synchronous and event-driven I/O, access to pin and break states, and access to serial driver properties. It can be used to wrap a Stream objects, allowing the serial port to be accessed by classes that use streams.
The namespace includes enumerations that simplify the control of serial ports, such as Handshake, Parity, SerialPinChange, and StopBits.
The SerialPort
class documentation contains a detailed usage exmaple.
精彩评论