EfortCommunication.cs
4.9 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
using DataAcquisition.Common.Enums;
using DataAcquisition.Models;
using HHECS.BllModel;
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 EfortCommunication() { }
public EfortCommunication(int communicationId, string ipAddress, int port)
{
CommunicationId = communicationId;
client = new ER7BC10(ipAddress, port);
client.SetPersistentConnection();
}
public BllResult ConnectClose()
{
try
{
client.ConnectClose();
return BllResultFactory.Success();
}
catch (Exception ex)
{
return BllResultFactory.Error(ex.Message);
}
}
public BllResult ConnectServer()
{
try
{
var result = client.ConnectServer();
if (!result.IsSuccess)
{
return BllResultFactory.Error(result.Message);
}
return BllResultFactory.Success();
}
catch (Exception ex)
{
return BllResultFactory.Error(ex.Message);
}
}
public BllResult Read(IEnumerable<EquipmentProperty> equipmentProperties)
{
try
{
var result = client.ReadEfortData();
if (!result.IsSuccess)
{
return BllResultFactory.Error($"读取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,
};
}
return BllResultFactory.Success();
}
catch (Exception ex)
{
return BllResultFactory.Error($"读取Efort[{IpAddress}]数据失败,{ex.Message}");
}
}
public BllResult Read(EquipmentProperty equipmentProperty)
{
return Read([equipmentProperty]);
}
public BllResult Write(IEnumerable<EquipmentProperty> equipmentProperties)
{
return BllResultFactory.Error($"Efort机器人[{IpAddress}]不支持数据写入操作");
}
public BllResult Write(EquipmentProperty equipmentProperty)
{
return Write([equipmentProperty]);
}
}
}