私はシリアルIOポートのデータ受信したイベントを書いていますとイベントハンドラのエラーが...次は、ラインコードのC#、シリアルポート
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.IO; //add namespaces
using System.IO.Ports;
public class Program
{
//define a delegate class to handle DataReceived events
internal delegate void SerialDataReceivedEventHanderDelegate(object sender,SerialDataReceivedEventArgs e);
internal void DataReceived(object sender, SerialDataReceivedEventArgs e)
{
//place code to read and process data here
}
static void Main()
{
string myComPortName=null;
//1. find available COM port
string[] nameArray = null;
nameArray = SerialPort.GetPortNames();
if(nameArray.GetUpperBound(0)>0) {
myComPortName = nameArray[0];
}
else {
Console.WriteLine("Error");
return;
}
//2. create a serialport object
// the port object is closed automatically by use using()
SerialPort myComPort = new SerialPort();
myComPort.PortName = myComPortName; //the default paramit are 9600,no parity,one stop bit, and no flow control
private static SerialDataReceivedEventHandler SerialDataReceivedEventHandler1 =
new SerialDataReceivedEventHandler(ComPort.DataReceived);
myComPort.DataReceived+=SerialDataReceivedEventHandler1;
}
}
なぜVS2010でありますSerialDataReceivedEventHandler(ComPort.DataReceived);
私を見せている。 1.無効な式の用語「プライベート」 2.修飾子「静的」 3.私はここでCOMポートを使用する必要があり、この用語には有効ではありませんか?またはちょうどDataReceived ...その関数名から
あなたの返事をありがとう。出宣言を移動し、
var SerialDataReceivedEventHandler1 =
new SerialDataReceivedEventHandler(ComPort.DataReceived);
いますが、それはプログラムのクラスのメンバーになりたいしている場合: - - :
アクセス修飾子を宣言する時期と方法、アクセス可能な/公開されていないことを判断する上で参考になる良いサイトです。 http://msdn.microsoft.com/en-us/library/wxh6fsc7%28v=vs.71%29.aspx – MethodMan