添加项目文件。
This commit is contained in:
1 parent
d68cdea124
commit
faaf9136d6
51 files changed
+11674
No files matched your search
@@ -0,0 +1,104 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Security.Claims;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace WindowsFormsApp1.server
|
||||
{
|
||||
public class ApiClient
|
||||
{
|
||||
public BllResult SN_CheckIN()
|
||||
{
|
||||
return BllResult.Sucess();
|
||||
}
|
||||
public BllResult Carrier_Check()
|
||||
{
|
||||
return BllResult.Sucess();
|
||||
}
|
||||
public BllResult SN_FeedingCheck()
|
||||
{
|
||||
return BllResult.Sucess();
|
||||
}
|
||||
public BllResult Link_Comp()
|
||||
{
|
||||
return BllResult.Sucess();
|
||||
}
|
||||
public BllResult SN_Release()
|
||||
{
|
||||
return BllResult.Sucess();
|
||||
}
|
||||
public BllResult Glue_CheckOut()
|
||||
{
|
||||
return BllResult.Sucess();
|
||||
}
|
||||
public BllResult Get_Para()
|
||||
{
|
||||
return BllResult.Sucess();
|
||||
}
|
||||
public BllResult DispatchPara()
|
||||
{
|
||||
return BllResult.Sucess();
|
||||
}
|
||||
public BllResult Data_Collection()
|
||||
{
|
||||
return BllResult.Sucess();
|
||||
}
|
||||
public BllResult Status()
|
||||
{
|
||||
return BllResult.Sucess();
|
||||
}
|
||||
public BllResult Alarm()
|
||||
{
|
||||
return BllResult.Sucess();
|
||||
}
|
||||
public BllResult OEEDataCollection()
|
||||
{
|
||||
return BllResult.Sucess();
|
||||
}
|
||||
public BllResult SN_FileUpload()
|
||||
{
|
||||
return BllResult.Sucess();
|
||||
}
|
||||
public BllResult Test()
|
||||
{
|
||||
return BllResult.Sucess();
|
||||
}
|
||||
public BllResult SN_Checkout()
|
||||
{
|
||||
return BllResult.Sucess();
|
||||
}
|
||||
public BllResult Initialization()
|
||||
{
|
||||
//1.获取PLC参数,扫码器参数
|
||||
|
||||
//2、调用接口
|
||||
|
||||
//3.给PLC的 writeaddress赋值
|
||||
|
||||
return BllResult.Sucess("Initialization");
|
||||
}
|
||||
|
||||
public BllResult CallFunctionByName(string functionName)
|
||||
{
|
||||
// 获取当前类的类型
|
||||
Type type = this.GetType();
|
||||
|
||||
// 使用反射调用指定名称的方法
|
||||
MethodInfo methodInfo = type.GetMethod(functionName);
|
||||
|
||||
if (methodInfo != null)
|
||||
{
|
||||
// 调用该方法
|
||||
return (BllResult)methodInfo.Invoke(this, null);
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine($"Method '{functionName}' not found.");
|
||||
return BllResult.Error();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace WindowsFormsApp1.server
|
||||
{
|
||||
public class BllResult<T>
|
||||
{
|
||||
public BllResult(bool success, string msg, T data)
|
||||
{
|
||||
Success = success;
|
||||
Msg = msg;
|
||||
Data = data;
|
||||
}
|
||||
|
||||
public bool Success { get; set; }
|
||||
public string Msg { get; set; }
|
||||
public T Data { get; set; }
|
||||
|
||||
public static BllResult<T> Sucess(T data, String msg)
|
||||
{
|
||||
return new BllResult<T>(true, msg, data);
|
||||
}
|
||||
|
||||
public static BllResult<T> Sucess(T data)
|
||||
{
|
||||
return new BllResult<T>(true, "", data);
|
||||
}
|
||||
|
||||
public static BllResult<T> Sucess(String msg)
|
||||
{
|
||||
return new BllResult<T>(true, msg, default(T));
|
||||
}
|
||||
|
||||
public static BllResult<T> Sucess()
|
||||
{
|
||||
return new BllResult<T>(true, "", default(T));
|
||||
}
|
||||
|
||||
public static BllResult<T> Error(T data, String msg)
|
||||
{
|
||||
return new BllResult<T>(false, msg, data);
|
||||
}
|
||||
|
||||
public static BllResult<T> Error(T data)
|
||||
{
|
||||
return new BllResult<T>(false, "", data);
|
||||
}
|
||||
|
||||
public static BllResult<T> Error(String msg)
|
||||
{
|
||||
return new BllResult<T>(false, msg, default(T));
|
||||
}
|
||||
|
||||
public static BllResult<T> Error()
|
||||
{
|
||||
return new BllResult<T>(false, "", default(T));
|
||||
}
|
||||
}
|
||||
|
||||
public class BllResult
|
||||
{
|
||||
private BllResult(bool success, string msg, object data)
|
||||
{
|
||||
Success = success;
|
||||
Msg = msg;
|
||||
Data = data;
|
||||
}
|
||||
|
||||
public bool Success { get; set; }
|
||||
public string Msg { get; set; }
|
||||
public object Data { get; set; }
|
||||
|
||||
public static BllResult Sucess(Object data, String msg)
|
||||
{
|
||||
return new BllResult(true, msg, data);
|
||||
}
|
||||
|
||||
public static BllResult Sucess(Object data)
|
||||
{
|
||||
return new BllResult(true, "", data);
|
||||
}
|
||||
|
||||
public static BllResult Sucess(String msg)
|
||||
{
|
||||
return new BllResult(true, msg, null);
|
||||
}
|
||||
|
||||
public static BllResult Sucess()
|
||||
{
|
||||
return new BllResult(true, "", null);
|
||||
}
|
||||
|
||||
public static BllResult Error(object data, String msg)
|
||||
{
|
||||
return new BllResult(false, msg, data);
|
||||
}
|
||||
|
||||
public static BllResult Error(object data)
|
||||
{
|
||||
return new BllResult(false, "", data);
|
||||
}
|
||||
|
||||
public static BllResult Error(String msg)
|
||||
{
|
||||
return new BllResult(false, msg, null);
|
||||
}
|
||||
|
||||
public static BllResult Error()
|
||||
{
|
||||
return new BllResult(false, "", null);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using HslCommunication.LogNet;
|
||||
|
||||
namespace WindowsFormsApp1.server
|
||||
{
|
||||
public class LogExecute
|
||||
{
|
||||
public static ILogNet logNet = new LogNetDateTime("C:\\Log\\Logs", GenerateMode.ByEveryDay);
|
||||
public static ILogNet PlclogNet = new LogNetDateTime("C:\\Log\\PlcLogs", GenerateMode.ByEveryDay);
|
||||
public static ILogNet ApilogNet = new LogNetDateTime("C:\\Log\\Apilogs", GenerateMode.ByEveryHour);
|
||||
public static HslCommunication.BasicFramework.SoftNumericalOrder softNumericalOrder = new HslCommunication.BasicFramework.SoftNumericalOrder("", "yyyyMMdd", 4, @"\numericalOrder.txt");
|
||||
|
||||
public LogExecute()
|
||||
{
|
||||
#region 日志
|
||||
|
||||
//设置日志发布等级及触发时间
|
||||
//logNet.SetMessageDegree(HslMessageDegree.INFO);//除DEBUG外,都存储
|
||||
|
||||
#endregion 日志
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,291 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using HslCommunication.Profinet.Siemens;
|
||||
using HslCommunication;
|
||||
using WindowsFormsApp1.mod;
|
||||
|
||||
namespace WindowsFormsApp1.server
|
||||
{
|
||||
public class SiemensHelp
|
||||
{
|
||||
private HslCommunication.Core.IByteTransform ByteTransform = new HslCommunication.Core.ReverseBytesTransform();
|
||||
private SiemensS7Net siemensS7Net;
|
||||
private string ip;
|
||||
private int timeout;
|
||||
private static bool ConnectB = false;
|
||||
public SiemensHelp(string ip,int timeout)
|
||||
{
|
||||
this.ip = ip;
|
||||
this.timeout = timeout;
|
||||
siemensS7Net = new SiemensS7Net(SiemensPLCS.S1500, ip) { ConnectTimeOut = timeout, ReceiveTimeOut = timeout };
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 打开S7 Net长连接
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public BllResult OpenConn()
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!ConnectB)
|
||||
{
|
||||
OperateResult connect = siemensS7Net.ConnectServer();
|
||||
if (!connect.IsSuccess)
|
||||
{
|
||||
return BllResult.Error(connect.Message);
|
||||
}
|
||||
else
|
||||
{
|
||||
ConnectB = true;
|
||||
return BllResult.Sucess();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return BllResult.Sucess();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return BllResult.Error(ex);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 关闭S7 Net长连接
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public BllResult CloseConn()
|
||||
{
|
||||
try
|
||||
{
|
||||
if (ConnectB)
|
||||
{
|
||||
OperateResult connect = siemensS7Net.ConnectClose();
|
||||
if (connect.IsSuccess)
|
||||
{
|
||||
ConnectB = false;
|
||||
return BllResult.Sucess();
|
||||
}
|
||||
else
|
||||
{
|
||||
return BllResult.Error(connect.Message);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return BllResult.Sucess();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return BllResult.Error(ex);
|
||||
}
|
||||
}
|
||||
|
||||
private BllResult ReadOneDB(List<t_plcaddress> address)
|
||||
{
|
||||
address = address.OrderBy(a => a.addressoffset).ToList();
|
||||
OperateResult<byte[]> read;
|
||||
if (address.Count == 1)
|
||||
{
|
||||
string startaddress = address[0].dbaddress + "." + address[0].addressoffset.ToString();
|
||||
read = siemensS7Net.Read(startaddress, Convert.ToUInt16(address[0].addresstypelegth));
|
||||
}
|
||||
else
|
||||
{
|
||||
double admax = address.Select(a => a.addressoffset).Max();
|
||||
double admin = address.Select(a => a.addressoffset).Min();
|
||||
ushort length = (ushort)(Math.Floor(admax - admin) + address.Last().addresstypelegth);
|
||||
string startaddress = address[0].dbaddress + "." + admin.ToString();
|
||||
read = siemensS7Net.Read(startaddress, length);
|
||||
}
|
||||
if (read.IsSuccess)
|
||||
{
|
||||
if (TransforWCSDataToAddressData(address, read).Success)
|
||||
{
|
||||
return BllResult.Sucess(address, "成功");
|
||||
}
|
||||
else
|
||||
{
|
||||
return BllResult.Sucess(address, "成功");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return BllResult.Error(read.Message);
|
||||
}
|
||||
}
|
||||
|
||||
public BllResult ReadAddress(List<t_plcaddress> address)
|
||||
{
|
||||
var ulist = address.GroupBy(a => a.dbaddress).ToList();
|
||||
foreach (var u in ulist)
|
||||
{
|
||||
var readresult = ReadOneDB(u.ToList());
|
||||
if (!readresult.Success)
|
||||
{
|
||||
return BllResult.Error(readresult.Msg);
|
||||
}
|
||||
}
|
||||
return BllResult.Sucess(address, "成功");
|
||||
}
|
||||
|
||||
private BllResult WriteOneDB(List<t_plcaddress> address)
|
||||
{
|
||||
address = address.OrderBy(a => a.addressoffset).ToList();
|
||||
string startaddress = address[0].dbaddress + "." + address[0].addressoffset.ToString();
|
||||
BllResult bllResult = TransforAddressDataToWCSData(address);
|
||||
if (bllResult.Success)
|
||||
{
|
||||
OperateResult operate = siemensS7Net.Write(startaddress, (byte[])bllResult.Data);
|
||||
if (operate.IsSuccess)
|
||||
{
|
||||
return BllResult.Sucess();
|
||||
}
|
||||
else
|
||||
{
|
||||
return BllResult.Error(operate.Message);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return BllResult.Error(bllResult.Msg);
|
||||
}
|
||||
}
|
||||
|
||||
public BllResult WriteAddress(List<t_plcaddress> address)
|
||||
{
|
||||
var ulist = address.GroupBy(a => a.dbaddress).ToList();
|
||||
foreach (var u in ulist)
|
||||
{
|
||||
var readresult = WriteOneDB(u.ToList());
|
||||
if (!readresult.Success)
|
||||
{
|
||||
return BllResult.Error(readresult.Msg);
|
||||
}
|
||||
}
|
||||
return BllResult.Sucess(address, "成功");
|
||||
}
|
||||
|
||||
private BllResult TransforWCSDataToAddressData(List<t_plcaddress> address, OperateResult<byte[]> read)
|
||||
{
|
||||
try
|
||||
{
|
||||
//按偏移量排序
|
||||
address = address.OrderBy(a => a.addressoffset).ToList();
|
||||
int startindex = address[0].addressoffset;
|
||||
for (int i = 0; i < address.Count; i++)
|
||||
{
|
||||
int index = address[i].addressoffset - startindex;
|
||||
switch (address[i].type)
|
||||
{
|
||||
case "byte":
|
||||
address[i].value = ByteTransform.TransByte(read.Content, index).ToString();
|
||||
break;
|
||||
|
||||
case "real":
|
||||
address[i].value = ByteTransform.TransSingle(read.Content, index).ToString();
|
||||
break;
|
||||
|
||||
case "lword":
|
||||
address[i].value = Convert.ToString(ByteTransform.TransInt64(read.Content, index), 16); ;
|
||||
break;
|
||||
|
||||
case "int":
|
||||
address[i].value = ByteTransform.TransInt16(read.Content, index).ToString();
|
||||
break;
|
||||
|
||||
case "uint":
|
||||
address[i].value = BitConverter.ToUInt16(read.Content, index).ToString();
|
||||
break;
|
||||
|
||||
case "dint":
|
||||
address[i].value = Convert.ToString(ByteTransform.TransInt32(read.Content, index), 10);
|
||||
break;
|
||||
|
||||
case "string":
|
||||
address[i].value = Encoding.ASCII.GetString(read.Content, index, address[i].addresstypelegth).Replace(" ", "").Replace("\0", "").Replace("\u0003", "");
|
||||
break;
|
||||
|
||||
default:
|
||||
return BllResult.Error("找不到未知的数据类型");
|
||||
}
|
||||
}
|
||||
return BllResult.Sucess(address);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return BllResult.Error($"转换WCS数据失败{ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
private BllResult TransforAddressDataToWCSData(List<t_plcaddress> address) //返回一个byte[]
|
||||
{
|
||||
try
|
||||
{
|
||||
address = address.OrderBy(a => a.addressoffset).ToList();
|
||||
double admax = address.Select(a => a.addressoffset).Max();
|
||||
double admin = address.Select(a => a.addressoffset).Min();
|
||||
ushort length = (ushort)(Math.Floor(admax - admin) + address.Last().addresstypelegth);
|
||||
int startindex = address[0].addressoffset;
|
||||
byte[] writebyte = new byte[length];
|
||||
for (int i = 0; i < address.Count; i++)
|
||||
{
|
||||
int index = address[i].addressoffset - startindex;
|
||||
object value = address[i].value;
|
||||
switch (address[i].addresstype)
|
||||
{
|
||||
case "byte":
|
||||
byte tobyte = Convert.ToByte(value);
|
||||
ByteTransform.TransByte(tobyte).CopyTo(writebyte, index);
|
||||
break;
|
||||
|
||||
case "lword":
|
||||
if ((string)value == "") value = null;
|
||||
long tolong = Convert.ToInt64((string)value, 16);
|
||||
ByteTransform.TransByte(tolong).CopyTo(writebyte, index);
|
||||
break;
|
||||
|
||||
case "int":
|
||||
short toint = Convert.ToInt16(value);
|
||||
ByteTransform.TransByte(toint).CopyTo(writebyte, index);
|
||||
break;
|
||||
|
||||
case "uint":
|
||||
ushort touint = Convert.ToUInt16(value);
|
||||
ByteTransform.TransByte(touint).CopyTo(writebyte, index);
|
||||
break;
|
||||
|
||||
case "dint":
|
||||
int todint = Convert.ToInt32(value);
|
||||
ByteTransform.TransByte(todint).CopyTo(writebyte, index);
|
||||
break;
|
||||
|
||||
case "read":
|
||||
float todreal = Convert.ToSingle(value);
|
||||
ByteTransform.TransByte(todreal).CopyTo(writebyte, index);
|
||||
break;
|
||||
|
||||
case "string":
|
||||
byte[] tochar = Encoding.ASCII.GetBytes(((string)value).PadRight(address[i].addresstypelegth, ' '));
|
||||
tochar.CopyTo(writebyte, index);
|
||||
break;
|
||||
|
||||
default:
|
||||
return BllResult.Error("找不到未知的数据类型");
|
||||
}
|
||||
}
|
||||
return BllResult.Sucess(writebyte);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return BllResult.Error($"转换WCS数据失败{ex.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user