L
lotus
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.WriteLine is acaully substitution of
sending command to instrument.
-----------Code start-------------------------------
using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication1
{
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.WriteLine("Select instrument 1 or 2");
string input = Console.ReadLine();
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.WriteLine(" instrument 1 is initilized");
}
void machine.turn_on()
{
Console.WriteLine("turn on");
}
}
public class instrument2 : machine
{
int id = 5;
public instrument2(ref int id_)
{
id = id_;
Console.WriteLine(" instrument 2 is initilized");
}
void machine.turn_on()
{
Console.WriteLine("power on");
Console.WriteLine("I need more step -- plevel 1");
}
}
}
------------------ end of code ----------------
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.WriteLine is acaully substitution of
sending command to instrument.
-----------Code start-------------------------------
using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication1
{
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.WriteLine("Select instrument 1 or 2");
string input = Console.ReadLine();
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.WriteLine(" instrument 1 is initilized");
}
void machine.turn_on()
{
Console.WriteLine("turn on");
}
}
public class instrument2 : machine
{
int id = 5;
public instrument2(ref int id_)
{
id = id_;
Console.WriteLine(" instrument 2 is initilized");
}
void machine.turn_on()
{
Console.WriteLine("power on");
Console.WriteLine("I need more step -- plevel 1");
}
}
}
------------------ end of code ----------------