Hola Happy New Year !! ~ im doing this project on C# programming and im stucked on it for many days.

What i need to do is to read either '0' or '1' from a circuit ( external circuit board is connected to my laptop via serial port ), and based on either '0' or '1'received, different videos ( video 1 or video 2) will be played.

The following is my source code by far, and there're 6 errors which popped out and i have no idea how to fix it.

using System;
using System.Collections.Generic;
using System.Text;
using System.IO.Ports;

namespace cs_open_videos
{
class Program
{
static void Main(string[] args)
{
OpenSerialPort();
//String fileToOpen = "C:/myog.avi"; System.Diagnostics.ProcessStartInfo ps = new System.Diagnostics.ProcessStartInfo("C:/Program Files/Windows Media Player/wmplayer.exe/play/fullscreen", fileToOpen); System.Diagnostics.Process.Start(ps);
} 
SerialPort com=new SerialPort();
private void OpenSerialPort()
{
SerialPort com=new SerialPort();

com.BaudRate=38400;

com.Open();
com.DataReceived = OnRecieved;

}
private void OnRecieved(object sender, SerialDataReceivedEventArgs c)
{

char c = com.ReadChar();
switch ©
{
case "0":

String fileToOpen = "C:/video1.avi"; System.Diagnostics.ProcessStartInfo 
ps = new 
System.Diagnostics.ProcessStartInfo("C:/Program Files/Windows Media Player/wmplayer.exe/play/fullscreen", fileToOpen); System.Diagnostics.Process.Start(ps);
case "1" :
String fileToOpen = "C:/video2.avi"; System.Diagnostics.ProcessStartInfo ps = new 
System.Diagnostics.ProcessStartInfo("C:/Program Files/Windows Media Player/wmplayer.exe/play/fullscreen", fileToOpen); System.Diagnostics.Process.Start(ps);


play();

}


}
}
}

8 errors occured in my coding, and are shown in the following:

Error 1
An object reference is required for the nonstatic field,
method, or property 'cs_open_videos.Program.OpenSerialPort()'

Error 2
The event 'System.IO.Ports.SerialPort.DataReceived' can only appear on the left hand side of += or -=

Error 3
A local variable named 'c' cannot be declared in this scope because it would give a different meaning to 'c', which is already used in a 'parent or current' scope to denote something els

Error 4
Cannot implicitly convert type 'int' to 'System.IO.Ports.SerialDataReceivedEventArgs'

Error 5
A value of an integral type expected

Error 6
A local variable named 'fileToOpen' is already defined in this scope

Error 7
A local variable named 'ps' is already defined in this scope

Error 8
The name 'play' does not exist in the current context

Can anybody pls help me fix this? Thank you in advance

Error 1 :
private void OpenSerialPort() should be private static void...
maybe this eliminates some of your other errors. Let me know.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.