diff --git a/CyberSystem/ApiServer/ApiServer.csproj b/CyberSystem/ApiServer/ApiServer.csproj new file mode 100644 index 0000000..9ecfb79 --- /dev/null +++ b/CyberSystem/ApiServer/ApiServer.csproj @@ -0,0 +1,17 @@ + + + + net8.0 + enable + enable + + + + + + + + + + + diff --git a/CyberSystem/ApiServer/Controllers/PostContoller.cs b/CyberSystem/ApiServer/Controllers/PostContoller.cs new file mode 100644 index 0000000..d7a0ed5 --- /dev/null +++ b/CyberSystem/ApiServer/Controllers/PostContoller.cs @@ -0,0 +1,26 @@ +using Microsoft.AspNetCore.Components; +using Microsoft.AspNetCore.Mvc; +using RouteAttribute = Microsoft.AspNetCore.Mvc.RouteAttribute; + + +namespace ApiServer.Controllers +{ + [ApiController] + [Route("api")] + public class PostContoller + { + [HttpGet] + [Route("post")] + public string GetUserPost() + { + return "Hello, user! Your post is best!"; + } + + [HttpGet] + [Route("admin")] + public string GetAdmin() + { + return "Hello, Admin! It's your POST!!!"; + } + } +} diff --git a/CyberSystem/ApiServer/Controllers/StateController.cs b/CyberSystem/ApiServer/Controllers/StateController.cs new file mode 100644 index 0000000..6a4eafd --- /dev/null +++ b/CyberSystem/ApiServer/Controllers/StateController.cs @@ -0,0 +1,36 @@ +using Microsoft.AspNetCore.Http.HttpResults; +using Microsoft.AspNetCore.Mvc; + +namespace ApiServer.Controllers +{ + [ApiController] + [Route("api/state")] + public class StateContoller + { + //[HttpGet] + //public byte GetActualState() + //{ + // return GetActualStateFromCom.CurrentState; + //} + + [HttpGet] + [Route("modbus")] + [Produces("application/json")] + public JsonResult GetActualState() + { + //if (inputIndex > 1) + //{ + //return new NotFoundResult(); + //throw new ArgumentOutOfRangeException(nameof(inputIndex), "Значение может быть от 0 до 1 включительно."); + //} + var inputIndex = 1; + var result = GetActualStateFromComWithModbus.CurrentState[inputIndex] + ? 1 + : 0; + + var obj = new { CoilResult = result }; + + return new JsonResult(obj); + } + } +} diff --git a/CyberSystem/ApiServer/GetActualStateFromCom.cs b/CyberSystem/ApiServer/GetActualStateFromCom.cs new file mode 100644 index 0000000..de2274b --- /dev/null +++ b/CyberSystem/ApiServer/GetActualStateFromCom.cs @@ -0,0 +1,48 @@ +using System; +using System.IO.Ports; +using System.Threading; +using System.Threading.Tasks; + + +namespace ApiServer +{ + public class GetActualStateFromCom : IHostedService, IDisposable + { + public static byte CurrentState { get; set; } + + static SerialPort _serialPort; + + static void DataReceivedHandler(object sender, SerialDataReceivedEventArgs e) + { + SerialPort serialPort = (SerialPort)sender; + string receivedData = serialPort.ReadExisting(); + + Console.WriteLine("Полученные данные: " + receivedData); + CurrentState = Convert.ToByte(receivedData); + } + + public Task StartAsync(CancellationToken cancellationToken) + { + string portName = "COM3"; + int baudRate = 9600; + + _serialPort = new SerialPort(portName, baudRate); + _serialPort.DataReceived += new SerialDataReceivedEventHandler(DataReceivedHandler); + _serialPort.Open(); + + Console.WriteLine("Чтение данных с порта: " + portName); + + return Task.CompletedTask; + } + + public Task StopAsync(CancellationToken cancellationToken) + { + return Task.CompletedTask; + } + + public void Dispose() + { + _serialPort.Dispose(); + } + } +} diff --git a/CyberSystem/ApiServer/GetActualStateFromComWithModbus.cs b/CyberSystem/ApiServer/GetActualStateFromComWithModbus.cs new file mode 100644 index 0000000..9af4f41 --- /dev/null +++ b/CyberSystem/ApiServer/GetActualStateFromComWithModbus.cs @@ -0,0 +1,37 @@ +using Modbus.Device; +using System.IO.Ports; + + +namespace ApiServer +{ + public class GetActualStateFromComWithModbus : BackgroundService, IDisposable + { + public static bool[] CurrentState { get; set; } + + private static SerialPort? _serialPort; + private static ModbusSerialMaster? _serialMaster; + + protected override async Task ExecuteAsync(CancellationToken stoppingToken) + { + _serialPort = new SerialPort(); + _serialPort.PortName = "COM5"; + _serialPort.BaudRate = 9600; + _serialPort.DataBits = 8; + _serialPort.Parity = Parity.None; + _serialPort.StopBits = StopBits.One; + _serialPort.Open(); + + _serialMaster = ModbusSerialMaster.CreateRtu(_serialPort); + byte slaveID = 1; + ushort startAddress = 0; + ushort numOfPoints = 2; + + while (!stoppingToken.IsCancellationRequested) + { + CurrentState = _serialMaster.ReadInputs(slaveID, startAddress, numOfPoints); + await Task.Delay(100, stoppingToken); + } + await Task.CompletedTask; + } + } +} diff --git a/CyberSystem/ApiServer/Program.cs b/CyberSystem/ApiServer/Program.cs new file mode 100644 index 0000000..6647018 --- /dev/null +++ b/CyberSystem/ApiServer/Program.cs @@ -0,0 +1,28 @@ +using ApiServer; + +var builder = WebApplication.CreateBuilder(args); + +// Add services to the container. + +builder.Services.AddControllers(); +// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle +builder.Services.AddEndpointsApiExplorer(); +builder.Services.AddSwaggerGen(); +//builder.Services.AddHostedService(); +builder.Services.AddHostedService(); + +var app = builder.Build(); + +// Configure the HTTP request pipeline. +if (app.Environment.IsDevelopment()) +{ + app.UseSwagger(); + app.UseSwaggerUI(); +} + +app.UseAuthorization(); + +app.MapControllers(); + +app.Run(); + diff --git a/CyberSystem/ApiServer/Properties/launchSettings.json b/CyberSystem/ApiServer/Properties/launchSettings.json new file mode 100644 index 0000000..3785afb --- /dev/null +++ b/CyberSystem/ApiServer/Properties/launchSettings.json @@ -0,0 +1,31 @@ +{ + "$schema": "http://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://0.0.0.0:3819", + "sslPort": 0 + } + }, + "profiles": { + "http": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "launchUrl": "swagger", + "applicationUrl": "http://0.0.0.0:12344", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/CyberSystem/ApiServer/appsettings.Development.json b/CyberSystem/ApiServer/appsettings.Development.json new file mode 100644 index 0000000..0c208ae --- /dev/null +++ b/CyberSystem/ApiServer/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/CyberSystem/ApiServer/appsettings.json b/CyberSystem/ApiServer/appsettings.json new file mode 100644 index 0000000..10f68b8 --- /dev/null +++ b/CyberSystem/ApiServer/appsettings.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*" +} diff --git a/CyberSystem/CyberSystem.sln b/CyberSystem/CyberSystem.sln index 6d19b17..2ec6940 100644 --- a/CyberSystem/CyberSystem.sln +++ b/CyberSystem/CyberSystem.sln @@ -5,6 +5,10 @@ VisualStudioVersion = 17.9.34728.123 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BerklySocketServer", "CyberSystem\BerklySocketServer.csproj", "{732F06D2-F9CE-40A3-8281-48D7A41E0F79}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ApiServer", "ApiServer\ApiServer.csproj", "{7C72B3F0-8B39-4D48-8D9B-9A56046E5DA8}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ModbusLearn", "ModbusLearn\ModbusLearn.csproj", "{40D2FA2B-4E68-47C8-881B-5733EC22CF47}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -15,6 +19,14 @@ Global {732F06D2-F9CE-40A3-8281-48D7A41E0F79}.Debug|Any CPU.Build.0 = Debug|Any CPU {732F06D2-F9CE-40A3-8281-48D7A41E0F79}.Release|Any CPU.ActiveCfg = Release|Any CPU {732F06D2-F9CE-40A3-8281-48D7A41E0F79}.Release|Any CPU.Build.0 = Release|Any CPU + {7C72B3F0-8B39-4D48-8D9B-9A56046E5DA8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {7C72B3F0-8B39-4D48-8D9B-9A56046E5DA8}.Debug|Any CPU.Build.0 = Debug|Any CPU + {7C72B3F0-8B39-4D48-8D9B-9A56046E5DA8}.Release|Any CPU.ActiveCfg = Release|Any CPU + {7C72B3F0-8B39-4D48-8D9B-9A56046E5DA8}.Release|Any CPU.Build.0 = Release|Any CPU + {40D2FA2B-4E68-47C8-881B-5733EC22CF47}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {40D2FA2B-4E68-47C8-881B-5733EC22CF47}.Debug|Any CPU.Build.0 = Debug|Any CPU + {40D2FA2B-4E68-47C8-881B-5733EC22CF47}.Release|Any CPU.ActiveCfg = Release|Any CPU + {40D2FA2B-4E68-47C8-881B-5733EC22CF47}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/CyberSystem/CyberSystem/App.config b/CyberSystem/CyberSystem/App.config index 193aecc..ecdcf8a 100644 --- a/CyberSystem/CyberSystem/App.config +++ b/CyberSystem/CyberSystem/App.config @@ -1,6 +1,6 @@ - + - + - \ No newline at end of file + diff --git a/CyberSystem/CyberSystem/BerklySocketServer.csproj b/CyberSystem/CyberSystem/BerklySocketServer.csproj index ad17448..cc3c335 100644 --- a/CyberSystem/CyberSystem/BerklySocketServer.csproj +++ b/CyberSystem/CyberSystem/BerklySocketServer.csproj @@ -8,10 +8,11 @@ Exe CyberSystem CyberSystem - v4.8 + v4.7.2 512 true true + AnyCPU diff --git a/CyberSystem/CyberSystem/Server.cs b/CyberSystem/CyberSystem/Server.cs index 47ba87e..c6cb049 100644 --- a/CyberSystem/CyberSystem/Server.cs +++ b/CyberSystem/CyberSystem/Server.cs @@ -8,7 +8,7 @@ public class Server public static void Main() { // Настройка IP-адреса сервера и номера порта. - var serverAddress = IPAddress.Parse("127.0.0.7"); + var serverAddress = IPAddress.Parse("0.0.0.0"); var serverPort = 8000; // Создаем наш серверный сокет. @@ -36,10 +36,25 @@ public class Server // Обработка и отправка клиенту новых данных. // Отправка сообщения обратно клиенту. - //var serverMessage = "Hello, client!"; - //var messageBytes = Encoding.ASCII.GetBytes(serverMessage); - //clientSocket.Send(messageBytes); + var serverMessage = string.Empty; + + if (clientMessage.Contains("GET /post")) + { + serverMessage = "HTTP/1.1 200 OK\r\nContent-Type: text/html; charset=UTF-8\r\n\r\nПример страницы

Привет, мир!

Страница с постами!

"; + } + else if (clientMessage.Contains("GET /admin")) + { + serverMessage = "HTTP/1.1 200 OK\r\nContent-Type: text/html; charset=UTF-8\r\n\r\nПример страницы

Привет, мир!

Страница администратора!

"; + } + else + { + serverMessage = "HTTP/1.1 200 OK\r\nContent-Type: text/html; charset=UTF-8\r\n\r\nПример страницы

Привет, мир!

Базовая страница!

"; + } + + var messageBytes = Encoding.UTF8.GetBytes(serverMessage); + clientSocket.Send(messageBytes); + // Закрытие соединения. clientSocket.Shutdown(SocketShutdown.Both); clientSocket.Close(); diff --git a/CyberSystem/ModbusLearn/App.config b/CyberSystem/ModbusLearn/App.config new file mode 100644 index 0000000..193aecc --- /dev/null +++ b/CyberSystem/ModbusLearn/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/CyberSystem/ModbusLearn/ModbusLearn.csproj b/CyberSystem/ModbusLearn/ModbusLearn.csproj new file mode 100644 index 0000000..9c8ead4 --- /dev/null +++ b/CyberSystem/ModbusLearn/ModbusLearn.csproj @@ -0,0 +1,218 @@ + + + + + Debug + AnyCPU + {40D2FA2B-4E68-47C8-881B-5733EC22CF47} + Exe + ModbusLearn + ModbusLearn + v4.8 + 512 + true + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\packages\Microsoft.Win32.Primitives.4.0.1\lib\net46\Microsoft.Win32.Primitives.dll + True + True + + + ..\packages\Microsoft.Win32.Registry.4.3.0\lib\net46\Microsoft.Win32.Registry.dll + + + ..\packages\NModbus4.2.1.0\lib\net40\NModbus4.dll + + + ..\packages\SerialPortStream.2.2.0\lib\net45\RJCP.SerialPortStream.dll + + + + ..\packages\System.AppContext.4.1.0\lib\net463\System.AppContext.dll + True + True + + + ..\packages\System.Collections.Specialized.4.3.0\lib\net46\System.Collections.Specialized.dll + True + True + + + + ..\packages\System.Console.4.0.0\lib\net46\System.Console.dll + True + True + + + + ..\packages\System.Diagnostics.DiagnosticSource.4.0.0\lib\net46\System.Diagnostics.DiagnosticSource.dll + + + ..\packages\System.Diagnostics.FileVersionInfo.4.3.0\lib\net46\System.Diagnostics.FileVersionInfo.dll + True + True + + + ..\packages\System.Diagnostics.TraceSource.4.3.0\lib\net46\System.Diagnostics.TraceSource.dll + True + True + + + ..\packages\System.Diagnostics.Tracing.4.1.0\lib\net462\System.Diagnostics.Tracing.dll + True + True + + + ..\packages\System.Globalization.Calendars.4.0.1\lib\net46\System.Globalization.Calendars.dll + True + True + + + ..\packages\System.IO.4.3.0\lib\net462\System.IO.dll + True + True + + + ..\packages\System.IO.Compression.4.1.0\lib\net46\System.IO.Compression.dll + True + True + + + + ..\packages\System.IO.Compression.ZipFile.4.0.1\lib\net46\System.IO.Compression.ZipFile.dll + True + True + + + ..\packages\System.IO.FileSystem.4.3.0\lib\net46\System.IO.FileSystem.dll + True + True + + + ..\packages\System.IO.FileSystem.Primitives.4.3.0\lib\net46\System.IO.FileSystem.Primitives.dll + True + True + + + ..\packages\System.Linq.4.1.0\lib\net463\System.Linq.dll + True + True + + + ..\packages\System.Linq.Expressions.4.1.0\lib\net463\System.Linq.Expressions.dll + True + True + + + ..\packages\System.Net.Http.4.1.0\lib\net46\System.Net.Http.dll + True + True + + + ..\packages\System.Net.Sockets.4.1.0\lib\net46\System.Net.Sockets.dll + True + True + + + + ..\packages\System.Reflection.4.1.0\lib\net462\System.Reflection.dll + True + True + + + ..\packages\System.Runtime.4.3.0\lib\net462\System.Runtime.dll + True + True + + + ..\packages\System.Runtime.Extensions.4.3.0\lib\net462\System.Runtime.Extensions.dll + True + True + + + ..\packages\System.Runtime.InteropServices.4.3.0\lib\net463\System.Runtime.InteropServices.dll + True + True + + + ..\packages\System.Runtime.InteropServices.RuntimeInformation.4.3.0\lib\net45\System.Runtime.InteropServices.RuntimeInformation.dll + True + True + + + ..\packages\System.Security.Cryptography.Algorithms.4.2.0\lib\net463\System.Security.Cryptography.Algorithms.dll + True + True + + + ..\packages\System.Security.Cryptography.Encoding.4.0.0\lib\net46\System.Security.Cryptography.Encoding.dll + True + True + + + ..\packages\System.Security.Cryptography.Primitives.4.0.0\lib\net46\System.Security.Cryptography.Primitives.dll + True + True + + + ..\packages\System.Security.Cryptography.X509Certificates.4.1.0\lib\net461\System.Security.Cryptography.X509Certificates.dll + True + True + + + ..\packages\System.Text.RegularExpressions.4.1.0\lib\net463\System.Text.RegularExpressions.dll + True + True + + + ..\packages\System.Threading.Overlapped.4.3.0\lib\net46\System.Threading.Overlapped.dll + True + True + + + ..\packages\System.Threading.Thread.4.3.0\lib\net46\System.Threading.Thread.dll + True + True + + + ..\packages\System.Threading.ThreadPool.4.3.0\lib\net46\System.Threading.ThreadPool.dll + True + True + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/CyberSystem/ModbusLearn/Program.cs b/CyberSystem/ModbusLearn/Program.cs new file mode 100644 index 0000000..38b6c85 --- /dev/null +++ b/CyberSystem/ModbusLearn/Program.cs @@ -0,0 +1,57 @@ +using Modbus.Device; +using System; +using System.IO.Ports; + +namespace ModbusLearn +{ + internal class Program + { + static void Main(string[] args) + { + SerialPort serialPort = new SerialPort(); + serialPort.PortName = "COM5"; + serialPort.BaudRate = 9600; + serialPort.DataBits = 8; + serialPort.Parity = Parity.None; + serialPort.StopBits = StopBits.One; + serialPort.Open(); + ModbusSerialMaster master = ModbusSerialMaster.CreateRtu(serialPort); + + byte slaveID = 1; + ushort startAddress = 0; + ushort numOfPoints = 5; + var data = master.ReadInputs(slaveID, startAddress, numOfPoints); + Console.WriteLine(data[0]); + Console.ReadKey(); + + + //using (SerialPort port = new SerialPort("COM5")) + //{ + // // configure serial port + // port.BaudRate = 9600; + // port.DataBits = 8; + // port.Parity = Parity.None; + // port.StopBits = StopBits.One; + // port.Open(); + + // // Wrap the serial port + // var adapter = new SerialPortAdapter(port); + + // // Create the factory + // var factory = new ModbusFactory(); + + // // Create Modbus Master + // IModbusMaster master = factory.CreateRtuMaster(adapter); + + // byte slaveId = 1; + // ushort startAddress = 100; + // ushort[] registers = new ushort[] { 1, 2, 3 }; + + // // write three registers + // master.WriteMultipleRegisters(slaveId, startAddress, registers); + + // Console.ReadKey(); + //} + } + } +} diff --git a/CyberSystem/ModbusLearn/Properties/AssemblyInfo.cs b/CyberSystem/ModbusLearn/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..27503a4 --- /dev/null +++ b/CyberSystem/ModbusLearn/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("ModbusLearn")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("ModbusLearn")] +[assembly: AssemblyCopyright("Copyright © 2024")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("40d2fa2b-4e68-47c8-881b-5733ec22cf47")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/CyberSystem/ModbusLearn/packages.config b/CyberSystem/ModbusLearn/packages.config new file mode 100644 index 0000000..1433123 --- /dev/null +++ b/CyberSystem/ModbusLearn/packages.config @@ -0,0 +1,58 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/CyberSystem/fuxa-project.json b/CyberSystem/fuxa-project.json new file mode 100644 index 0000000..93c85a5 --- /dev/null +++ b/CyberSystem/fuxa-project.json @@ -0,0 +1 @@ +{"devices":{"0":{"id":"0","name":"FUXA Server","type":"FuxaServer","property":{},"enabled":true,"tags":{"t_f76a7b7e-ea8e4178":{"id":"t_f76a7b7e-ea8e4178","daq":{"restored":false,"enabled":false,"changed":false,"interval":60},"name":"Maser Connection Status","label":"Maser Connection Status","type":"number","memaddress":"d_cf82a6fa-17b24fab","sysType":1,"init":"","timestamp":1716223999827}},"polling":1000},"d_cf82a6fa-17b24fab":{"id":"d_cf82a6fa-17b24fab","property":{"address":"http://172.20.10.2:12344/api/state/modbus","port":null,"slot":null,"rack":null,"baudrate":9600,"databits":8,"stopbits":1,"parity":"None","method":"GET","format":"JSON"},"enabled":true,"tags":{"t_b5de94c1-5efd4df9":{"id":"t_b5de94c1-5efd4df9","daq":{"restored":false,"enabled":false,"changed":false,"interval":60},"name":"coilResult","label":"coilResult","type":"boolean","address":"coilResult","timestamp":1716223999840}},"name":"Master","type":"WebAPI","polling":1000}},"hmi":{"views":[{"id":"v_71057412b12-8119b","name":"MainView","profile":{"width":1024,"height":768,"bkcolor":"#ffffffff","margin":10},"items":{"HXT_94d610d6-0245443c":{"id":"HXT_94d610d6-0245443c","type":"svg-ext-html_switch","name":"switch_1","property":{"events":[],"actions":[],"variableId":"t_b5de94c1-5efd4df9","options":{"offValue":0,"onValue":1,"offBackground":"#ccc","onBackground":"#ccc","offText":"","onText":"","offSliderColor":"#fff","onSliderColor":"#0CC868","offTextColor":"#000","onTextColor":"#fff","fontSize":12,"fontFamily":"","radius":0,"height":22}},"label":"HtmlSwitch"}},"variables":{},"svgcontent":"\n \n \n \n \n Layer 1\n \n \n \n \n \n \n \n"}],"layout":{"autoresize":false,"start":"v_71057412b12-8119b","navigation":{"bkcolor":"#F4F5F7","fgcolor":"#1D1D1D","logo":false,"mode":"over","type":"block"},"header":{"bkcolor":"#ffffff","fgcolor":"#000000","fontSize":13,"itemsAnchor":"left"},"showdev":true,"inputdialog":"false","hidenavigation":false,"theme":"","loginonstart":false,"loginoverlaycolor":"none","show_connection_error":true}},"version":"1.00","server":{"id":"0","name":"FUXA Server","type":"FuxaServer","property":{}}} \ No newline at end of file diff --git a/project1/project1.ino b/project1/project1.ino new file mode 100644 index 0000000..afb393a --- /dev/null +++ b/project1/project1.ino @@ -0,0 +1,20 @@ +const int digitalPin = 13; + +void setup() { + Serial.begin(9600); +} + +void loop() { + const int value = digitalRead(digitalPin); + + if (value == HIGH) + { + Serial.print(1); + } + else + { + Serial.print(0); + } + + delay(500); +} diff --git a/sketch_apr29a/sketch_apr29a.ino b/sketch_apr29a/sketch_apr29a.ino new file mode 100644 index 0000000..f376a4a --- /dev/null +++ b/sketch_apr29a/sketch_apr29a.ino @@ -0,0 +1,18 @@ +#include +const int GPIOCoil = 0; + +bool coils[10]; +const int pinToRead = 2; + +ModbusSerial mb (Serial, 10); + +void setup() { + Serial.begin(9600); + pinMode(pinToRead, INPUT); + mb.addIsts(0); +} + +void loop() { + mb.setIsts(0 digitalRead(pinToRead)); + mb.task(); +} diff --git a/sketch_apr29a/sketch_may6a/sketch_may6a.ino b/sketch_apr29a/sketch_may6a/sketch_may6a.ino new file mode 100644 index 0000000..baca216 --- /dev/null +++ b/sketch_apr29a/sketch_may6a/sketch_may6a.ino @@ -0,0 +1,31 @@ +# include + +const uint8_t coilPins[2] = {4, 5}; +const uint8_t discreteInputPins[2] = {2, 3}; + +ModbusRTUSlave modbus(Serial); + +bool coils[5]; +bool discreteInputs[5]; + +void setup() { + pinMode(coilPins[0], OUTPUT); + pinMode(coilPins[1], OUTPUT); + pinMode(discreteInputPins[0], INPUT); + pinMode(discreteInputPins[1], INPUT); + + modbus.configureCoils(coils, 5); + modbus.configureDiscreteInputs(discreteInputs, 5); + modbus.begin(1, 9600); +} + +void loop() { + discreteInputs[0] = digitalRead(discreteInputPins[0]); + discreteInputs[1] = digitalRead(discreteInputPins[1]); + //Serial.print(discreteInputs[0]); + + modbus.poll(); + + digitalWrite(coilPins[0], coils[0]); + digitalWrite(coilPins[1], coils[1]); +}