ke_junjie
2025-06-04 101c57ec4c28bc3c36e49c50a926e9e7c0dd0247
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
using S7.Net;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace iWareSda_QQJF.OPCService
{
    public class EXS7PLC : PlcS7
    {
        public EXS7PLC(CpuType cpu, string ip, short rack, short slot, string name = "", object tag = null):base(cpu, ip, rack, slot)
        {
        }
        /// <summary>
        /// S7写入(暂时写这里)
        /// </summary>
        /// <param name="add"></param>
        /// <param name="value"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        public string WriteValuePoint(string add, object value)
        {
            object o = new object();
            //bool
            var t = value.GetType();
            if (value.GetType() == typeof(bool))
            {
                byte MyData = Convert.ToByte(value);
                o = this.Write(add, MyData);
            }
            //浮点
            if (value.GetType() == typeof(double) || value.GetType() == typeof(float))
            {
                double MyData = Convert.ToDouble(value);
                o = this.Write(add, MyData.ConvertToUInt());
 
            }
            //整数
            else if (value.GetType() == typeof(Int32) || value.GetType() == typeof(short))
            {
                short MyData = Convert.ToInt16(value);
                o = this.Write(add, MyData.ConvertToUshort());
            }
            //双整数
            else if (value.GetType() == typeof(Int32))
            {
                int myData = Convert.ToInt32(value);
                o = this.Write(add, myData);
            }
            if (o == null)
            {
                return "";
            }
            return o.ToString();
        }
 
        /// <summary>
        /// S7读取
        /// </summary>
        /// <param name="add"></param>
        /// <param name="type"></param>
        /// <param name="plc"></param>
        /// <returns></returns>
        public object ReadValuePoint(string add)
        {
            ////bool
            //if (type == "Bool")
            //{
            //    // double MyPlcData = ((uint)S71200.Read("DB" + txtDB.Text + "." + "DBX" + txtStart.Text)).ConvertToDouble();
            //    var MyPlcData = this.Read(add).ToString();
            //    return MyPlcData;
            //}
            ////浮点
            //if (type == "Real")
            //{
            //    double MyPlcData = ((uint)this.Read(add)).ConvertToDouble();
            //    return MyPlcData;
            //}
            ////整数
            //else if (type == "Int")
            //{
            //    //short MyPlcData = ((ushort)S71200.Read("DB" + txtDB.Text + "." + "DBW" + txtStart.Text)).ConvertToShort();
            //    var MyPlcData = this.Read(add);
 
            //    return MyPlcData;
            //}
            ////双整数
            //else if (type == "DInt")
            //{
            //    int MyPlcData = ((uint)this.Read(add)).ConvertToInt();
            //    return MyPlcData;
            //}
            //return "";
            object MyPlcData = this.Read(add);
            return MyPlcData;
        }
    }
}