Hi all.
I want to control two different instrtument but have simliar
functionality.
Acually the fisrt one is controlled by using serial communication, and
the other is controlled by LAN communication.
The number of instruments will be extetned by 5 or more.
So If user select instrument (ex. by selection of combo box items), I
must do right procedure of contolling proper instrument.
I want to contol these instrument by same command. so I select
following strategy by using INTERFACE keyword of C#.
Is it right strategy? Is there more powerful method?
---lotus----
In the following code, Console.WriteLi ne is acaully substitution of
sending command to instrument.
-----------Code start-------------------------------
using System;
using System.Collecti ons.Generic;
using System.Text;
namespace ConsoleApplicat ion1
{
class Program
{
static void Main(string[] args)
{
int id = 5;
machine src;
instrument1 ins1 = new instrument1(ref id);
instrument2 ins2 = new instrument2(ref id);
Console.WriteLi ne("Select instrument 1 or 2");
string input = Console.ReadLin e();
if (input =="1")
{
src = ins1;
src.turn_on();
}
else if (input == "2")
{
src = ins2;
src.turn_on();
}
}
}
public interface machine
{
void turn_on();
}
public class instrument1 : machine
{
int id = 3;
public instrument1(ref int id_)
{
id = id_;
Console.WriteLi ne(" instrument 1 is initilized");
}
void machine.turn_on ()
{
Console.WriteLi ne("turn on");
}
}
public class instrument2 : machine
{
int id = 5;
public instrument2(ref int id_)
{
id = id_;
Console.WriteLi ne(" instrument 2 is initilized");
}
void machine.turn_on ()
{
Console.WriteLi ne("power on");
Console.WriteLi ne("I need more step -- plevel 1");
}
}
}
------------------ end of code ----------------