MelsecCommunication.cs
1.99 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
using HHECS.BllModel;
using HslCommunication.Profinet.Melsec;
namespace HHECS.DAQWebClient.Communications
{
public class MelsecCommunication : ICommunication
{
public readonly MelsecMcNet Melsec = null!;
public string IpAddress => Melsec.IpAddress;
public int CommunicationId { get; set; }
private MelsecCommunication() { }
public MelsecCommunication(int communicationId, string ipAddress, int port = 6000)
{
CommunicationId = communicationId;
Melsec = new MelsecMcNet(ipAddress, port);
Melsec.SetPersistentConnection();
}
public BllResult ConnectServer()
{
var result = Melsec.ConnectServer();
if (!result.IsSuccess)
{
return BllResultFactory.Error(result.Message);
}
return BllResultFactory.Success();
}
public BllResult ConnectClose()
{
Melsec.ConnectClose();
return BllResultFactory.Success();
}
// Other methods for reading/writing data would go here
public BllResult Read(IEnumerable<DataItem> dataItems)
{
try
{
//待完善
return BllResultFactory.Success();
}
catch (Exception ex)
{
return BllResultFactory.Error(ex.Message);
}
}
public BllResult Read(DataItem dataItem)
{
return Read(new DataItem[] { dataItem });
}
public BllResult Write(IEnumerable<DataItem> dataItems)
{
try
{
//待完善
return BllResultFactory.Success();
}
catch (Exception ex)
{
return BllResultFactory.Error(ex.Message);
}
}
public BllResult Write(DataItem dataItem)
{
return Write(new DataItem[] { dataItem });
}
}
}