MachineControllor.cs
4.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
//所有控制机器发送指令的类
using System.Threading;
using System;
using System.Collections.Generic;
using System.IO;
using log4net.Repository.Hierarchy;
namespace MachineDll
{
public class MachineControllor
{
private readonly SerialPortSetting _ItsSerialPort;
bool IsDebug = false;
List<double> simulate_data;
List<double>.Enumerator simulate_data_Enumerator;
public MachineControllor(SerialPortSetting itsSerialPort, bool isdebug = false)
{
IsDebug = isdebug;
_ItsSerialPort = itsSerialPort;
if (File.Exists("simulate_data.txt"))
{
try
{
var s = File.ReadAllLines("simulate_data.txt");
simulate_data = new List<double>();
foreach (var ss in s)
{
if (double.TryParse(ss, out double ts))
simulate_data.Add(ts);
}
}
catch { }
}
else {
simulate_data = new List<double>() {1,2,3,4,5,6,7,8 };
}
simulate_data_Enumerator = simulate_data.GetEnumerator();
}
#region NewControlPorts
public void OpenY0()
{
if (IsDebug)
return;
_ItsSerialPort.SendString("%01#WCSY00001**");
}
public void CloseY0()
{
if (IsDebug)
return;
_ItsSerialPort.SendString("%01#WCSY00000**");
}
public void OpenY1()
{
if (IsDebug)
return;
_ItsSerialPort.SendString("%01#WCSY00011**");
}
public void CloseY1()
{
if (IsDebug)
return;
_ItsSerialPort.SendString("%01#WCSY00010**");
}
public void OpenY2()
{
if (IsDebug)
return;
_ItsSerialPort.SendString("%01#WCSY00021**");
}
public void CloseY2()
{
if (IsDebug)
return;
_ItsSerialPort.SendString("%01#WCSY00020**");
}
public void OpenY1Y2()
{//过滤
if (IsDebug)
return;
_ItsSerialPort.SendIOString("01 0F 00 64 00 04 01 06 CF 5C");
}
public void OpenY0Y2()
{//清洗
if (IsDebug)
return;
_ItsSerialPort.SendIOString("01 0F 00 64 00 04 01 05 8F 5D");
}
public void CloseAll()
{//关闭
if (IsDebug)
return;
_ItsSerialPort.SendIOString("01 0F 00 64 00 04 01 00 4F 5E");
}
public double SendAIString()
{//读AI数据
if (IsDebug) {
simulate_data_Enumerator.MoveNext();
return simulate_data_Enumerator.Current;
}
double data = _ItsSerialPort.ReadAIString("01 03 02 58 00 08 C4 67");
var cdata = SerialPortSetting.CurrentConversion(data);
SerialPortSetting.LOGGER.Debug($"IO Return: data:{data}, cov:{cdata}");
return cdata;
}
public bool ReadX0()
{
_ItsSerialPort.SendString("%01#RCSX0000**");
Thread.Sleep(50);
string response = _ItsSerialPort.ReadExisting();
//%01$RC021\r ---response示例
return !response[6].Equals('0');
}
public void TestCommand(string s)
{
_ItsSerialPort.SendString(s);
}
public double GetOHREC10_Value()
{//读AI数据
if (IsDebug)
{
simulate_data_Enumerator.MoveNext();
return simulate_data_Enumerator.Current;
}
double data = _ItsSerialPort.ReadAIString("02 03 00 80 00 02 C5 E3",100,SerialPortSetting.ByteType.Double_32Bit_Little_endian_ByteSwap);
double temp = _ItsSerialPort.ReadAIString("02 03 00 05 00 01 94 0B",10, SerialPortSetting.ByteType.Int16);
SerialPortSetting.LOGGER.Debug($"IO2 Return: data:{data}, temp:{temp}");
return data;
}
#endregion
}
}