init: 导入项目到 meswork Gitea
This commit is contained in:
@@ -0,0 +1,848 @@
|
||||
using OpcBasic;
|
||||
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Text;
|
||||
using System.Web;
|
||||
using System.Web.Http;
|
||||
|
||||
using MesWork;
|
||||
using System.Collections.Concurrent;
|
||||
using DoWhatPlc;
|
||||
using System.Collections;
|
||||
using MesDataFunctionWebApi;
|
||||
|
||||
namespace MesWorkWebApp
|
||||
{
|
||||
|
||||
[RoutePrefix("api/PLC1")]
|
||||
public partial class PLC1Controller : ApiController
|
||||
{
|
||||
[HttpGet]
|
||||
public HttpResponseMessage GetHashtableList()
|
||||
{
|
||||
HashtableList hsList = new HashtableList();
|
||||
hsList.hashtable_MesDll = HashtableList.hashtable_MesDll_Temp;
|
||||
hsList.hashtable_MesServerCode = HashtableList.hashtable_MesServerCode_Temp;
|
||||
hsList.hashtable_TagTypeDataType = HashtableList.hashtable_TagTypeDataType_Temp;
|
||||
hsList.hashtable_TagType = HashtableList.hashtable_TagType_Temp;
|
||||
hsList.hashtable_OpNameRepair = HashtableList.hashtable_OpNameRepair_Temp;
|
||||
hsList.hashtable_TagTypeTagName = HashtableList.hashtable_TagTypeTagName_Temp;
|
||||
|
||||
|
||||
hsList.hashtable_workStepProperty = HashtableList.hashtable_workStepProperty_Temp;
|
||||
hsList.hashtable_QualityMesRead = HashtableList.hashtable_QualityMesRead_Temp;
|
||||
hsList.hashtable_IsAllowWork = HashtableList.hashtable_IsAllowWork_Temp;
|
||||
hsList.hashtable_WorkGroupIndex = HashtableList.hashtable_WorkGroupIndex_Temp;
|
||||
hsList.hashtableOpName_OpType = HashtableList.hashtableOpName_OpType_Temp;
|
||||
hsList.hashtable_tagTable_OpName_SaveData = HashtableList.hashtable_tagTable_OpName_SaveData_Temp;
|
||||
|
||||
|
||||
|
||||
hsList.hashtable_EngineGetOver_EngineID = DoWhatPlc.HashtableList.hashtable_EngineGetOver_EngineID_Temp ;
|
||||
hsList.hashtable_EngineGetOver_EngineTypeID = DoWhatPlc.HashtableList.hashtable_EngineGetOver_EngineTypeID_Temp ;
|
||||
hsList.hashtable_EngineGetOver_EngineType = DoWhatPlc.HashtableList.hashtable_EngineGetOver_EngineType_Temp ;
|
||||
hsList.hashtable_EngineGetOver_OrderForm= DoWhatPlc.HashtableList.hashtable_EngineGetOver_OrderForm_Temp ;
|
||||
|
||||
hsList.BasicDataTagValue = MesServerWork.MIS_BASE.BasicDataTagValue;
|
||||
hsList.BasicDataTagValueUpDown = MesServerWork.MIS_BASE.BasicDataTagValueUpDown;
|
||||
hsList.hashtable_EngineTypeID = MesServerWork.MIS_BASE.hashtable_EngineTypeID;
|
||||
hsList.hashtable_tagTable_OpName_SaveData = MesServerWork.MIS_BASE.hashtable_tagTable_OpName_SaveData;
|
||||
|
||||
|
||||
var pp = JsonConvert.SerializeObject(hsList);
|
||||
HttpResponseMessage result = new HttpResponseMessage { Content = new StringContent(pp, Encoding.GetEncoding("UTF-8"), "application/json") };
|
||||
return result;//
|
||||
}
|
||||
[HttpGet]
|
||||
public HttpResponseMessage ReadPLC_OpName(string opName)
|
||||
{
|
||||
try
|
||||
{
|
||||
string tagStartAdr = "";
|
||||
ushort tagAdrListMaxLength = 0;
|
||||
PlcLinkForm.GetDbAndMaxLengthByOpName(opName, out tagStartAdr, out tagAdrListMaxLength);
|
||||
var tagAdrListTagFormat = PlcLinkForm.ReadQualityDataList(opName, tagStartAdr, tagAdrListMaxLength);
|
||||
|
||||
var pp = JsonConvert.SerializeObject(tagAdrListTagFormat);
|
||||
HttpResponseMessage result = new HttpResponseMessage { Content = new StringContent(pp, Encoding.GetEncoding("UTF-8"), "application/json") };
|
||||
return result;
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
var pp = JsonConvert.SerializeObject(ex.Message);
|
||||
HttpResponseMessage result = new HttpResponseMessage { Content = new StringContent(pp, Encoding.GetEncoding("UTF-8"), "application/json") };
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
[HttpGet]
|
||||
public HttpResponseMessage ReadPLC_GroupMonitor(string opName)
|
||||
{
|
||||
List<TagIDTagFormat> TagIDTagFormatList = new List<TagIDTagFormat>();
|
||||
var cd = MesWork.PlcLinkForm.ReadPLC_GroupMonitor(opName);
|
||||
foreach (KeyValuePair<string, object> _cd in cd)
|
||||
{
|
||||
var tagID = _cd.Key;
|
||||
|
||||
var pp1 = JsonConvert.SerializeObject(_cd.Value);
|
||||
var pp2 = JsonConvert.DeserializeObject<DoWhatPlc.TagFormat>(pp1);
|
||||
TagIDTagFormat TagTF = new TagIDTagFormat(tagID, pp2);
|
||||
|
||||
TagIDTagFormatList.Add(TagTF);
|
||||
}
|
||||
var pp = JsonConvert.SerializeObject(TagIDTagFormatList);
|
||||
HttpResponseMessage result = new HttpResponseMessage { Content = new StringContent(pp, Encoding.GetEncoding("UTF-8"), "application/json") };
|
||||
return result;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public HttpResponseMessage ReadPLC_GroupData_Qd(string opName)
|
||||
{
|
||||
List<TagIDTagFormat> TagIDTagFormatList = new List<TagIDTagFormat>();
|
||||
var cd = MesWork.PlcLinkForm.ReadPLC_GroupData_Qd(opName);
|
||||
foreach (KeyValuePair<string, object> _cd in cd)
|
||||
{
|
||||
var tagID = _cd.Key;
|
||||
var pp1 = JsonConvert.SerializeObject(_cd.Value);
|
||||
var pp2 = JsonConvert.DeserializeObject<DoWhatPlc.TagFormat>(pp1);
|
||||
TagIDTagFormat TagTF = new TagIDTagFormat(tagID, pp2);
|
||||
|
||||
TagIDTagFormatList.Add(TagTF);
|
||||
}
|
||||
var pp = JsonConvert.SerializeObject(TagIDTagFormatList);
|
||||
HttpResponseMessage result = new HttpResponseMessage { Content = new StringContent(pp, Encoding.GetEncoding("UTF-8"), "application/json") };
|
||||
return result;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public HttpResponseMessage ReadPLC_GroupData(string opName)
|
||||
{
|
||||
try
|
||||
{
|
||||
List<TagIDTagFormat> TagIDTagFormatList = new List<TagIDTagFormat>();
|
||||
var cd = MesWork.PlcLinkForm.ReadPLC_GroupData(opName);
|
||||
foreach (KeyValuePair<string, object> _cd in cd)
|
||||
{
|
||||
var tagID = _cd.Key;
|
||||
|
||||
var pp1 = JsonConvert.SerializeObject(_cd.Value);
|
||||
var pp2 = JsonConvert.DeserializeObject<DoWhatPlc.TagFormat>(pp1);
|
||||
TagIDTagFormat TagTF = new TagIDTagFormat(tagID, pp2);
|
||||
|
||||
TagIDTagFormatList.Add(TagTF);
|
||||
}
|
||||
var pp = JsonConvert.SerializeObject(TagIDTagFormatList);
|
||||
|
||||
//var rtList = JsonConvert.DeserializeObject<List<TagIDTagFormat>>(pp);
|
||||
|
||||
HttpResponseMessage result = new HttpResponseMessage { Content = new StringContent(pp, Encoding.GetEncoding("UTF-8"), "application/json") };
|
||||
return result;
|
||||
}
|
||||
catch(Exception err)
|
||||
{
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据tagType,工位号写入PLC对应值
|
||||
/// </summary>
|
||||
/// <param name="opName"></param>
|
||||
/// <param name="tagValue"></param>
|
||||
[HttpGet]
|
||||
public void Write_TagValueByTagTypeName(string cmd, string opName, string tagValue)
|
||||
{
|
||||
int tagTypeID = 0;
|
||||
string msg;
|
||||
try
|
||||
{
|
||||
var rvValue = JsonConvert.DeserializeObject<ReturnValueString>(tagValue);
|
||||
ReturnValueObject ro = rvValue.ReturnValueToObject();
|
||||
|
||||
tagTypeID = Convert.ToInt32(MesDataFunction.OpcOperation.hashtable_TagType[cmd]);
|
||||
MesDataFunction.OpcOperation.WriteTagValue(tagTypeID, opName, ro.TagValue);
|
||||
}
|
||||
catch (Exception err)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据tagType,工位号写入PLC对应值
|
||||
/// </summary>
|
||||
/// <param name="opName"></param>
|
||||
/// <param name="tagValue"></param>
|
||||
[HttpGet]
|
||||
public void Write_TagValueByTagTypeNameList(string cmd, string opName, string tagValue)
|
||||
{
|
||||
int tagTypeID = 0;
|
||||
string msg;
|
||||
var cmd_List = JsonConvert.DeserializeObject<List<string>>(cmd);
|
||||
var opName_List = JsonConvert.DeserializeObject<List<string>>(opName);
|
||||
var tagValue_List = JsonConvert.DeserializeObject<List<string>>(tagValue);
|
||||
try
|
||||
{
|
||||
for(int i=0;i< cmd_List.Count;i++)
|
||||
{
|
||||
Write_TagValueByTagTypeName(cmd, opName, tagValue);
|
||||
}
|
||||
}
|
||||
catch (Exception err)
|
||||
{
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 通过TagTypeName读取PLC数据 列表
|
||||
/// </summary>
|
||||
/// <param name="opName"></param>
|
||||
/// <param name="tagValue"></param>
|
||||
[HttpGet]
|
||||
public HttpResponseMessage Read_TagValueByTagTypeNameList(string cmd, string opName)
|
||||
{
|
||||
object tagValue;
|
||||
List<ReturnValueString> rvList = new List<ReturnValueString>();
|
||||
tagValue = "-1";
|
||||
int tagTypeID;
|
||||
var cmd_List = JsonConvert.DeserializeObject<List<string>>(cmd);
|
||||
var opName_List = JsonConvert.DeserializeObject<List<string>>(opName);
|
||||
|
||||
try
|
||||
{
|
||||
for(int i = 0; i < cmd_List.Count; i++)
|
||||
{
|
||||
cmd = cmd_List[i];
|
||||
opName = opName_List[i];
|
||||
tagTypeID = Convert.ToInt32(MesDataFunction.OpcOperation.hashtable_TagType[cmd]);
|
||||
tagValue = PlcLinkForm.ReadPLC(tagTypeID, opName);
|
||||
ReturnValueString rv = new ReturnValueString();
|
||||
rv.CmdPlcReadWrite = cmd;
|
||||
rv.OpName = opName;
|
||||
rv.TagValue = tagValue.ToString();
|
||||
rv.TagTypeID = tagTypeID.ToString();
|
||||
rv.ValueType = tagValue.GetType().Name.ToLower();
|
||||
|
||||
rvList.Add(rv);
|
||||
}
|
||||
|
||||
var pp = JsonConvert.SerializeObject(rvList);
|
||||
HttpResponseMessage result = new HttpResponseMessage { Content = new StringContent(pp, Encoding.GetEncoding("UTF-8"), "application/json") };
|
||||
return result;
|
||||
}
|
||||
catch (Exception err)
|
||||
{
|
||||
var pp = JsonConvert.SerializeObject(err);
|
||||
HttpResponseMessage result = new HttpResponseMessage { Content = new StringContent(pp, Encoding.GetEncoding("UTF-8"), "application/json") };
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 通过TagTypeName读取PLC数据
|
||||
/// </summary>
|
||||
/// <param name="opName"></param>
|
||||
/// <param name="tagValue"></param>
|
||||
[HttpGet]
|
||||
public HttpResponseMessage Read_TagValueByTagTypeName(string cmd, string opName)
|
||||
{
|
||||
object tagValue = "-1";
|
||||
int tagTypeID;
|
||||
try
|
||||
{
|
||||
tagTypeID = Convert.ToInt32(MesDataFunction.OpcOperation.hashtable_TagType[cmd]);
|
||||
tagValue = PlcLinkForm.ReadPLC(tagTypeID, opName);
|
||||
ReturnValueString rv = new ReturnValueString();
|
||||
rv.CmdPlcReadWrite = cmd;
|
||||
rv.OpName = opName;
|
||||
rv.TagValue = tagValue.ToString();
|
||||
rv.TagTypeID = tagTypeID.ToString();
|
||||
rv.ValueType = tagValue.GetType().Name.ToLower();
|
||||
var pp = JsonConvert.SerializeObject(rv);
|
||||
HttpResponseMessage result = new HttpResponseMessage { Content = new StringContent(pp, Encoding.GetEncoding("UTF-8"), "application/json") };
|
||||
return result;
|
||||
}
|
||||
catch (Exception err)
|
||||
{
|
||||
var pp = JsonConvert.SerializeObject(err);
|
||||
HttpResponseMessage result = new HttpResponseMessage { Content = new StringContent(pp, Encoding.GetEncoding("UTF-8"), "application/json") };
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// http://localhost:41180/api/PLC/ReadAllTagValue?opname=OP1010
|
||||
/// </summary>
|
||||
/// <param name="tagID"></param>
|
||||
/// <returns>ReturnValue</returns>
|
||||
[HttpGet]
|
||||
public HttpResponseMessage ReadAllTagValue(string opname)
|
||||
{
|
||||
var objValue = PlcLinkForm.ReadAllTagValue(opname);
|
||||
|
||||
var pp = JsonConvert.SerializeObject(objValue);
|
||||
HttpResponseMessage result = new HttpResponseMessage { Content = new StringContent(pp, Encoding.GetEncoding("UTF-8"), "application/json") };
|
||||
return result;
|
||||
}
|
||||
/// <summary>
|
||||
/// http://localhost:41180/api/PLC/Get_opNameList
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public HttpResponseMessage Get_opNameList()
|
||||
{
|
||||
|
||||
var pp = JsonConvert.SerializeObject(PlcLinkForm.opNameList);
|
||||
HttpResponseMessage result = new HttpResponseMessage { Content = new StringContent(pp, Encoding.GetEncoding("UTF-8"), "application/json") };
|
||||
return result;
|
||||
}
|
||||
/// <summary>
|
||||
/// http://localhost:41180/api/PLC/Get_ipList
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public HttpResponseMessage Get_ipList()
|
||||
{
|
||||
|
||||
var pp = JsonConvert.SerializeObject(PlcLinkForm.ipList);
|
||||
HttpResponseMessage result = new HttpResponseMessage { Content = new StringContent(pp, Encoding.GetEncoding("UTF-8"), "application/json") };
|
||||
return result;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public HttpResponseMessage Get_cd_Cache_IpGroupMonitorList()
|
||||
{
|
||||
var cd_Cache_IpGroupMonitorList = PlcLinkForm.DriverCache[CacheType.Cache_IpGroupMonitorList];
|
||||
var pp = JsonConvert.SerializeObject(cd_Cache_IpGroupMonitorList);
|
||||
HttpResponseMessage result = new HttpResponseMessage { Content = new StringContent(pp, Encoding.GetEncoding("UTF-8"), "application/json") };
|
||||
return result;
|
||||
}
|
||||
[HttpGet]
|
||||
public HttpResponseMessage Get_TagAdrListTagFormat(string ip,string group)
|
||||
{
|
||||
ConcurrentDictionary<string, object> TagAdrListTagFormat;
|
||||
PlcLinkForm.Driver.ReadIpGroupDataList(ip, group, out TagAdrListTagFormat);
|
||||
|
||||
var pp = JsonConvert.SerializeObject(TagAdrListTagFormat);
|
||||
HttpResponseMessage result = new HttpResponseMessage { Content = new StringContent(pp, Encoding.GetEncoding("UTF-8"), "application/json") };
|
||||
return result;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public HttpResponseMessage ReadTagValue_tagAdrListTagFormat(string readWhat, string opOrIp)
|
||||
{
|
||||
ConcurrentDictionary<string, object> tagAdrListTagFormat = null;
|
||||
|
||||
switch (readWhat)
|
||||
{
|
||||
case "OpAllTag"://OP所有点
|
||||
tagAdrListTagFormat = PlcLinkForm.ReadPLC_GroupData(opOrIp);
|
||||
break;
|
||||
case "OpMonitorTag"://OP监控点
|
||||
tagAdrListTagFormat = PlcLinkForm.ReadPLC_GroupMonitor(opOrIp);
|
||||
break;
|
||||
case "IpAllTag"://IP所有点
|
||||
tagAdrListTagFormat = PlcLinkForm.ReadPLC_IpTag(opOrIp);
|
||||
break;
|
||||
case "IpMonitorTag"://IP监控点
|
||||
tagAdrListTagFormat = PlcLinkForm.ReadPLC_IpMonitorTag(opOrIp);
|
||||
break;
|
||||
case "RegionRead"://按区域读取(起始地址 + 长度)
|
||||
string tagStartAdr = "";
|
||||
ushort tagAdrListMaxLength = 0;
|
||||
PlcLinkForm.GetDbAndMaxLengthByOpName(opOrIp, out tagStartAdr, out tagAdrListMaxLength);
|
||||
tagAdrListTagFormat = PlcLinkForm.ReadQualityDataList(opOrIp, tagStartAdr, tagAdrListMaxLength);
|
||||
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
var pp = JsonConvert.SerializeObject(tagAdrListTagFormat);
|
||||
HttpResponseMessage result = new HttpResponseMessage { Content = new StringContent(pp, Encoding.GetEncoding("UTF-8"), "application/json") };
|
||||
return result;
|
||||
|
||||
}
|
||||
//
|
||||
/// <summary>
|
||||
/// http://localhost:41180/api/PLC/ReadPLC?opname=AOPOP001
|
||||
/// </summary>
|
||||
/// <param name="tagID"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public HttpResponseMessage ReadPLC(string tagID)
|
||||
{
|
||||
var tagValue = PlcLinkForm.ReadPLC(tagID);
|
||||
ReturnValueString rv = new ReturnValueString();
|
||||
rv.CmdPlcReadWrite = "";
|
||||
rv.OpName = "";
|
||||
rv.TagValue = tagValue.ToString();
|
||||
rv.TagID = tagID;
|
||||
rv.ValueType = tagValue.GetType().Name.ToLower();
|
||||
|
||||
var pp = JsonConvert.SerializeObject(rv);
|
||||
HttpResponseMessage result = new HttpResponseMessage { Content = new StringContent(pp, Encoding.GetEncoding("UTF-8"), "application/json") };
|
||||
return result;
|
||||
}
|
||||
[HttpGet]
|
||||
public HttpResponseMessage ReadByteData_Op(string OpName,string Adr, string Length)
|
||||
{
|
||||
ushort LengthValue = Convert .ToUInt16(Length);
|
||||
var tagValue = PlcLinkForm.ReadByteData_Op(OpName, Adr, LengthValue); ;
|
||||
ReturnValueString rv = new ReturnValueString();
|
||||
rv.CmdPlcReadWrite = "";
|
||||
rv.OpName = "";
|
||||
rv.TagValue = System.Text.Encoding.UTF8.GetString(tagValue);
|
||||
rv.TagID = "";
|
||||
rv.ValueType = tagValue.GetType().Name.ToLower();
|
||||
|
||||
var pp = JsonConvert.SerializeObject(rv);
|
||||
HttpResponseMessage result = new HttpResponseMessage { Content = new StringContent(pp, Encoding.GetEncoding("UTF-8"), "application/json") };
|
||||
return result;
|
||||
}
|
||||
[HttpGet]
|
||||
public HttpResponseMessage ReadByteData_Ip(string Ip, string Adr, string Length)
|
||||
{
|
||||
ushort LengthValue = Convert.ToUInt16(Length);
|
||||
|
||||
var tagValue = PlcLinkForm.ReadByteData_Op(Ip, Adr, LengthValue); ;
|
||||
ReturnValueString rv = new ReturnValueString();
|
||||
rv.CmdPlcReadWrite = "";
|
||||
rv.OpName = "";
|
||||
rv.TagValue = System.Text.Encoding.UTF8.GetString(tagValue);
|
||||
rv.TagID = "";
|
||||
rv.ValueType = tagValue.GetType().Name.ToLower();
|
||||
|
||||
var pp = JsonConvert.SerializeObject(rv);
|
||||
HttpResponseMessage result = new HttpResponseMessage { Content = new StringContent(pp, Encoding.GetEncoding("UTF-8"), "application/json") };
|
||||
return result;
|
||||
}
|
||||
[HttpGet]
|
||||
public HttpResponseMessage WritePLC_Bytes_Op(string OpName, string Adr, string bytes)
|
||||
{
|
||||
byte[] bytesValue = JsonToByte(bytes);
|
||||
var tagValue = PlcLinkForm.WritePLC_Bytes_Op(OpName, Adr, bytesValue);
|
||||
ReturnValueString rv = new ReturnValueString();
|
||||
rv.CmdPlcReadWrite = "";
|
||||
rv.OpName = "";
|
||||
rv.TagValue = tagValue.ToString();
|
||||
rv.TagID = "";
|
||||
rv.ValueType = tagValue.GetType().Name.ToLower();
|
||||
|
||||
var pp = JsonConvert.SerializeObject(rv);
|
||||
HttpResponseMessage result = new HttpResponseMessage { Content = new StringContent(pp, Encoding.GetEncoding("UTF-8"), "application/json") };
|
||||
return result;
|
||||
}
|
||||
[HttpGet]
|
||||
public HttpResponseMessage WritePLC_Bytes_Ip(string Ip, string Adr, string bytes)
|
||||
{
|
||||
byte[] bytesValue = JsonToByte(bytes);
|
||||
var tagValue = PlcLinkForm.WritePLC_Bytes_Ip(Ip, Adr, bytesValue); ;
|
||||
ReturnValueString rv = new ReturnValueString();
|
||||
rv.CmdPlcReadWrite = "";
|
||||
rv.OpName = "";
|
||||
rv.TagValue = tagValue.ToString();
|
||||
rv.TagID = "";
|
||||
rv.ValueType = tagValue.GetType().Name.ToLower();
|
||||
|
||||
var pp = JsonConvert.SerializeObject(rv);
|
||||
HttpResponseMessage result = new HttpResponseMessage { Content = new StringContent(pp, Encoding.GetEncoding("UTF-8"), "application/json") };
|
||||
return result;
|
||||
}
|
||||
public string ByteToJson(byte[] bytes)
|
||||
{
|
||||
string convertJson = System.Text.Encoding.UTF8.GetString(bytes);
|
||||
return convertJson;
|
||||
}
|
||||
|
||||
public byte[] JsonToByte(string strjson)
|
||||
{
|
||||
byte[] bytes = System.Text.Encoding.UTF8.GetBytes(strjson);
|
||||
|
||||
return bytes;
|
||||
}
|
||||
|
||||
|
||||
// case DoWhat.ReadByteData_Op://按区域读取(起始地址 + 长度)
|
||||
// {
|
||||
// //string tagStartAdr = "DB411.10";
|
||||
// //ushort tagAdrListMaxLength = 100;
|
||||
// result = PlcLinkForm.ReadByteData_Op(opOrIp, tagStartAdr, tagAdrListMaxLength);
|
||||
// }
|
||||
// break;
|
||||
// case DoWhat.ReadByteData_Ip://按区域读取(起始地址 + 长度)
|
||||
// {
|
||||
// //string tagStartAdr = "DB411.10";
|
||||
// //ushort tagAdrListMaxLength = 100;
|
||||
// result = PlcLinkForm.ReadByteData_Ip(opOrIp, tagStartAdr, tagAdrListMaxLength);
|
||||
// }
|
||||
// break;
|
||||
// case DoWhat.WritePLC_Bytes_Op://按区域读取(起始地址 + 长度)
|
||||
// {
|
||||
// //string tagStartAdr = "DB411.10";
|
||||
// result = PlcLinkForm.WritePLC_Bytes_Op(opOrIp, tagStartAdr, new byte[1024]);
|
||||
// }
|
||||
// break;
|
||||
// case DoWhat.WritePLC_Bytes_Ip://按区域读取(起始地址 + 长度)
|
||||
// {
|
||||
// //string tagStartAdr = "DB411.10";
|
||||
// result = PlcLinkForm.WritePLC_Bytes_Ip(opOrIp, tagStartAdr, new byte[1024]);
|
||||
// }
|
||||
// break;
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// http://localhost:41180/api/PLC/ReadPLCList?tagID=["AOPOP001","AOPOP002"]
|
||||
/// </summary>
|
||||
/// <param name="tagID"> List<string></param>
|
||||
/// <returns>ReturnValue</returns>
|
||||
[HttpGet]
|
||||
public HttpResponseMessage ReadPLCList(string tagID)
|
||||
{
|
||||
|
||||
List<ReturnValueString> tagValeList = new List<ReturnValueString>();
|
||||
var tagID_List = JsonConvert.DeserializeObject<List<string>>(tagID);
|
||||
foreach (var tagID1 in tagID_List)
|
||||
{
|
||||
var objValue = PlcLinkForm.ReadPLC(tagID1);
|
||||
|
||||
object tagValue = PlcLinkForm.ReadPLC(tagID1);
|
||||
ReturnValueString rv = new ReturnValueString();
|
||||
rv.CmdPlcReadWrite = "";
|
||||
rv.OpName = "";
|
||||
rv.TagValue = tagValue.ToString();
|
||||
rv.TagID = tagID1;
|
||||
rv.ValueType = tagValue.GetType().Name.ToLower();
|
||||
|
||||
//ReturnValueString rs = new ReturnValueString(tagID1, objValue);
|
||||
tagValeList.Add(rv);
|
||||
}
|
||||
|
||||
var pp = JsonConvert.SerializeObject(tagValeList);
|
||||
HttpResponseMessage result = new HttpResponseMessage { Content = new StringContent(pp, Encoding.GetEncoding("UTF-8"), "application/json") };
|
||||
return result;
|
||||
}
|
||||
/// <summary>
|
||||
/// http://localhost:41180/api/PLC/WritePLC?tagID=AOPOP001&tagValue=222
|
||||
/// </summary>
|
||||
/// <param name="tagID"> List<string></param>
|
||||
/// <param name="tagValue"> List<string></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public bool WritePLC(string tagID, string tagValue)
|
||||
{
|
||||
try
|
||||
{
|
||||
var rs = JsonConvert.DeserializeObject<ReturnValueString>(tagValue);
|
||||
var ro = rs.ReturnValueToObject();
|
||||
var objValue = PlcLinkForm.WritePLC(tagID, ro.TagValue);
|
||||
return objValue;
|
||||
}
|
||||
catch
|
||||
(Exception ex)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// http://localhost:41180/api/PLC/WritePLCList?tagID=["AOPOP001","AOPOP002"]&tagValue=["222","111"]
|
||||
/// </summary>
|
||||
/// <param name="tagID"> List<string></param>
|
||||
/// <param name="tagValue"> List<string></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public bool WritePLCList(string tagID, string tagValue)
|
||||
{
|
||||
var tagID_List = JsonConvert.DeserializeObject<List<string>>(tagID);
|
||||
var tagValue_List = JsonConvert.DeserializeObject<List<string>>(tagValue);
|
||||
bool objValue = false;
|
||||
for (int i = 0; i < tagID_List.Count; i++)
|
||||
{
|
||||
string tagID1 = tagID_List[i];
|
||||
var rs = JsonConvert.DeserializeObject<ReturnValueString>(tagValue_List[i]);
|
||||
var ro = rs.ReturnValueToObject();
|
||||
|
||||
objValue = PlcLinkForm.WritePLC(tagID1, ro.TagValue);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
/// <summary>
|
||||
/// http://localhost:41180/api/PLC/ReadPLC_TagTypeCodeID?tagTypeCodeID=10&opName=OP1010
|
||||
/// </summary>
|
||||
/// <param name="tagTypeCodeID"></param>
|
||||
/// <param name="opName"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public HttpResponseMessage ReadPLC_TagTypeCodeID(string tagTypeCodeID, string opName)
|
||||
{
|
||||
|
||||
var tagValue = PlcLinkForm.ReadPLC( Convert.ToInt32(tagTypeCodeID) , opName);
|
||||
ReturnValueString rv = new ReturnValueString();
|
||||
rv.CmdPlcReadWrite = "";
|
||||
rv.OpName = opName;
|
||||
rv.TagValue = tagValue.ToString();
|
||||
rv.TagTypeID = tagTypeCodeID.ToString();
|
||||
rv.ValueType = tagValue.GetType().Name.ToLower();
|
||||
var pp = JsonConvert.SerializeObject(rv);
|
||||
|
||||
//ReturnValueString rs = new ReturnValueString("", objValue, opName, tagTypeCodeID);
|
||||
//var pp = JsonConvert.SerializeObject(rs);
|
||||
HttpResponseMessage result = new HttpResponseMessage { Content = new StringContent(pp, Encoding.GetEncoding("UTF-8"), "application/json") };
|
||||
return result;
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="tagTypeCodeID">List<string></param>
|
||||
/// <param name="opName">List<string></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public HttpResponseMessage ReadPLC_TagTypeCodeIDList(string tagTypeCodeID, string opName)
|
||||
{
|
||||
var tagTypeCodeID_List = JsonConvert.DeserializeObject<List<string>>(tagTypeCodeID);
|
||||
var opName_List = JsonConvert.DeserializeObject<List<string>>(opName);
|
||||
List<ReturnValueString> ReturnValueList = new List<ReturnValueString>();
|
||||
|
||||
|
||||
for (int i = 0; i < tagTypeCodeID_List.Count; i++)
|
||||
{
|
||||
string tagTypeCodeI1 = tagTypeCodeID_List[i];
|
||||
string opName1 = opName_List[i];
|
||||
var tagValue = PlcLinkForm.ReadPLC(Convert.ToInt32(tagTypeCodeI1), opName1);
|
||||
|
||||
ReturnValueString rv = new ReturnValueString();
|
||||
rv.CmdPlcReadWrite = "";
|
||||
rv.OpName = opName;
|
||||
rv.TagValue = tagValue.ToString();
|
||||
rv.TagTypeID = tagTypeCodeI1.ToString();
|
||||
rv.ValueType = tagValue.GetType().Name.ToLower();
|
||||
rv.TagTypeCodeID = tagTypeCodeI1;
|
||||
ReturnValueList.Add(rv);
|
||||
}
|
||||
var pp = JsonConvert.SerializeObject(ReturnValueList);
|
||||
HttpResponseMessage result = new HttpResponseMessage { Content = new StringContent(pp, Encoding.GetEncoding("UTF-8"), "application/json") };
|
||||
return result;
|
||||
}
|
||||
/// <summary>
|
||||
/// http://localhost:41180/api/PLC/ReadPLC_TagTypeCodeID?tagTypeCodeID=10&opName=OP1010&tagValue=111
|
||||
/// </summary>
|
||||
/// <param name="tagTypeCodeID"></param>
|
||||
/// <param name="opName"></param>
|
||||
/// <param name="tagValue"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public bool WritePLC_TagTypeCodeID(string tagTypeCodeID, string opName,string tagValue)
|
||||
{
|
||||
var rs = JsonConvert.DeserializeObject<ReturnValueString>(tagValue);
|
||||
var ro = rs.ReturnValueToObject();
|
||||
|
||||
var objValue = PlcLinkForm.WritePLC(Convert.ToInt32(tagTypeCodeID), opName, ro.TagValue);
|
||||
return objValue;
|
||||
}
|
||||
///// <summary>
|
||||
///// http://localhost:41180/api/PLC/ReadPLC_GroupData?opName=OP1010
|
||||
///// </summary>
|
||||
///// <param name="opOrIp"></param>
|
||||
///// <returns></returns>
|
||||
//[HttpGet]
|
||||
//public HttpResponseMessage ReadPLC_GroupData(string opName)
|
||||
//{
|
||||
// List<ReturnValueString> rvList = new List<ReturnValueString>();
|
||||
// var objValue = PlcLinkForm.ReadPLC_GroupData(opName);
|
||||
// //得到工位信号列表
|
||||
// foreach (KeyValuePair<string, object> de in objValue)
|
||||
// {
|
||||
// DoWhatPlc.TagFormat TF = (DoWhatPlc.TagFormat)de.Value;
|
||||
// ReturnValueString rs = new ReturnValueString(TF.TagID, TF.TagValue, TF.OpName);
|
||||
// rvList.Add(rs);
|
||||
// }
|
||||
// //ReturnValue rv = new ReturnValue("", objValue, opOrIp);
|
||||
// var pp = JsonConvert.SerializeObject(rvList);
|
||||
// HttpResponseMessage result = new HttpResponseMessage { Content = new StringContent(pp, Encoding.GetEncoding("UTF-8"), "application/json") };
|
||||
// return result;
|
||||
//}
|
||||
///// <summary>
|
||||
///// http://localhost:41180/api/PLC/ReadPLC_GroupMonitor?opName=OP1010
|
||||
///// </summary>
|
||||
///// <param name="opName"></param>
|
||||
///// <returns></returns>
|
||||
//[HttpGet]
|
||||
//public HttpResponseMessage ReadPLC_GroupMonitor(string opName)
|
||||
//{
|
||||
// List<ReturnValueString> rvList = new List<ReturnValueString>();
|
||||
// var objValue = PlcLinkForm.ReadPLC_GroupMonitor(opName);
|
||||
// foreach (KeyValuePair<string, object> de in objValue)
|
||||
// {
|
||||
// DoWhatPlc.TagFormat TF = (DoWhatPlc.TagFormat)de.Value;
|
||||
// ReturnValueString rs = new ReturnValueString(TF.TagID, TF.TagValue, TF.OpName);
|
||||
// rvList.Add(rs);
|
||||
// }
|
||||
// var pp = JsonConvert.SerializeObject(rvList);
|
||||
// HttpResponseMessage result = new HttpResponseMessage { Content = new StringContent(pp, Encoding.GetEncoding("UTF-8"), "application/json") };
|
||||
// return result;
|
||||
//}
|
||||
/// <summary>
|
||||
/// http://localhost:41180/api/PLC/ReadPLC_IpTag?ip=127.0.0.1
|
||||
/// </summary>
|
||||
/// <param name="ip"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public HttpResponseMessage ReadPLC_IpTag(string ip)
|
||||
{
|
||||
List<ReturnValueString> rvList = new List<ReturnValueString>();
|
||||
var objValue = PlcLinkForm.ReadPLC_IpTag(ip);
|
||||
foreach (KeyValuePair<string, object> de in objValue)
|
||||
{
|
||||
DoWhatPlc.TagFormat TF = (DoWhatPlc.TagFormat)de.Value;
|
||||
ReturnValueString rs = new ReturnValueString();
|
||||
rs.TagID = TF.TagID;
|
||||
rs.TagValue = TF.TagValue.ToString();
|
||||
rs.OpName = TF.OpName;
|
||||
rs.ValueType = TF.TagValue.GetType().Name.ToLower();
|
||||
rvList.Add(rs);
|
||||
}
|
||||
var pp = JsonConvert.SerializeObject(rvList);
|
||||
HttpResponseMessage result = new HttpResponseMessage { Content = new StringContent(pp, Encoding.GetEncoding("UTF-8"), "application/json") };
|
||||
return result;
|
||||
}
|
||||
/// <summary>
|
||||
/// http://localhost:41180/api/PLC/ReadPLC_IpTag?ip=127.0.0.1
|
||||
/// </summary>
|
||||
/// <param name="ip"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public HttpResponseMessage ReadPLC_IpMonitorTag(string ip)
|
||||
{
|
||||
List<ReturnValueString> rvList = new List<ReturnValueString>();
|
||||
var objValue = PlcLinkForm.ReadPLC_IpMonitorTag(ip);
|
||||
foreach (KeyValuePair<string, object> de in objValue)
|
||||
{
|
||||
DoWhatPlc.TagFormat TF = (DoWhatPlc.TagFormat)de.Value;
|
||||
ReturnValueString rs = new ReturnValueString();
|
||||
rs.TagID = TF.TagID;
|
||||
rs.TagValue = TF.TagValue.ToString();
|
||||
rs.OpName = TF.OpName;
|
||||
rs.ValueType = TF.TagValue.GetType().Name.ToLower();
|
||||
rvList.Add(rs);
|
||||
}
|
||||
var pp = JsonConvert.SerializeObject(rvList);
|
||||
HttpResponseMessage result = new HttpResponseMessage { Content = new StringContent(pp, Encoding.GetEncoding("UTF-8"), "application/json") };
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 读写取方法
|
||||
/// </summary>
|
||||
/// <param name="readWhat"></param>
|
||||
/// <param name="opOrIp"></param>
|
||||
//[HttpGet]
|
||||
//private void ReadWritePLC(string doWhat, DoWhatPlc.TagFormat tf)
|
||||
//{
|
||||
// try
|
||||
// {
|
||||
|
||||
|
||||
// string opName = tf.OpName;//."OP1010";
|
||||
// object tagValue = tf.TagValue;
|
||||
// object result ;
|
||||
// string opOrIp = tf.IP;
|
||||
// string tagID = tf.TagID;
|
||||
// int tagTypeCodeID = tf.TagTypeCodeID;
|
||||
// string tagStartAdr = tf.TagOPCAdrStr;
|
||||
// ushort tagAdrListMaxLength =(ushort) tf.Length;
|
||||
|
||||
|
||||
// ConcurrentDictionary<string, object> tagAdrListTagFormat = null;
|
||||
|
||||
// switch (doWhat)
|
||||
// {
|
||||
// case DoWhat.ReadPLC_TagID:
|
||||
// tagValue = PlcLinkForm.ReadPLC(tagID);
|
||||
// break;
|
||||
// case DoWhat.WritePLC_TagID:
|
||||
// result = PlcLinkForm.WritePLC(tagID, tagValue);
|
||||
// break;
|
||||
|
||||
// case DoWhat.ReadPLC_TagTypeCodeID:
|
||||
// tagValue = PlcLinkForm.ReadPLC(tagTypeCodeID, opName);
|
||||
// break;
|
||||
// case DoWhat.WritePLC_TagTypeCodeID:
|
||||
// result = PlcLinkForm.WritePLC(tagTypeCodeID, opName, tagValue);
|
||||
// break;
|
||||
// case DoWhat.ReadPLC_GroupData://OP所有点
|
||||
// tagAdrListTagFormat = PlcLinkForm.ReadPLC_GroupData(opOrIp);
|
||||
// break;
|
||||
// case DoWhat.ReadPLC_GroupMonitor://OP监控点
|
||||
// tagAdrListTagFormat = PlcLinkForm.ReadPLC_GroupMonitor(opOrIp);
|
||||
// break;
|
||||
// case DoWhat.ReadPLC_IpTag://IP所有点
|
||||
// tagAdrListTagFormat = PlcLinkForm.ReadPLC_IpTag(opOrIp);
|
||||
// break;
|
||||
// case DoWhat.ReadPLC_IpMonitorTag://IP监控点
|
||||
// tagAdrListTagFormat = PlcLinkForm.ReadPLC_IpMonitorTag(opOrIp);
|
||||
// break;
|
||||
// case DoWhat.ReadQualityDataList://按区域读取(起始地址 + 长度)
|
||||
// {
|
||||
// //string tagStartAdr = "DB411.10";
|
||||
// //ushort tagAdrListMaxLength = 100;
|
||||
// PlcLinkForm.GetDbAndMaxLengthByOpName(opOrIp, out tagStartAdr, out tagAdrListMaxLength);
|
||||
// tagAdrListTagFormat = PlcLinkForm.ReadQualityDataList(opOrIp, tagStartAdr, tagAdrListMaxLength);
|
||||
// }
|
||||
// break;
|
||||
// case DoWhat.ReadByteData_Op://按区域读取(起始地址 + 长度)
|
||||
// {
|
||||
// //string tagStartAdr = "DB411.10";
|
||||
// //ushort tagAdrListMaxLength = 100;
|
||||
// result = PlcLinkForm.ReadByteData_Op(opOrIp, tagStartAdr, tagAdrListMaxLength);
|
||||
// }
|
||||
// break;
|
||||
// case DoWhat.ReadByteData_Ip://按区域读取(起始地址 + 长度)
|
||||
// {
|
||||
// //string tagStartAdr = "DB411.10";
|
||||
// //ushort tagAdrListMaxLength = 100;
|
||||
// result = PlcLinkForm.ReadByteData_Ip(opOrIp, tagStartAdr, tagAdrListMaxLength);
|
||||
// }
|
||||
// break;
|
||||
// case DoWhat.WritePLC_Bytes_Op://按区域读取(起始地址 + 长度)
|
||||
// {
|
||||
// //string tagStartAdr = "DB411.10";
|
||||
// result = PlcLinkForm.WritePLC_Bytes_Op(opOrIp, tagStartAdr, new byte[1024]);
|
||||
// }
|
||||
// break;
|
||||
// case DoWhat.WritePLC_Bytes_Ip://按区域读取(起始地址 + 长度)
|
||||
// {
|
||||
// //string tagStartAdr = "DB411.10";
|
||||
// result = PlcLinkForm.WritePLC_Bytes_Ip(opOrIp, tagStartAdr, new byte[1024]);
|
||||
// }
|
||||
// break;
|
||||
// default:
|
||||
// break;
|
||||
// }
|
||||
|
||||
// //得到工位信号列表
|
||||
// foreach (System.Collections.Generic.KeyValuePair<string, object> de in tagAdrListTagFormat)
|
||||
// {
|
||||
// DoWhatPlc.TagFormat TF = (DoWhatPlc.TagFormat)de.Value;
|
||||
// string recResult = TF.OpName + " (" + TF.TagTypeCodeID + ")" + TF.TagValue.ToString(); ;
|
||||
// }
|
||||
|
||||
// }
|
||||
// catch (System.Exception err)
|
||||
// {
|
||||
// }
|
||||
|
||||
//}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user