You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
lj_plc/DataBlockHelper/DBHelpers/Db2110Help.cs

192 lines
5.3 KiB
C#

6 months ago
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DataBlockHelper.DBHelpers
{
public class Db2110Help: DBHelper
{
public Db2110Help()
{
bytes = PlcConnect.Instance.Read("DB2110.3384.0", 28).Content;
var content = bytes.ToArray();
queA0 = PlcConnect.Instance.ByteTransform.TransInt16(content, 0);
queA1 = PlcConnect.Instance.ByteTransform.TransInt16(content, 2);
queA2 = PlcConnect.Instance.ByteTransform.TransInt16(content, 4);
queA3 = PlcConnect.Instance.ByteTransform.TransInt16(content, 6);
queA4 = PlcConnect.Instance.ByteTransform.TransInt16(content, 8);
queB0 = PlcConnect.Instance.ByteTransform.TransInt16(content, 10);
queB1 = PlcConnect.Instance.ByteTransform.TransInt16(content, 12);
queB2 = PlcConnect.Instance.ByteTransform.TransInt16(content, 14);
queB3 = PlcConnect.Instance.ByteTransform.TransInt16(content, 16);
queB4 = PlcConnect.Instance.ByteTransform.TransInt16(content, 18);
queB5 = PlcConnect.Instance.ByteTransform.TransInt16(content, 20);
queB6 = PlcConnect.Instance.ByteTransform.TransInt16(content, 22);
queB7 = PlcConnect.Instance.ByteTransform.TransInt16(content, 24);
queB8 = PlcConnect.Instance.ByteTransform.TransInt16(content, 26);
}
6 months ago
public string GetA()
{
List<string> list = new List<string>();
list.Add(GetAvalue(queA0));
list.Add(GetAvalue(queA1));
list.Add(GetAvalue(queA2));
list.Add(GetAvalue(queA3));
list.Add(GetAvalue(queA4));
6 months ago
if (list.Count == list.Where(x => x == "0").Count())
{
return "";
}
6 months ago
StringBuilder stringBuilder = new StringBuilder();
for (int i = 0; i < list.Count; i++)
{
string a= list[i];
if (i > 0)
{
stringBuilder.Append("=>"+a);
}
else
{
stringBuilder.Append(a);
}
}
return stringBuilder.ToString();
}
public string GetB()
{
List<string> list = new List<string>();
list.Add(GetAvalue(queB0));
list.Add(GetAvalue(queB1));
list.Add(GetAvalue(queB2));
list.Add(GetAvalue(queB3));
list.Add(GetAvalue(queB4));
list.Add(GetAvalue(queB5));
list.Add(GetAvalue(queB6));
list.Add(GetAvalue(queB7));
list.Add(GetAvalue(queB8));
6 months ago
if (list.Count == list.Where(x => x == "0").Count())
{
return "";
}
6 months ago
StringBuilder stringBuilder = new StringBuilder();
for (int i = 0; i < list.Count; i++)
{
string a = list[i];
if (i > 0)
{
6 months ago
stringBuilder.Append("=> " + a);
6 months ago
}
else
{
stringBuilder.Append(a);
}
}
return stringBuilder.ToString();
}
private string GetBvalue(short shor)
{
if(shor == 1)
{
return shor.ToString();
}
if (shor == 3 || shor==4)
{
return (shor-1).ToString();
}
if (shor == 6 || shor == 7)
{
return (shor - 2).ToString();
}
if (shor == 9 || shor == 10)
{
return (shor - 3).ToString();
}
if (shor ==12)
{
return (shor - 4).ToString();
}
return shor.ToString();
}
private string GetAvalue(short shor)
{
if (shor == 2)
{
return "A";
}
else
{
if (shor == 5)
{
return "B";
}
else
{
if (shor == 8)
{
return "C";
}
else
{
if (shor == 11)
{
return "D";
}
else
{
return shor.ToString();
}
}
}
}
}
6 months ago
public short queA0 { get; set; }
public short queA1 { get; set; }
public short queA2 { get; set; }
public short queA3 { get; set; }
public short queA4 { get; set; }
public short queB0 { get; set; }
public short queB1 { get; set; }
public short queB2 { get; set; }
public short queB3 { get; set; }
public short queB4 { get; set; }
public short queB5 { get; set; }
public short queB6 { get; set; }
public short queB7 { get; set; }
public short queB8 { get; set; }
}
}