EfortCommunication.cs
4.94 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
using DataAcquisition.Common.Enums;
using DataAcquisition.Common.Utils;
using DataAcquisition.Models;
using HslCommunication;
using HslCommunication.Robot.EFORT;
namespace DataAcquisition.Common.Communications
{
/// <summary>
/// Efort机器人通讯
/// </summary>
public class EfortCommunication : ICommunication
{
public int CommunicationId { get; set; }
public string IpAddress => client.IpAddress;
private readonly ER7BC10 client = null!;
private SystemLog log = SystemLog.Instance;
private EfortCommunication() { }
public EfortCommunication(int communicationId, string ipAddress, int port)
{
CommunicationId = communicationId;
client = new ER7BC10(ipAddress, port);
client.SetPersistentConnection();
}
public OperateResult ConnectClose()
{
try
{
client.ConnectClose();
return OperateResult.CreateSuccessResult();
}
catch (Exception ex)
{
return new OperateResult
{
ErrorCode = 500,
IsSuccess = false,
Message = ex.Message,
};
}
}
public OperateResult ConnectServer()
{
try
{
return client.ConnectServer();
}
catch (Exception ex)
{
return new OperateResult
{
ErrorCode = 500,
IsSuccess = false,
Message = ex.Message,
};
}
}
public void Read(IEnumerable<EquipmentProperty> equipmentProperties)
{
try
{
var result = client.ReadEfortData();
if (!result.IsSuccess)
{
log.LogError($"读取Efort[{IpAddress}]数据失败,{result.Message}");
}
var data = result.Content;
foreach (var item in equipmentProperties)
{
_ = Enum.TryParse<RobotProps>(item.Code, out var robotPropCode);
item.Value = robotPropCode switch
{
RobotProps.BootFlag => bool.TrueString,
//RobotProps.WorkFlag => throw new NotImplementedException(),
//RobotProps.WeldFlag => throw new NotImplementedException(),
//RobotProps.WeldCompleteFlag => throw new NotImplementedException(),
//RobotProps.Weld_V => throw new NotImplementedException(),
//RobotProps.Weld_I => throw new NotImplementedException(),
//RobotProps.Weld_Speed => throw new NotImplementedException(),
//RobotProps.Weld_Gas => throw new NotImplementedException(),
//RobotProps.Gas_Flow => throw new NotImplementedException(),
//RobotProps.Weld_CleanGun => throw new NotImplementedException(),
RobotProps.Alarm => Convert.ToBoolean(data.ErrorStatus).ToString(),
//RobotProps.Work_Time => throw new NotImplementedException(),
RobotProps.Work_Mode => data.ModeStatus.ToString(),
//RobotProps.Type => throw new NotImplementedException(),
RobotProps.Pos_X => data.DbCartPos[0].ToString(),
RobotProps.Pos_Y => data.DbCartPos[1].ToString(),
RobotProps.Pos_Z => data.DbCartPos[2].ToString(),
RobotProps.Pos_A => data.DbCartPos[3].ToString(),
RobotProps.Pos_B => data.DbCartPos[4].ToString(),
RobotProps.Pos_C => data.DbCartPos[5].ToString(),
//RobotProps.Pos_E1 => throw new NotImplementedException(),
//RobotProps.Pos_E2 => throw new NotImplementedException(),
//RobotProps.Pos_E3 => throw new NotImplementedException(),
//RobotProps.Pos_E4 => throw new NotImplementedException(),
RobotProps.Program_No => data.ProgramName,
_ => string.Empty,
};
}
}
catch (Exception ex)
{
log.LogError($"读取Efort[{IpAddress}]数据失败,{ex.Message}");
}
}
public void Read(EquipmentProperty equipmentProperty)
{
Read([equipmentProperty]);
}
public void Write(IEnumerable<EquipmentProperty> equipmentProperties)
{
log.LogError($"Efort机器人[{IpAddress}]不支持数据写入操作");
}
public void Write(EquipmentProperty equipmentProperty)
{
Write([equipmentProperty]);
}
}
}