130 lines
4.6 KiB
C#
130 lines
4.6 KiB
C#
using DoWhatPlc;
|
|
using Newtonsoft.Json;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Net;
|
|
using System.Net.Http;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace DtWebApi
|
|
{
|
|
public partial class ReadWritePLC
|
|
{
|
|
// static object lockerReadWritePLC = new object();
|
|
|
|
public static void Write_TagValueByTagTypeID(string tagTypeCodeID, string opName, object tagValue)
|
|
{
|
|
//lock (lockerReadWritePLC)
|
|
{
|
|
var rs = new ReturnValueString("", tagValue, opName, tagTypeCodeID);
|
|
var tagvalue = JsonConvert.SerializeObject(rs);
|
|
string api = "";
|
|
string type = "GET";
|
|
string controlStr = "PLC1";
|
|
string actionStr = "WritePLC_TagTypeCodeID";
|
|
Dictionary<string, string> dic = new Dictionary<string, string>();
|
|
dic.Add("tagTypeCodeID", tagTypeCodeID);
|
|
dic.Add("opName", opName);
|
|
|
|
ReturnValueString rv = new ReturnValueString();
|
|
rv.TagTypeCodeID = tagTypeCodeID;
|
|
rv.OpName = opName;
|
|
rv.TagValue = tagValue.ToString();
|
|
rv.ValueType = tagValue.GetType().Name.ToLower();
|
|
dic.Add("tagValue", JsonConvert.SerializeObject(rv));
|
|
|
|
new CallWebApi().InvokeWebapiWritePLC(controlStr, actionStr, api, type, dic);
|
|
}
|
|
|
|
}
|
|
public static void Write_TagValueByTagID(string TagID, object tagValue)
|
|
{
|
|
WritePLC(TagID, tagValue);
|
|
}
|
|
public static void WritePLC(string tagTypeCodeID, string opName, object tagValue)
|
|
{
|
|
//lock (lockerReadWritePLC)
|
|
{
|
|
var rs = new ReturnValueString("", tagValue, opName, tagTypeCodeID);
|
|
var tagvalue = JsonConvert.SerializeObject(rs);
|
|
string api = "";
|
|
string type = "GET";
|
|
string controlStr = "PLC1";
|
|
string actionStr = "WritePLC_TagTypeCodeID";
|
|
Dictionary<string, string> dic = new Dictionary<string, string>();
|
|
dic.Add("tagTypeCodeID", tagTypeCodeID);
|
|
dic.Add("opName", opName);
|
|
|
|
ReturnValueString rv = new ReturnValueString();
|
|
rv.TagTypeCodeID = tagTypeCodeID;
|
|
rv.OpName = opName;
|
|
rv.TagValue = tagValue.ToString();
|
|
rv.ValueType = tagValue.GetType().Name.ToLower();
|
|
dic.Add("tagValue", JsonConvert.SerializeObject(rv));
|
|
|
|
|
|
new CallWebApi().InvokeWebapiWritePLC(controlStr, actionStr, api, type, dic);
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
public static void WritePLC(string tagID, object tagValue)
|
|
{
|
|
//lock (lockerReadWritePLC)
|
|
{
|
|
var rs = new ReturnValueString(tagID, tagValue, "", "");
|
|
var tagvalue = JsonConvert.SerializeObject(rs);
|
|
|
|
|
|
string api = "";
|
|
string type = "GET";
|
|
string controlStr = "PLC1";
|
|
string actionStr = "WritePLC";
|
|
Dictionary<string, string> dic = new Dictionary<string, string>();
|
|
dic.Add("tagID", tagID);
|
|
|
|
ReturnValueString rv = new ReturnValueString();
|
|
rv.TagID = tagID;
|
|
rv.TagValue = tagValue.ToString();
|
|
rv.ValueType = tagValue.GetType().Name.ToLower();
|
|
|
|
dic.Add("tagValue", JsonConvert.SerializeObject(rv));
|
|
|
|
new CallWebApi().InvokeWebapiWritePLC(controlStr, actionStr, api, type, dic);
|
|
}
|
|
}
|
|
|
|
public static void Write_TagValueByTagTypeName(string cmd, string opName, object tagValue)
|
|
{
|
|
// lock (lockerReadWritePLC)
|
|
{
|
|
string api = "";
|
|
string type = "GET";
|
|
string controlStr = "PLC1";
|
|
string actionStr = "Write_TagValueByTagTypeName";
|
|
Dictionary<string, string> dic = new Dictionary<string, string>();
|
|
dic.Add("cmd", cmd);
|
|
dic.Add("opName", opName);
|
|
|
|
ReturnValueString rv = new ReturnValueString();
|
|
rv.CmdPlcReadWrite = cmd;
|
|
rv.OpName = opName;
|
|
rv.TagValue = tagValue.ToString();
|
|
rv.ValueType = tagValue.GetType().Name.ToLower();
|
|
dic.Add("tagValue", JsonConvert.SerializeObject(rv)); ;
|
|
|
|
var rc = new CallWebApi().InvokeWebapiReturnValueObject(controlStr, actionStr, api, type, dic);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
}
|