output based on data read by serial port

different videos played based on the number data received.

Page 1 of 1

3 Replies - 2312 Views - Last Post: 27 December 2008 - 11:37 PM Rate Topic: -----

#1 james557  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 17-December 08

output based on data read by serial port

Posted 26 December 2008 - 02:25 AM

Hola ~ 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();
			
			}
			
		
		}
	}
}









6 errors occured after i compiled and built it. Pls help me out.

Cheers,
James :)

Is This A Good Question/Topic? 0
  • +

Replies To: output based on data read by serial port

#2 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 418
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: output based on data read by serial port

Posted 26 December 2008 - 10:41 AM

Can you post the exact error messages that you are currently receiving?
Was This Post Helpful? 0
  • +
  • -

#3 ibbz101  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 3
  • Joined: 26-December 08

Re: output based on data read by serial port

Posted 26 December 2008 - 01:34 PM

Hi James,

You had a few errors.. Try the following (note: i havnt tested this):

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

namespace cs_open_videos
{
	class Program
	{
		static void Main(string[] args)
		{
			OpenSerialPort();
			//Process.Start("D:/videos/myvideo.avi");

		} 
		public static SerialPort com=new SerialPort();
		private static void OpenSerialPort()
		{
			//SerialPort com=new SerialPort();

			com.BaudRate=38400;
			
			com.Open();
			com.DataReceived += OnRecieved;
		
		}
		private static void OnRecieved(object sender, SerialDataReceivedEventArgs c)
		{

			int ca = com.ReadChar();
			switch (ca)
			{
				case 0:
				Process.Start("D:/videos/myvideo1.avi");
				break;

				case 1:
				Process.Start("D:/videos/myvideo2.avi");
				break;
			
			}
			
		
		}
	}
}


This post has been edited by ibbz101: 26 December 2008 - 01:35 PM

Was This Post Helpful? 0
  • +
  • -

#4 james557  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 17-December 08

Re: output based on data read by serial port

Posted 27 December 2008 - 11:37 PM

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
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1