Note that there are some explanatory texts on larger screens.

plurals
  1. POC#, event handler error with Serial Port
    primarykey
    data
    text
    <p>I am writing a data received event For Serial IO port...the following is the code</p> <pre><code> 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)&gt;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; } } </code></pre> <p>Why in VS2010, Line: private static SerialDataReceivedEventHandler SerialDataReceivedEventHandler1 = new SerialDataReceivedEventHandler(ComPort.DataReceived);</p> <p>is showing me: 1. invalid expression term 'private' 2. the modifier 'static' is not valid for this term 3. should I use Comport here? or just DataReceived...since its the function name</p> <p>Thanks for your reply.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload