diff --git a/watlow-f4sd/ModbusWatlowRamp/ModbusWatlowRamp.csproj b/watlow-f4sd/ModbusWatlowRamp/ModbusWatlowRamp.csproj new file mode 100644 index 0000000..db6b6ef --- /dev/null +++ b/watlow-f4sd/ModbusWatlowRamp/ModbusWatlowRamp.csproj @@ -0,0 +1,14 @@ + + + + Exe + net8.0 + enable + enable + + + + + + + diff --git a/watlow-f4sd/ModbusWatlowRamp/ModbusWatlowRamp.sln b/watlow-f4sd/ModbusWatlowRamp/ModbusWatlowRamp.sln new file mode 100644 index 0000000..f40b76b --- /dev/null +++ b/watlow-f4sd/ModbusWatlowRamp/ModbusWatlowRamp.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.14.36121.58 d17.14 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ModbusWatlowRamp", "ModbusWatlowRamp.csproj", "{138F9A2D-5D63-4303-87AD-9C131B93BA62}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {138F9A2D-5D63-4303-87AD-9C131B93BA62}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {138F9A2D-5D63-4303-87AD-9C131B93BA62}.Debug|Any CPU.Build.0 = Debug|Any CPU + {138F9A2D-5D63-4303-87AD-9C131B93BA62}.Release|Any CPU.ActiveCfg = Release|Any CPU + {138F9A2D-5D63-4303-87AD-9C131B93BA62}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {986BB29F-AC51-4EA5-9A56-1400A2778A90} + EndGlobalSection +EndGlobal diff --git a/watlow-f4sd/ModbusWatlowRamp/Program.cs b/watlow-f4sd/ModbusWatlowRamp/Program.cs new file mode 100644 index 0000000..7548cc5 --- /dev/null +++ b/watlow-f4sd/ModbusWatlowRamp/Program.cs @@ -0,0 +1,88 @@ +using Modbus.Device; // NModbus namespace +using System.Net.Sockets; + +internal class Program +{ + // Configuration + private const string hostname = "127.0.0.1"; // Replace with your Watlow F4 IP + + private const int port = 502; + private const byte slaveId = 0; + + // Register 100 should be the first read-only input on the F4 + // Value 99 or 100 should work depending on zero indexing + private const ushort loadRegister = 99; + + private static void Main(string[] args) + { + TcpClient tcpClient = null; + ModbusIpMaster master = null; + + try + { + // Initialize connection + tcpClient = new TcpClient(hostname, port); + master = ModbusIpMaster.CreateIp(tcpClient); + + // Monitor continuously + while (true) + { + // Check for Escape key press + if (Console.KeyAvailable) + { + ConsoleKeyInfo key = Console.ReadKey(true); + if (key.Key == ConsoleKey.Escape) + { + Console.WriteLine("Escape pressed. Exiting..."); + break; + } + } + + try + { + // Read load value (holding register) + ushort[] registers = master.ReadHoldingRegisters(slaveId, loadRegister, 1); + int load = registers[0]; + + // Display load info + DisplayLoadInfo(load); + + // Pause before next read + Thread.Sleep(1000); + } + catch (Exception ex) + { + Console.WriteLine($"Error: {ex.Message}"); + break; + } + } + } + catch (Exception ex) + { + Console.WriteLine($"Initialization error: {ex.Message}"); + } + finally + { + // Clean up + master?.Dispose(); + tcpClient?.Close(); + } + } + + private static void DisplayLoadInfo(int load) + { + Console.Clear(); // Clears the console + + // Assume load is 0-65535 for 0.00-100.00% (16-bit range) + int percent = (int)load / 65535 * 100; + int barLength = (int)(percent / 2); // Scale to 50 chars for console + + Console.WriteLine($"Load Value: {load}"); + Console.WriteLine($"Load Percentage: {percent:F2}%"); + Console.Write("Bar Graph: ["); + Console.Write(new string('=', barLength)); + Console.Write(new string(' ', 50 - barLength)); + Console.WriteLine("]"); + Console.WriteLine("\nHold ESC to exit."); + } +} \ No newline at end of file