diff --git a/CyberSystem/CyberSystem.sln b/CyberSystem/CyberSystem.sln index fce98b7..2ec6940 100644 --- a/CyberSystem/CyberSystem.sln +++ b/CyberSystem/CyberSystem.sln @@ -5,7 +5,9 @@ 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("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ApiServer", "ApiServer\ApiServer.csproj", "{7C72B3F0-8B39-4D48-8D9B-9A56046E5DA8}" +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 @@ -21,6 +23,10 @@ Global {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/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..c946f88 --- /dev/null +++ b/CyberSystem/ModbusLearn/ModbusLearn.csproj @@ -0,0 +1,224 @@ + + + + + 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\NModbus.3.0.81\lib\net46\NModbus.dll + + + ..\packages\NModbus.Serial.3.0.81\lib\net46\NModbus.Serial.dll + + + ..\packages\NModbus.SerialPortStream.3.0.81\lib\net46\NModbus.SerialPortStream.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..23193d3 --- /dev/null +++ b/CyberSystem/ModbusLearn/Program.cs @@ -0,0 +1,40 @@ +using NModbus; +using NModbus.Extensions.Enron; +using NModbus.Serial; +using System; +using System.IO.Ports; + +namespace ModbusLearn +{ + internal class Program + { + static void Main(string[] args) + { + 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); + } + } + } +} 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..18beadf --- /dev/null +++ b/CyberSystem/ModbusLearn/packages.config @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file