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)
{
}
///
/// S7写入(暂时写这里)
///
///
///
///
///
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();
}
///
/// S7读取
///
///
///
///
///
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;
}
}
}