nodalis-compiler 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +134 -0
- package/package.json +59 -0
- package/src/compilers/CPPCompiler.js +272 -0
- package/src/compilers/Compiler.js +108 -0
- package/src/compilers/JSCompiler.js +293 -0
- package/src/compilers/iec-parser/parser.js +4254 -0
- package/src/compilers/st-parser/expressionConverter.js +155 -0
- package/src/compilers/st-parser/gcctranspiler.js +237 -0
- package/src/compilers/st-parser/jstranspiler.js +254 -0
- package/src/compilers/st-parser/parser.js +367 -0
- package/src/compilers/st-parser/tokenizer.js +78 -0
- package/src/compilers/support/generic/json.hpp +25526 -0
- package/src/compilers/support/generic/modbus.cpp +378 -0
- package/src/compilers/support/generic/modbus.h +124 -0
- package/src/compilers/support/generic/nodalis.cpp +421 -0
- package/src/compilers/support/generic/nodalis.h +798 -0
- package/src/compilers/support/generic/opcua.cpp +267 -0
- package/src/compilers/support/generic/opcua.h +50 -0
- package/src/compilers/support/generic/open62541.c +151897 -0
- package/src/compilers/support/generic/open62541.h +50357 -0
- package/src/compilers/support/jint/nodalis/Nodalis.sln +28 -0
- package/src/compilers/support/jint/nodalis/NodalisEngine/ModbusClient.cs +200 -0
- package/src/compilers/support/jint/nodalis/NodalisEngine/NodalisEngine.cs +817 -0
- package/src/compilers/support/jint/nodalis/NodalisEngine/NodalisEngine.csproj +16 -0
- package/src/compilers/support/jint/nodalis/NodalisEngine/OPCClient.cs +172 -0
- package/src/compilers/support/jint/nodalis/NodalisEngine/OPCServer.cs +275 -0
- package/src/compilers/support/jint/nodalis/NodalisPLC/NodalisPLC.csproj +19 -0
- package/src/compilers/support/jint/nodalis/NodalisPLC/Program.cs +197 -0
- package/src/compilers/support/jint/nodalis/NodalisPLC/bootstrap.bat +5 -0
- package/src/compilers/support/jint/nodalis/NodalisPLC/bootstrap.sh +5 -0
- package/src/compilers/support/jint/nodalis/build.bat +25 -0
- package/src/compilers/support/jint/nodalis/build.sh +31 -0
- package/src/compilers/support/nodejs/IOClient.js +110 -0
- package/src/compilers/support/nodejs/modbus.js +115 -0
- package/src/compilers/support/nodejs/nodalis.js +662 -0
- package/src/compilers/support/nodejs/opcua.js +194 -0
- package/src/nodalis.js +174 -0
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
|
|
2
|
+
Microsoft Visual Studio Solution File, Format Version 12.00
|
|
3
|
+
# Visual Studio Version 17
|
|
4
|
+
VisualStudioVersion = 17.0.31903.59
|
|
5
|
+
MinimumVisualStudioVersion = 10.0.40219.1
|
|
6
|
+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NodalisEngine", "NodalisEngine\NodalisEngine.csproj", "{108ECD98-6353-4039-9531-2D1A2F5C6B79}"
|
|
7
|
+
EndProject
|
|
8
|
+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NodalisPLC", "NodalisPLC\NodalisPLC.csproj", "{0A564B0C-881D-4862-8913-9EC89DF69D63}"
|
|
9
|
+
EndProject
|
|
10
|
+
Global
|
|
11
|
+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
|
12
|
+
Debug|Any CPU = Debug|Any CPU
|
|
13
|
+
Release|Any CPU = Release|Any CPU
|
|
14
|
+
EndGlobalSection
|
|
15
|
+
GlobalSection(SolutionProperties) = preSolution
|
|
16
|
+
HideSolutionNode = FALSE
|
|
17
|
+
EndGlobalSection
|
|
18
|
+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
|
19
|
+
{108ECD98-6353-4039-9531-2D1A2F5C6B79}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
|
20
|
+
{108ECD98-6353-4039-9531-2D1A2F5C6B79}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
|
21
|
+
{108ECD98-6353-4039-9531-2D1A2F5C6B79}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
|
22
|
+
{108ECD98-6353-4039-9531-2D1A2F5C6B79}.Release|Any CPU.Build.0 = Release|Any CPU
|
|
23
|
+
{0A564B0C-881D-4862-8913-9EC89DF69D63}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
|
24
|
+
{0A564B0C-881D-4862-8913-9EC89DF69D63}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
|
25
|
+
{0A564B0C-881D-4862-8913-9EC89DF69D63}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
|
26
|
+
{0A564B0C-881D-4862-8913-9EC89DF69D63}.Release|Any CPU.Build.0 = Release|Any CPU
|
|
27
|
+
EndGlobalSection
|
|
28
|
+
EndGlobal
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
#nullable enable
|
|
2
|
+
|
|
3
|
+
// Copyright [2025] Nathan Skipper
|
|
4
|
+
//
|
|
5
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
// you may not use this file except in compliance with the License.
|
|
7
|
+
// You may obtain a copy of the License at
|
|
8
|
+
//
|
|
9
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
//
|
|
11
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
// See the License for the specific language governing permissions and
|
|
15
|
+
// limitations under the License.
|
|
16
|
+
|
|
17
|
+
/// <summary>
|
|
18
|
+
/// Modbus Client for .NET
|
|
19
|
+
/// </summary>
|
|
20
|
+
using System;
|
|
21
|
+
using System.Collections.Generic;
|
|
22
|
+
using System.Net.Sockets;
|
|
23
|
+
using System.Net;
|
|
24
|
+
using System.Text;
|
|
25
|
+
|
|
26
|
+
namespace Nodalis
|
|
27
|
+
{
|
|
28
|
+
/// <summary>
|
|
29
|
+
/// The ModbusClient class implements IOClient to provide communications to a Modbus TCP slave device.
|
|
30
|
+
/// </summary>
|
|
31
|
+
public class ModbusClient : IOClient
|
|
32
|
+
{
|
|
33
|
+
private TcpClient client;
|
|
34
|
+
private NetworkStream stream;
|
|
35
|
+
private string ip = "";
|
|
36
|
+
private int port = 502;
|
|
37
|
+
private byte unitId = 1;
|
|
38
|
+
private ushort transactionId = 0;
|
|
39
|
+
|
|
40
|
+
public ModbusClient() : base("MODBUS-TCP")
|
|
41
|
+
{
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
public override void Connect()
|
|
45
|
+
{
|
|
46
|
+
if (connected) Disconnect();
|
|
47
|
+
|
|
48
|
+
if (mappings.Count > 0)
|
|
49
|
+
{
|
|
50
|
+
ip = mappings[0].moduleID;
|
|
51
|
+
port = int.Parse(mappings[0].modulePort);
|
|
52
|
+
moduleID = ip;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
try
|
|
56
|
+
{
|
|
57
|
+
client = new TcpClient();
|
|
58
|
+
client.Connect(ip, port);
|
|
59
|
+
stream = client.GetStream();
|
|
60
|
+
connected = true;
|
|
61
|
+
}
|
|
62
|
+
catch
|
|
63
|
+
{
|
|
64
|
+
connected = false;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
private void Disconnect()
|
|
69
|
+
{
|
|
70
|
+
if (connected)
|
|
71
|
+
{
|
|
72
|
+
stream?.Close();
|
|
73
|
+
client?.Close();
|
|
74
|
+
connected = false;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
private bool SendRequest(byte function, ushort startAddress, ushort quantity, byte[]? payload, out byte[] response)
|
|
79
|
+
{
|
|
80
|
+
response = Array.Empty<byte>();
|
|
81
|
+
if (!connected) return false;
|
|
82
|
+
|
|
83
|
+
transactionId++;
|
|
84
|
+
var mbap = new byte[7];
|
|
85
|
+
mbap[0] = (byte)(transactionId >> 8);
|
|
86
|
+
mbap[1] = (byte)(transactionId & 0xFF);
|
|
87
|
+
mbap[2] = 0; mbap[3] = 0;
|
|
88
|
+
ushort length = (ushort)(1 + 1 + 2 + 2 + (payload?.Length ?? 0));
|
|
89
|
+
mbap[4] = (byte)(length >> 8);
|
|
90
|
+
mbap[5] = (byte)(length & 0xFF);
|
|
91
|
+
mbap[6] = unitId;
|
|
92
|
+
|
|
93
|
+
var pdu = new List<byte> { function, (byte)(startAddress >> 8), (byte)(startAddress & 0xFF) };
|
|
94
|
+
if (function == 0x01 || function == 0x02 || function == 0x03 || function == 0x04)
|
|
95
|
+
{
|
|
96
|
+
pdu.Add((byte)(quantity >> 8));
|
|
97
|
+
pdu.Add((byte)(quantity & 0xFF));
|
|
98
|
+
}
|
|
99
|
+
else if (payload != null)
|
|
100
|
+
{
|
|
101
|
+
pdu.AddRange(payload);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
var request = new List<byte>(mbap);
|
|
105
|
+
request.AddRange(pdu);
|
|
106
|
+
|
|
107
|
+
try
|
|
108
|
+
{
|
|
109
|
+
stream.Write(request.ToArray(), 0, request.Count);
|
|
110
|
+
byte[] buffer = new byte[260];
|
|
111
|
+
int read = stream.Read(buffer, 0, buffer.Length);
|
|
112
|
+
if (read >= 9)
|
|
113
|
+
{
|
|
114
|
+
response = new byte[read - 7];
|
|
115
|
+
Array.Copy(buffer, 7, response, 0, response.Length);
|
|
116
|
+
return true;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
catch
|
|
120
|
+
{
|
|
121
|
+
Disconnect();
|
|
122
|
+
}
|
|
123
|
+
return false;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
public override bool ReadBit(string address, out int result)
|
|
127
|
+
{
|
|
128
|
+
result = 0;
|
|
129
|
+
if (!ushort.TryParse(address, out var addr)) return false;
|
|
130
|
+
if (!SendRequest(0x02, addr, 1, null, out var response)) return false;
|
|
131
|
+
result = (response[2] & 0x01) != 0 ? 1 : 0;
|
|
132
|
+
return true;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
public override bool WriteBit(string address, int value)
|
|
136
|
+
{
|
|
137
|
+
if (!ushort.TryParse(address, out var addr)) return false;
|
|
138
|
+
var payload = new byte[] {
|
|
139
|
+
(byte)(value != 0 ? 0xFF : 0x00), 0x00
|
|
140
|
+
};
|
|
141
|
+
return SendRequest(0x05, addr, 0, payload, out _);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
public override bool ReadByte(string address, out byte result)
|
|
145
|
+
{
|
|
146
|
+
result = 0;
|
|
147
|
+
if (!ushort.TryParse(address, out var addr)) return false;
|
|
148
|
+
if (!SendRequest(0x03, addr, 1, null, out var response)) return false;
|
|
149
|
+
result = response.Length >= 3 ? response[2] : (byte)0;
|
|
150
|
+
return true;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
public override bool WriteByte(string address, byte value)
|
|
154
|
+
{
|
|
155
|
+
if (!ushort.TryParse(address, out var addr)) return false;
|
|
156
|
+
var payload = new byte[] { (byte)(addr >> 8), (byte)(addr & 0xFF), 0x00, value };
|
|
157
|
+
return SendRequest(0x06, addr, 1, payload, out _);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
public override bool ReadWord(string address, out ushort result)
|
|
161
|
+
{
|
|
162
|
+
result = 0;
|
|
163
|
+
if (!ushort.TryParse(address, out var addr)) return false;
|
|
164
|
+
if (!SendRequest(0x03, addr, 1, null, out var response)) return false;
|
|
165
|
+
result = (ushort)((response[2] << 8) | response[3]);
|
|
166
|
+
return true;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
public override bool WriteWord(string address, ushort value)
|
|
170
|
+
{
|
|
171
|
+
if (!ushort.TryParse(address, out var addr)) return false;
|
|
172
|
+
var payload = new byte[] {
|
|
173
|
+
(byte)(addr >> 8), (byte)(addr & 0xFF),
|
|
174
|
+
(byte)(value >> 8), (byte)(value & 0xFF)
|
|
175
|
+
};
|
|
176
|
+
return SendRequest(0x06, addr, 1, payload, out _);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
public override bool ReadDWord(string address, out uint result)
|
|
180
|
+
{
|
|
181
|
+
result = 0;
|
|
182
|
+
if (!ushort.TryParse(address, out var addr)) return false;
|
|
183
|
+
if (!SendRequest(0x03, addr, 2, null, out var response)) return false;
|
|
184
|
+
result = (uint)((response[2] << 24) | (response[3] << 16) | (response[4] << 8) | response[5]);
|
|
185
|
+
return true;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
public override bool WriteDWord(string address, uint value)
|
|
189
|
+
{
|
|
190
|
+
if (!ushort.TryParse(address, out var addr)) return false;
|
|
191
|
+
var payload = new byte[] {
|
|
192
|
+
(byte)(addr >> 8), (byte)(addr & 0xFF),
|
|
193
|
+
0x04,
|
|
194
|
+
(byte)(value >> 24), (byte)((value >> 16) & 0xFF),
|
|
195
|
+
(byte)((value >> 8) & 0xFF), (byte)(value & 0xFF)
|
|
196
|
+
};
|
|
197
|
+
return SendRequest(0x10, addr, 2, payload, out _);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|