或0-5v的信号,把信号采集后进行陪大模拟量运算就OK了,具体的要根据PLC品牌来选择相应的指令,然兄岩后根据你温度传感器,压力传感变送器量羡乱御程进行运算。把运算结果传送到你的显示器就ok
了
写好了,两个类分别为:
public enum Mode{
Heating,
Cooling
}
public enum UpDown
{
Up,
Down
}
public class AirConditioner
{
private bool powerOn
private Mode currentMode
private int currentTemp
public AirConditioner()
{
this.powerOn = false
this.currentMode = Mode.Cooling
this.currentTemp = 16
}
public void SwichPower()
{
this.powerOn = !powerOn
}
internal void SetMode(Mode mode)
{
this.currentMode = mode
}
internal void SetTemp(UpDown upDown)
{
switch (upDown)
{
case UpDown.Up:
if (this.currentTemp <= 30)
{
this.currentTemp++
}
break
case UpDown.Down:
if (this.currentTemp >= 16)
{
this.currentTemp--
衡历 }
break
}
}
public 咐肆搜override string ToString()
{
return string.Format("Current Status:\r\nPower: {0}\r\nMode: {1}\r\nTemp: {2}", this.powerOn ? "On" : "Off", this.currentMode, this.currentTemp)
}
} public class RemoteController
{
private AirConditioner conditioner
public RemoteController()
{
this.conditioner = new AirConditioner()
}
public void SwitchPower()
{
this.conditioner.SwichPower()
Console.WriteLine(this.conditioner)
}
public void SetMode(Mode mode)
{
雹闹 this.conditioner.SetMode(mode)
Console.WriteLine(this.conditioner)
}
public void SetTemp(UpDown upDown)
{
this.conditioner.SetTemp(upDown)
Console.WriteLine(this.conditioner)
}
}
值得注意的是,“通过直接 *** 作空调不能进行调节温度、改变模式(制热、制冷)。”这一条说明这些方法应该不允许被声明为public,但是又要能够被遥控器访问,所以应该声明为internal
测试代码:
static void Main(string[] args){
var controller = new RemoteController()
Console.WriteLine("Turn on the conditioner...\r\n")
controller.SwitchPower()
Console.WriteLine("================================================================")
Console.WriteLine("Turn off the conditioner...\r\n")
controller.SwitchPower()
Console.WriteLine("================================================================")
Console.WriteLine("Set the mode as \"cooling\"...\r\n")
controller.SetMode(Mode.Cooling)
Console.WriteLine("================================================================")
Console.WriteLine("Set the mode as \"Heating\"...\r\n")
controller.SetMode(Mode.Heating)
Console.WriteLine("================================================================")
Console.WriteLine("Turn up temp...\r\n")
controller.SetTemp(UpDown.Up)
Console.WriteLine("================================================================")
Console.WriteLine("Turn down temp...\r\n")
controller.SetTemp(UpDown.Down)
}
运行结果:
源码在附件中,如有疑问,欢迎追问。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)