diff --git a/.vs/ProjectEvaluation/hybirdmyframe.metadata.v7.bin b/.vs/ProjectEvaluation/hybirdmyframe.metadata.v7.bin index 87bae8f..f91c8bb 100644 Binary files a/.vs/ProjectEvaluation/hybirdmyframe.metadata.v7.bin and b/.vs/ProjectEvaluation/hybirdmyframe.metadata.v7.bin differ diff --git a/.vs/ProjectEvaluation/hybirdmyframe.projects.v7.bin b/.vs/ProjectEvaluation/hybirdmyframe.projects.v7.bin index 83bbef6..413d70c 100644 Binary files a/.vs/ProjectEvaluation/hybirdmyframe.projects.v7.bin and b/.vs/ProjectEvaluation/hybirdmyframe.projects.v7.bin differ diff --git a/.vs/hybirdMyFrame/DesignTimeBuild/.dtbcache.v2 b/.vs/hybirdMyFrame/DesignTimeBuild/.dtbcache.v2 index 14686b0..5caff38 100644 Binary files a/.vs/hybirdMyFrame/DesignTimeBuild/.dtbcache.v2 and b/.vs/hybirdMyFrame/DesignTimeBuild/.dtbcache.v2 differ diff --git a/.vs/hybirdMyFrame/v17/.futdcache.v2 b/.vs/hybirdMyFrame/v17/.futdcache.v2 index e4481a7..99f4acb 100644 Binary files a/.vs/hybirdMyFrame/v17/.futdcache.v2 and b/.vs/hybirdMyFrame/v17/.futdcache.v2 differ diff --git a/.vs/hybirdMyFrame/v17/.suo b/.vs/hybirdMyFrame/v17/.suo index 05ea547..527c773 100644 Binary files a/.vs/hybirdMyFrame/v17/.suo and b/.vs/hybirdMyFrame/v17/.suo differ diff --git a/.vs/hybirdMyFrame/v17/DocumentLayout.json b/.vs/hybirdMyFrame/v17/DocumentLayout.json index 1979a5d..89fcd06 100644 --- a/.vs/hybirdMyFrame/v17/DocumentLayout.json +++ b/.vs/hybirdMyFrame/v17/DocumentLayout.json @@ -1,18 +1,18 @@ { "Version": 1, - "WorkspaceRootPath": "D:\\Desktop\\MyFrame\\Frame\\hybirdMyFrame\\", + "WorkspaceRootPath": "D:\\Desktop\\TestFrame2\\", "Documents": [ { - "AbsoluteMoniker": "D:0:0:{A6757DAD-EF5A-41FD-9323-F3FCF05ED777}|WinFormStarter\\WinFormStarter.csproj|d:\\desktop\\myframe\\frame\\hybirdmyframe\\winformstarter\\form1.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}", - "RelativeMoniker": "D:0:0:{A6757DAD-EF5A-41FD-9323-F3FCF05ED777}|WinFormStarter\\WinFormStarter.csproj|solutionrelative:winformstarter\\form1.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}" + "AbsoluteMoniker": "D:0:0:{6ACFA707-E72E-4BA1-8262-9F2E5B758D46}|HybirdFrameworkDriver\\HybirdFrameworkDriver.csproj|d:\\desktop\\testframe2\\hybirdframeworkdriver\\modbustcpmaster\\modbustcpmaster.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}", + "RelativeMoniker": "D:0:0:{6ACFA707-E72E-4BA1-8262-9F2E5B758D46}|HybirdFrameworkDriver\\HybirdFrameworkDriver.csproj|solutionrelative:hybirdframeworkdriver\\modbustcpmaster\\modbustcpmaster.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}" }, { - "AbsoluteMoniker": "D:0:0:{A6757DAD-EF5A-41FD-9323-F3FCF05ED777}|WinFormStarter\\WinFormStarter.csproj|d:\\desktop\\myframe\\frame\\hybirdmyframe\\winformstarter\\program.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}", - "RelativeMoniker": "D:0:0:{A6757DAD-EF5A-41FD-9323-F3FCF05ED777}|WinFormStarter\\WinFormStarter.csproj|solutionrelative:winformstarter\\program.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}" + "AbsoluteMoniker": "D:0:0:{8EAFC092-1C8A-4CF7-B283-FFCB02D58ED8}|ConsoleStarter\\ConsoleStarter.csproj|d:\\desktop\\testframe2\\consolestarter\\program.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}", + "RelativeMoniker": "D:0:0:{8EAFC092-1C8A-4CF7-B283-FFCB02D58ED8}|ConsoleStarter\\ConsoleStarter.csproj|solutionrelative:consolestarter\\program.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}" }, { - "AbsoluteMoniker": "D:0:0:{A6757DAD-EF5A-41FD-9323-F3FCF05ED777}|WinFormStarter\\WinFormStarter.csproj|d:\\desktop\\myframe\\frame\\hybirdmyframe\\winformstarter\\form1.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}|Form", - "RelativeMoniker": "D:0:0:{A6757DAD-EF5A-41FD-9323-F3FCF05ED777}|WinFormStarter\\WinFormStarter.csproj|solutionrelative:winformstarter\\form1.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}|Form" + "AbsoluteMoniker": "D:0:0:{6ACFA707-E72E-4BA1-8262-9F2E5B758D46}|HybirdFrameworkDriver\\HybirdFrameworkDriver.csproj|d:\\desktop\\testframe2\\hybirdframeworkdriver\\modbustcpmaster\\watercooldata.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}", + "RelativeMoniker": "D:0:0:{6ACFA707-E72E-4BA1-8262-9F2E5B758D46}|HybirdFrameworkDriver\\HybirdFrameworkDriver.csproj|solutionrelative:hybirdframeworkdriver\\modbustcpmaster\\watercooldata.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}" } ], "DocumentGroupContainers": [ @@ -22,56 +22,61 @@ "DocumentGroups": [ { "DockedHeight": 200, - "SelectedChildIndex": 3, + "SelectedChildIndex": 1, "Children": [ - { - "$type": "Bookmark", - "Name": "ST:0:0:{1c4feeaa-4718-4aa9-859d-94ce25d182ba}" - }, - { - "$type": "Bookmark", - "Name": "ST:129:0:{116d2292-e37d-41cd-a077-ebacac4c8cc4}" - }, - { - "$type": "Bookmark", - "Name": "ST:128:0:{116d2292-e37d-41cd-a077-ebacac4c8cc4}" - }, { "$type": "Document", - "DocumentIndex": 0, - "Title": "Form1.cs", - "DocumentMoniker": "D:\\Desktop\\MyFrame\\Frame\\hybirdMyFrame\\WinFormStarter\\Form1.cs", - "RelativeDocumentMoniker": "WinFormStarter\\Form1.cs", - "ToolTip": "D:\\Desktop\\MyFrame\\Frame\\hybirdMyFrame\\WinFormStarter\\Form1.cs", - "RelativeToolTip": "WinFormStarter\\Form1.cs", - "ViewState": "AQIAAAAAAAAAAAAAAAAAAAgAAAA8AAAA", + "DocumentIndex": 1, + "Title": "Program.cs", + "DocumentMoniker": "D:\\Desktop\\TestFrame2\\ConsoleStarter\\Program.cs", + "RelativeDocumentMoniker": "ConsoleStarter\\Program.cs", + "ToolTip": "D:\\Desktop\\TestFrame2\\ConsoleStarter\\Program.cs", + "RelativeToolTip": "ConsoleStarter\\Program.cs", + "ViewState": "AQIAAA4AAAAAAAAAAAAqwBgAAAAbAAAA", "Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|", - "WhenOpened": "2024-04-02T05:25:54.384Z", + "WhenOpened": "2024-04-22T08:22:49.429Z", + "IsPinned": true, "EditorCaption": "" }, { "$type": "Document", - "DocumentIndex": 1, - "Title": "Program.cs", - "DocumentMoniker": "D:\\Desktop\\MyFrame\\Frame\\hybirdMyFrame\\WinFormStarter\\Program.cs", - "RelativeDocumentMoniker": "WinFormStarter\\Program.cs", - "ToolTip": "D:\\Desktop\\MyFrame\\Frame\\hybirdMyFrame\\WinFormStarter\\Program.cs", - "RelativeToolTip": "WinFormStarter\\Program.cs", - "ViewState": "AQIAAB4AAAAAAAAAAAAhwDAAAAA8AAAA", + "DocumentIndex": 0, + "Title": "ModbusTcpMaster.cs", + "DocumentMoniker": "D:\\Desktop\\TestFrame2\\HybirdFrameworkDriver\\ModbusTcpMaster\\ModbusTcpMaster.cs", + "RelativeDocumentMoniker": "HybirdFrameworkDriver\\ModbusTcpMaster\\ModbusTcpMaster.cs", + "ToolTip": "D:\\Desktop\\TestFrame2\\HybirdFrameworkDriver\\ModbusTcpMaster\\ModbusTcpMaster.cs", + "RelativeToolTip": "HybirdFrameworkDriver\\ModbusTcpMaster\\ModbusTcpMaster.cs", + "ViewState": "AQIAAH8AAAAAAAAAAAApwIoAAABVAAAA", "Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|", - "WhenOpened": "2024-04-02T05:24:49.188Z" + "WhenOpened": "2024-04-22T08:22:52.863Z", + "IsPinned": true, + "EditorCaption": "" }, { "$type": "Document", "DocumentIndex": 2, - "Title": "Form1.cs [\u8BBE\u8BA1]", - "DocumentMoniker": "D:\\Desktop\\MyFrame\\Frame\\hybirdMyFrame\\WinFormStarter\\Form1.cs", - "RelativeDocumentMoniker": "WinFormStarter\\Form1.cs", - "ToolTip": "D:\\Desktop\\MyFrame\\Frame\\hybirdMyFrame\\WinFormStarter\\Form1.cs [\u8BBE\u8BA1]", - "RelativeToolTip": "WinFormStarter\\Form1.cs [\u8BBE\u8BA1]", + "Title": "WaterCoolData.cs", + "DocumentMoniker": "D:\\Desktop\\TestFrame2\\HybirdFrameworkDriver\\ModbusTcpMaster\\WaterCoolData.cs", + "RelativeDocumentMoniker": "HybirdFrameworkDriver\\ModbusTcpMaster\\WaterCoolData.cs", + "ToolTip": "D:\\Desktop\\TestFrame2\\HybirdFrameworkDriver\\ModbusTcpMaster\\WaterCoolData.cs", + "RelativeToolTip": "HybirdFrameworkDriver\\ModbusTcpMaster\\WaterCoolData.cs", + "ViewState": "AQIAABYAAAAAAAAAAIA6wB8AAAAsAAAA", "Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|", - "WhenOpened": "2024-04-02T05:25:07.994Z", - "EditorCaption": " [\u8BBE\u8BA1]" + "WhenOpened": "2024-04-22T08:31:49.675Z", + "IsPinned": true, + "EditorCaption": "" + }, + { + "$type": "Bookmark", + "Name": "ST:0:0:{1c4feeaa-4718-4aa9-859d-94ce25d182ba}" + }, + { + "$type": "Bookmark", + "Name": "ST:129:0:{116d2292-e37d-41cd-a077-ebacac4c8cc4}" + }, + { + "$type": "Bookmark", + "Name": "ST:128:0:{116d2292-e37d-41cd-a077-ebacac4c8cc4}" } ] } diff --git a/ConsoleStarter/Program.cs b/ConsoleStarter/Program.cs index f05a0c0..c817326 100644 --- a/ConsoleStarter/Program.cs +++ b/ConsoleStarter/Program.cs @@ -11,18 +11,29 @@ internal class Program { ModbusTcpMaster master = new ModbusTcpMaster() { - Ip = "", + Ip = "192.168.1.5", ReadAction = ReadFunc }; bool connected = master.Connect(); Debug.Assert(connected, "连接modbus server 失败"); + #region 测试写 WaterCoolData coolData = new WaterCoolData(); + //写入ushort + coolData.ushortType.Value = 17; + bool writeResult4 = master.WriteValue(coolData.ushortType); + Debug.Assert(writeResult4, "写入失败"); + //写入byte 0-8 byte[1] + coolData.Status.Value = 12; + bool writeResult1 = master.WriteValue(coolData.Status); + Debug.Assert(writeResult1, "写入失败"); + //写入bit coolData.DraughtFan2.Value = true; - bool writeResult = master.WriteValue(coolData.DraughtFan2); - Debug.Assert(writeResult, "写入失败"); + bool writeResult3 = master.WriteValue(coolData.DraughtFan2); + Debug.Assert(writeResult3, "写入失败"); + #endregion 测试写 } private static void ReadFunc(ModbusTcpMaster master) diff --git a/HybirdFrameworkDriver/ModbusTcpMaster/ModbusTcpMaster.cs b/HybirdFrameworkDriver/ModbusTcpMaster/ModbusTcpMaster.cs index f1c2e6e..5b75164 100644 --- a/HybirdFrameworkDriver/ModbusTcpMaster/ModbusTcpMaster.cs +++ b/HybirdFrameworkDriver/ModbusTcpMaster/ModbusTcpMaster.cs @@ -10,8 +10,8 @@ public class ModbusTcpMaster { private static readonly ILog Log = LogManager.GetLogger(typeof(ModbusTcpMaster)); - public string Ip { get; set; } = "127.0.0.1"; - + // public string Ip { get; set; } = "127.0.0.1"; + public string Ip { get; set; } = "192.168.1.5"; public int Port { get; set; } = 502; public int Duration { get; set; } = 1000; @@ -81,18 +81,19 @@ public class ModbusTcpMaster private void ReadFunc() { - while (!StopFlag) - { - try - { - ReadAction(this); - Thread.Sleep(Duration); - } - catch (Exception e) - { - Log.Error(e); - } - } + // ReadAction(this); + //while (!StopFlag) + //{ + // try + // { + // ReadAction(this); + // Thread.Sleep(Duration); + // } + // catch (Exception e) + // { + // Log.Error(e); + // } + //} GetLog().Info("stop listen"); } @@ -141,17 +142,16 @@ public class ModbusTcpMaster case ModbusDataType.Byte: start = start % 2 == 0 ? start / 2 : start / 2 + 1; - ModbusTcpNet.Write("x=6;" + start, setValue); + OperateResult operateResult1 = ModbusTcpNet.Write("x=6;" + start, setValue); break; case ModbusDataType.Register: - ModbusTcpNet.Write("x=10;" + start, setValue); + OperateResult operateResult2 = ModbusTcpNet.Write("x=16;" + start, setValue); break; case ModbusDataType.Bit: start = start % 16 == 0 ? start / 16 : start / 16 + 1; length = length % 8 == 0 ? length / 8 : length / 8 + 1; - OperateResult readResult = - ModbusTcpNet.Read("x=3;" + (property.RegisterNo + start), (ushort)length); + OperateResult readResult = ModbusTcpNet.Read("x=3;" + (property.RegisterNo + start), (ushort)length); if (readResult.IsSuccess) { diff --git a/HybirdFrameworkDriver/ModbusTcpMaster/WaterCoolData.cs b/HybirdFrameworkDriver/ModbusTcpMaster/WaterCoolData.cs index 4d9da83..f60b97f 100644 --- a/HybirdFrameworkDriver/ModbusTcpMaster/WaterCoolData.cs +++ b/HybirdFrameworkDriver/ModbusTcpMaster/WaterCoolData.cs @@ -28,6 +28,8 @@ public class WaterCoolData public ModbusProperty CompressorTemperature2 { get; set; } = new(40012, scale: 0.1, round: 1); public ModbusProperty CompressorTemperature3 { get; set; } = new(40013, scale: 0.1, round: 1); public ModbusProperty CompressorTemperature4 { get; set; } = new(40014, scale: 0.1, round: 1); + + public ModbusProperty ushortType { get; set; } = new(40015); public ModbusProperty ElectromagneticStatus1 { get; set; } = new(40023, scale: 0.1, round: 1); public ModbusProperty ElectromagneticStatus2 { get; set; } = new(40024, scale: 0.1, round: 1);