diff --git a/DataBlockHelper/DBHelpers/DB112Helper.cs b/DataBlockHelper/DBHelpers/DB112Helper.cs new file mode 100644 index 0000000..ee44a15 --- /dev/null +++ b/DataBlockHelper/DBHelpers/DB112Helper.cs @@ -0,0 +1,86 @@ +using HslCommunication; + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DataBlockHelper.DBHelpers +{ + public class DB112Helper: DBHelper + + { + public DB112Helper() { + OperateResult db112 = PlcConnect.Instance.Read("DB112.0.0", 151); + bytes = db112.Content; + } + + + public Conveyor PressureA => new Conveyor(2, bytes); + + public Conveyor PressureB => new Conveyor(34, bytes); + + + public Conveyor PressureC => new Conveyor(66, bytes); + + + public ConveyorTimer LineTimeA=>new ConveyorTimer(98, bytes); + + public ConveyorTimer LineTimeB => new ConveyorTimer(102, bytes); + + public ConveyorTimer LineTimeC => new ConveyorTimer(104, bytes); + } + + + + public class Conveyor + { + public Conveyor() { } + + public Conveyor(ushort startSet, byte[] bytes) + { + byte[] content = bytes.Skip(startSet).Take(32).ToArray(); + var trans= PlcConnect.Instance.ByteTransform; + SetValue1 = trans.TransSingle(content, 0); + SetValue2 = trans.TransSingle(content, 4); + SetValue3 = trans.TransSingle(content, 8); + SetValue4 = trans.TransSingle(content, 12); + SetValue5 = trans.TransSingle(content, 16); + SetValue6 = trans.TransSingle(content, 20); + SetValue7 = trans.TransSingle(content, 24); + SetValue8 = trans.TransSingle(content, 28); + } + + public float SetValue1 { get; set; } + public float SetValue2 { get; set; } + public float SetValue3 { get; set; } + public float SetValue4 { get; set; } + public float SetValue5 { get; set; } + public float SetValue6 { get; set; } + public float SetValue7 { get; set; } + public float SetValue8 { get; set; } + } + + + + public class ConveyorTimer + { + public ConveyorTimer() + { + + } + + public ConveyorTimer(ushort startSet, byte[] bytes) + { + byte[] content = bytes.Skip(startSet).Take(4).ToArray(); + + var trans = PlcConnect.Instance.ByteTransform; + SetValue1 = trans.TransInt16(content, 0); + SetValue2 = trans.TransInt16(content, 2); + } + + public short SetValue1 { get; set; } + public short SetValue2 { get; set; } + } +} diff --git a/DataBlockHelper/DBHelpers/DB112WriterHelper.cs b/DataBlockHelper/DBHelpers/DB112WriterHelper.cs new file mode 100644 index 0000000..8b162e9 --- /dev/null +++ b/DataBlockHelper/DBHelpers/DB112WriterHelper.cs @@ -0,0 +1,88 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DataBlockHelper.DBHelpers +{ + public class DB112WriterHelper + { + private static readonly string DbName = "DB112"; + // var siemensS7Net = PlcConnect.Instance; + + + + public static void AddConveyorA(Conveyor conveyor) + { + + int start = 2; + AddConveyor(start, conveyor); + + } + + public static void AddConveyorB(Conveyor conveyor) + { + + int start = 34; + AddConveyor(start, conveyor); + + } + + public static void AddConveyorC(Conveyor conveyor) + { + + int start = 66; + AddConveyor(start , conveyor); + + } + + + public static void AddConveyorTimerA(ConveyorTimer conveyor) + { + int start = 98; + AddConveyorTimer(start, conveyor); + } + + public static void AddConveyorTimerB(ConveyorTimer conveyor) + { + int start = 102; + AddConveyorTimer(start, conveyor); + } + + + public static void AddConveyorTimerC(ConveyorTimer conveyor) + { + int start = 106; + AddConveyorTimer(start, conveyor); + } + + private static void AddConveyor(int start, Conveyor conveyor) + { + + var siemensS7Net = PlcConnect.Instance; + siemensS7Net.Write($"{DbName}.{start}.0", conveyor.SetValue1); + siemensS7Net.Write($"{DbName}.{start + 4}.0", conveyor.SetValue2); + siemensS7Net.Write($"{DbName}.{start + 8}.0", conveyor.SetValue3); + siemensS7Net.Write($"{DbName}.{start + 12}.0", conveyor.SetValue4); + siemensS7Net.Write($"{DbName}.{start + 16}.0", conveyor.SetValue5); + siemensS7Net.Write($"{DbName}.{start + 20}.0", conveyor.SetValue6); + siemensS7Net.Write($"{DbName}.{start + 24}.0", conveyor.SetValue7); + siemensS7Net.Write($"{DbName}.{start + 28}.0", conveyor.SetValue7); + } + + + private static void AddConveyorTimer(int start, ConveyorTimer conveyor) + { + + var siemensS7Net = PlcConnect.Instance; + siemensS7Net.Write($"{DbName}.{start}.0", conveyor.SetValue1); + siemensS7Net.Write($"{DbName}.{start + 2}.0", conveyor.SetValue2); + + } + + + // + + } +} diff --git a/DataBlockHelper/DataBlockHelper.csproj b/DataBlockHelper/DataBlockHelper.csproj index e89be44..310a721 100644 --- a/DataBlockHelper/DataBlockHelper.csproj +++ b/DataBlockHelper/DataBlockHelper.csproj @@ -48,6 +48,8 @@ + + diff --git a/DataBlockHelper/PlcConnect.cs b/DataBlockHelper/PlcConnect.cs index c543ffe..c85771c 100644 --- a/DataBlockHelper/PlcConnect.cs +++ b/DataBlockHelper/PlcConnect.cs @@ -21,19 +21,13 @@ namespace DataBlockHelper SiemensPLCS siemensPLCS = SiemensPLCS.S1500; SiemensS7Net s7 = new SiemensS7Net(siemensPLCS); s7.SetPersistentConnection(); - s7.IpAddress = "172.18.4.100"; + s7.IpAddress = "192.168.1.110"; s7.Port = 102; var su = s7.ConnectServer(); if (!su.IsSuccess) { - s7.IpAddress = "192.168.0.100"; - s7.Port = 7788; - var fn = s7.ConnectServer(); - if (!fn.IsSuccess) - { - return new SiemensS7Net(siemensPLCS); - } + } return s7;