프로그래밍 할 때 새로운 기능입니다.시리얼 포트를 통한 송수신은 작동하지 않습니다.
일부 테스트를 위해 터미널 프로그램을 만들고 있는데,이 프로그램은 직렬 널 모뎀을 통해 데이터를 송수신해야합니다. MSDN에서 예제를 찾았습니다. http://msdn.microsoft.com/en-us/library/y2sxhat8.aspx?cs-save-lang=1&cs-lang=csharp#code-snippet-2
하지만 제대로 작동하지 않습니다.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO.Ports;
using System.Threading;
namespace Terminal_0._0._0._2
{
class Program
{
public static void Main()
{
string name;
string message;
StringComparer stringComparer = StringComparer.OrdinalIgnoreCase;
Thread readThread = new Thread(Read);
// Create a new SerialPort object with default settings.
SerialPort _serialPort = new SerialPort();
// Allow the user to set the appropriate properties.
_serialPort.PortName = "COM8";
_serialPort.BaudRate = 115200;
_serialPort.Parity = Parity.None;
_serialPort.DataBits = 8;
_serialPort.StopBits = StopBits.One;
_serialPort.Handshake = Handshake.None;
// Set the read/write timeouts
_serialPort.ReadTimeout = 500;
_serialPort.WriteTimeout = 500;
_serialPort.Open();
var _continue = true;
readThread.Start();
Console.Write("Name: ");
name = Console.ReadLine();
Console.WriteLine("Type QUIT to exit");
while (_continue)
{
message = Console.ReadLine();
if (stringComparer.Equals("quit", message))
{
_continue = false;
}
else
{
_serialPort.WriteLine(
String.Format("<{0}>: {1}", name, message));
}
}
readThread.Join();
_serialPort.Close();
}
}
public static void Read()
{
while (_continue)
{
try
{
string message = _serialPort.ReadLine();
Console.WriteLine(message);
}
catch (TimeoutException) { }
}
}
}
는이 오류를 얻을 : 여기에 내가 지금 무엇을 가지고 예상 클래스, 위임, 열거, 라인 인터페이스 또는 구조체 : 66 칼럼 : 사전에 19 개
감사합니다.
난 당신이 문제의 더 나은 제목 .. –
그래서 문제가 정확히 무엇을해야 할 것 같아요? "일할 수 없다"는 것은 우리에게 아무 일도하지 않는다. –
어떤 오류 메시지가 나타 납니까? –