株洲长江硬质合金工具有限公司 项目

master
xiaoguo 2 years ago
parent 163f1f75c0
commit b09f326df4

@ -0,0 +1,69 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
namespace PLCCommunication.Common
{
public class ModelTools
{
public static class PubClone<TEntity, TResult>
{
private static readonly Func<TEntity, TResult> cache = GetFunc();
private static Func<TEntity, TResult> GetFunc()
{
ParameterExpression parameterExpression = Expression.Parameter(typeof(TEntity), "p");
List<MemberBinding> memberBindingList = new List<MemberBinding>();
foreach (var item in typeof(TResult).GetProperties())
{
if (!item.CanWrite)
{
continue;
}
var _Property = typeof(TEntity).GetProperty(item.Name);
if (_Property == null)
{
continue;
}
if (item.PropertyType.FullName != _Property.PropertyType.FullName)
{
continue;
}
MemberExpression property = Expression.Property(parameterExpression, typeof(TEntity).GetProperty(item.Name));
MemberBinding memberBinding = Expression.Bind(item, property);
memberBindingList.Add(memberBinding);
}
MemberInitExpression memberInitExpression = Expression.MemberInit(Expression.New(typeof(TResult)), memberBindingList.ToArray());
Expression<Func<TEntity, TResult>> lambda = Expression.Lambda<Func<TEntity, TResult>>(memberInitExpression, new ParameterExpression[] { parameterExpression });
return lambda.Compile();
}
public static TResult Trans(TEntity tIn)
{
if (tIn == null)
{
return default(TResult);
}
return cache(tIn);
}
public static List<TResult> TransList(List<TEntity> list)
{
List<TResult> result = new List<TResult>();
foreach (var item in list)
{
result.Add(Trans(item));
}
return result;
}
}
}
}

@ -0,0 +1,77 @@
using HslCommunication;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PLCCommunication.Common
{
public class PLCResult
{
//
// 摘要:
// 指示本次操作是否成功。
// Indicates whether this operation was successful.
public bool IsSuccess { get; set; }
//
// 摘要:
// 具体的错误描述。
// Specific error description.
public string Message { get; set; }
public int ErrorCode { get; set; }
//
// 摘要:
// 实例化一个默认的结果对象
public PLCResult()
{
}
//
// 摘要:
// 使用指定的消息实例化一个默认的结果对象
//
// 参数:
// msg:
// 错误消息
public PLCResult(string msg)
{
Message = msg;
}
//
// 摘要:
// 使用错误代码,消息文本来实例化对象
//
// 参数:
// err:
// 错误代码
//
// msg:
// 错误消息
public PLCResult(int err, string msg)
{
ErrorCode = err;
Message = msg;
}
}
public class PLCResult<T> : PLCResult
{
public T Content { get; set; }
public PLCResult()
{
}
public PLCResult(T content)
{
Content = content;
}
}
}

@ -0,0 +1,261 @@
using HslCommunication.Core.Address;
using HslCommunication;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Sockets;
using System.Text;
using System.Threading.Tasks;
using HslCommunication.Profinet.Siemens;
using PLCCommunication.Common;
namespace PLCCommunication
{
/// <summary>
/// PLC通信接口
/// </summary>
public interface IPLCCommunicationService
{
/// <summary>
/// 是否已连接
/// </summary>
bool isConnected { get; }
#region 同步
/// <summary>
/// 连接PLC长连接
/// </summary>
/// <param name="address"></param>
/// <param name="port"></param>
PLCResult Connection(string address, int port = 0);
/// <summary>
/// 关闭连接PLC长连接
/// </summary>
PLCResult ColseConnection();
/// <summary>
/// 读取指定地址的byte[]值
/// </summary>
/// <param name="address"></param>
/// <returns></returns>
PLCResult<byte[]> ReadBytes(string address, ushort length);
/// <summary>
/// 读取指定地址的bool值
/// </summary>
/// <param name="address"></param>
/// <returns></returns>
PLCResult<bool> ReadBool(string address);
/// <summary>
/// 读取指定地址的byte值
/// </summary>
/// <param name="address"></param>
/// <returns></returns>
PLCResult<byte> ReadByte(string address);
/// <summary>
/// 读取指定地址的Int16值
/// </summary>
/// <param name="address"></param>
/// <returns></returns>
PLCResult<short> ReadInt16(string address);
/// <summary>
/// 读取指定地址的Int32值
/// </summary>
/// <param name="address"></param>
/// <returns></returns>
PLCResult<int> ReadInt32(string address);
/// <summary>
/// 读取指定地址的long值
/// </summary>
/// <param name="address"></param>
/// <returns></returns>
PLCResult<long> ReadLong(string address);
/// <summary>
/// 读取指定地址的Float值
/// </summary>
/// <returns></returns>
PLCResult<float> ReadFloat(string address);
/// <summary>
/// 读取指定地址的double值
/// </summary>
/// <returns></returns>
PLCResult<double> ReadDouble(string address);
/// <summary>
/// 写入bool值
/// </summary>
/// <param name="address">写入地址</param>
/// <param name="value"></param>
PLCResult Write(string address, bool value);
/// <summary>
/// 写入byte值
/// </summary>
/// <param name="address">写入地址</param>
/// <param name="value"></param>
PLCResult Write(string address, byte value);
/// <summary>
/// 写入Int16值
/// </summary>
/// <param name="address">写入地址</param>
/// <param name="value"></param>
PLCResult Write(string address, Int16 value);
/// <summary>
/// 写入Int32值
/// </summary>
/// <param name="address">写入地址</param>
/// <param name="value"></param>
PLCResult Write(string address, Int32 value);
/// <summary>
/// 写入float值
/// </summary>
/// <param name="address">写入地址</param>
/// <param name="value"></param>
PLCResult Write(string address, float value);
/// <summary>
/// 写入double值
/// </summary>
/// <param name="address">写入地址</param>
/// <param name="value"></param>
PLCResult Write(string address, double value);
/// <summary>
/// 写入long值
/// </summary>
/// <param name="address">写入地址</param>
/// <param name="value"></param>
PLCResult Write(string address, long value);
#endregion
#region 异步
/// <summary>
/// 连接PLC长连接
/// </summary>
/// <param name="address"></param>
/// <param name="port"></param>
Task<PLCResult> ConnectionAsync(string address, int port = 0);
/// <summary>
/// 关闭连接PLC长连接
/// </summary>
Task<PLCResult> ColseConnectionAsyn();
/// <summary>
/// 读取指定地址的byte[]值
/// </summary>
/// <param name="address"></param>
/// <returns></returns>
Task<PLCResult<byte[]>> ReadBytesAsync(string address, ushort length);
/// <summary>
/// 读取指定地址的bool值
/// </summary>
/// <param name="address"></param>
/// <returns></returns>
Task<PLCResult<bool>> ReadBoolAsync(string address);
/// <summary>
/// 读取指定地址的byte值
/// </summary>
/// <param name="address"></param>
/// <returns></returns>
Task<PLCResult<byte>> ReadByteAsync(string address);
/// <summary>
/// 读取指定地址的Int16值
/// </summary>
/// <param name="address"></param>
/// <returns></returns>
Task<PLCResult<short>> ReadInt16Async(string address);
/// <summary>
/// 读取指定地址的Int32值
/// </summary>
/// <param name="address"></param>
/// <returns></returns>
Task<PLCResult<int>> ReadInt32Async(string address);
/// <summary>
/// 读取指定地址的long值
/// </summary>
/// <param name="address"></param>
/// <returns></returns>
Task<PLCResult<long>> ReadLongAsync(string address);
/// <summary>
/// 读取指定地址的Float值
/// </summary>
/// <returns></returns>
Task<PLCResult<float>> ReadFloatAsync(string address);
/// <summary>
/// 读取指定地址的double值
/// </summary>
/// <returns></returns>
Task<PLCResult<double>> ReadDoubleAsync(string address);
/// <summary>
/// 写入bool值
/// </summary>
/// <param name="address">写入地址</param>
/// <param name="value"></param>
Task<PLCResult> WriteAsync(string address, bool value);
/// <summary>
/// 写入byte值
/// </summary>
/// <param name="address">写入地址</param>
/// <param name="value"></param>
Task<PLCResult> WriteAsync(string address, byte value);
/// <summary>
/// 写入Int16值
/// </summary>
/// <param name="address">写入地址</param>
/// <param name="value"></param>
Task<PLCResult> WriteAsync(string address, Int16 value);
/// <summary>
/// 写入Int32值
/// </summary>
/// <param name="address">写入地址</param>
/// <param name="value"></param>
Task<PLCResult> WriteAsync(string address, Int32 value);
/// <summary>
/// 写入float值
/// </summary>
/// <param name="address">写入地址</param>
/// <param name="value"></param>
Task<PLCResult> WriteAsync(string address, float value);
/// <summary>
/// 写入double值
/// </summary>
/// <param name="address">写入地址</param>
/// <param name="value"></param>
Task<PLCResult> WriteAsync(string address, double value);
/// <summary>
/// 写入long值
/// </summary>
/// <param name="address">写入地址</param>
/// <param name="value"></param>
Task<PLCResult> WriteAsync(string address, long value);
#endregion
}
}

@ -0,0 +1,487 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Sockets;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using PLCCommunication;
using HslCommunication.Profinet.Siemens;
using HslCommunication;
using PLCCommunication.Common;
using HslCommunication.Profinet.Delta;
namespace PLCCommunication.Impl
{
/// <summary>
/// PLC通信服务 SiemensS7 smart200 实现
/// </summary>
internal class DeltaCommunicationService : IPLCCommunicationService
{
private DeltaTcpNet deltaTcpNet = null;
/// <summary>
/// 是否已连接
/// </summary>
public bool isConnected { get; private set; }
public DeltaCommunicationService()
{
deltaTcpNet = new DeltaTcpNet();
deltaTcpNet.Series = DeltaSeries.AS;
deltaTcpNet.ConnectTimeOut = 3000;
}
#region 同步
/// <summary>
/// 连接PLC长连接
/// </summary>
/// <param name="address"></param>
/// <param name="port"></param>
public PLCResult Connection(string address, int port = 0)
{
deltaTcpNet.IpAddress = address;
if (port > 0)
{
deltaTcpNet.Port = port;
}
var operateResult = deltaTcpNet.ConnectServer();
var result = ConvertResult(operateResult);
if (result.IsSuccess)
{
isConnected = true;
}
return result;
}
/// <summary>
/// 关闭连接PLC长连接
/// </summary>
public PLCResult ColseConnection()
{
var operateResult = deltaTcpNet.ConnectClose();
var result = ConvertResult(operateResult);
if (result.IsSuccess)
{
isConnected = false;
}
return result;
}
/// <summary>
/// 读取指定地址的byte[]值
/// </summary>
/// <param name="address"></param>
/// <returns></returns>
public PLCResult<byte[]> ReadBytes(string address, ushort length)
{
var operateResult = deltaTcpNet.Read(address, length);
var result = ConvertResult(operateResult);
return result;
}
/// <summary>
/// 读取指定地址的bool值
/// </summary>
/// <param name="address"></param>
/// <returns></returns>
public PLCResult<bool> ReadBool(string address)
{
var operateResult = deltaTcpNet.ReadBool(address);
var result = ConvertResult(operateResult);
return result;
}
/// <summary>
/// 读取指定地址的byte值
/// </summary>
/// <param name="address"></param>
/// <returns></returns>
public PLCResult<byte> ReadByte(string address)
{
throw new NotImplementedException();
}
/// <summary>
/// 读取指定地址的Int16值
/// </summary>
/// <param name="address"></param>
/// <returns></returns>
public PLCResult<short> ReadInt16(string address)
{
var operateResult = deltaTcpNet.ReadInt16(address);
var result = ConvertResult(operateResult);
return result;
}
/// <summary>
/// 读取指定地址的Int32值
/// </summary>
/// <param name="address"></param>
/// <returns></returns>
public PLCResult<int> ReadInt32(string address)
{
var operateResult = deltaTcpNet.ReadInt32(address);
var result = ConvertResult(operateResult);
return result;
}
/// <summary>
/// 读取指定地址的long值
/// </summary>
/// <param name="address"></param>
/// <returns></returns>
public PLCResult<long> ReadLong(string address)
{
var operateResult = deltaTcpNet.ReadInt64(address);
var result = ConvertResult(operateResult);
return result;
}
/// <summary>
/// 读取指定地址的Float值
/// </summary>
/// <returns></returns>
public PLCResult<float> ReadFloat(string address)
{
var operateResult = deltaTcpNet.ReadFloat(address);
var result = ConvertResult(operateResult);
return result;
}
/// <summary>
/// 读取指定地址的double值
/// </summary>
/// <returns></returns>
public PLCResult<double> ReadDouble(string address)
{
var operateResult = deltaTcpNet.ReadDouble(address);
var result = ConvertResult(operateResult);
return result;
}
/// <summary>
/// 写入bool值
/// </summary>
/// <param name="address">写入地址</param>
/// <param name="value"></param>
public PLCResult Write(string address, bool value)
{
var operateResult = deltaTcpNet.Write(address, value);
var result = ConvertResult(operateResult);
return result;
}
/// <summary>
/// 写入byte值
/// </summary>
/// <param name="address">写入地址</param>
/// <param name="value"></param>
public PLCResult Write(string address, byte value)
{
var operateResult = deltaTcpNet.Write(address, value);
var result = ConvertResult(operateResult);
return result;
}
/// <summary>
/// 写入Int16值
/// </summary>
/// <param name="address">写入地址</param>
/// <param name="value"></param>
public PLCResult Write(string address, Int16 value)
{
var operateResult = deltaTcpNet.Write(address, value);
var result = ConvertResult(operateResult);
return result;
}
/// <summary>
/// 写入Int32值
/// </summary>
/// <param name="address">写入地址</param>
/// <param name="value"></param>
public PLCResult Write(string address, Int32 value)
{
var operateResult = deltaTcpNet.Write(address, value);
var result = ConvertResult(operateResult);
return result;
}
/// <summary>
/// 写入float值
/// </summary>
/// <param name="address">写入地址</param>
/// <param name="value"></param>
public PLCResult Write(string address, float value)
{
var operateResult = deltaTcpNet.Write(address, value);
var result = ConvertResult(operateResult);
return result;
}
/// <summary>
/// 写入double值
/// </summary>
/// <param name="address">写入地址</param>
/// <param name="value"></param>
public PLCResult Write(string address, double value)
{
var operateResult = deltaTcpNet.Write(address, value);
var result = ConvertResult(operateResult);
return result;
}
/// <summary>
/// 写入long值
/// </summary>
/// <param name="address">写入地址</param>
/// <param name="value"></param>
public PLCResult Write(string address, long value)
{
var operateResult = deltaTcpNet.Write(address, value);
var result = ConvertResult(operateResult);
return result;
}
#endregion
#region 异步
/// <summary>
/// 连接PLC长连接
/// </summary>
/// <param name="address"></param>
/// <param name="port"></param>
public async Task<PLCResult> ConnectionAsync(string address, int port = 0)
{
deltaTcpNet.IpAddress = address;
if (port > 0)
{
deltaTcpNet.Port = port;
}
var operateResult = await deltaTcpNet.ConnectServerAsync();
var result = ConvertResult(operateResult);
if (operateResult.IsSuccess)
{
isConnected = true;
}
return result;
}
/// <summary>
/// 关闭连接PLC长连接
/// </summary>
public async Task<PLCResult> ColseConnectionAsyn()
{
var operateResult = await deltaTcpNet.ConnectCloseAsync();
var result = ConvertResult(operateResult);
if (operateResult.IsSuccess)
{
isConnected = false;
}
return result;
}
/// <summary>
/// 读取指定地址的byte[]值
/// </summary>
/// <param name="address"></param>
/// <returns></returns>
public async Task<PLCResult<byte[]>> ReadBytesAsync(string address, ushort length)
{
var operateResult = await deltaTcpNet.ReadAsync(address, length);
var result = ConvertResult(operateResult);
return result;
}
/// <summary>
/// 读取指定地址的bool值
/// </summary>
/// <param name="address"></param>
/// <returns></returns>
public async Task<PLCResult<bool>> ReadBoolAsync(string address)
{
var operateResult = await deltaTcpNet.ReadBoolAsync(address);
var result = ConvertResult(operateResult);
return result;
}
/// <summary>
/// 读取指定地址的byte值
/// </summary>
/// <param name="address"></param>
/// <returns></returns>
public async Task<PLCResult<byte>> ReadByteAsync(string address)
{
throw new NotImplementedException();
}
/// <summary>
/// 读取指定地址的Int16值
/// </summary>
/// <param name="address"></param>
/// <returns></returns>
public async Task<PLCResult<short>> ReadInt16Async(string address)
{
var operateResult = await deltaTcpNet.ReadInt16Async(address);
var result = ConvertResult(operateResult);
return result;
}
/// <summary>
/// 读取指定地址的Int32值
/// </summary>
/// <param name="address"></param>
/// <returns></returns>
public async Task<PLCResult<int>> ReadInt32Async(string address)
{
var operateResult = await deltaTcpNet.ReadInt32Async(address);
var result = ConvertResult(operateResult);
return result;
}
/// <summary>
/// 读取指定地址的long值
/// </summary>
/// <param name="address"></param>
/// <returns></returns>
public async Task<PLCResult<long>> ReadLongAsync(string address)
{
var operateResult = await deltaTcpNet.ReadInt64Async(address);
var result = ConvertResult(operateResult);
return result;
}
/// <summary>
/// 读取指定地址的Float值
/// </summary>
/// <returns></returns>
public async Task<PLCResult<float>> ReadFloatAsync(string address)
{
var operateResult = await deltaTcpNet.ReadFloatAsync(address);
var result = ConvertResult(operateResult);
return result;
}
/// <summary>
/// 读取指定地址的double值
/// </summary>
/// <returns></returns>
public async Task<PLCResult<double>> ReadDoubleAsync(string address)
{
var operateResult = await deltaTcpNet.ReadDoubleAsync(address);
var result = ConvertResult(operateResult);
return result;
}
/// <summary>
/// 写入bool值
/// </summary>
/// <param name="address">写入地址</param>
/// <param name="value"></param>
public async Task<PLCResult> WriteAsync(string address, bool value)
{
var operateResult = await deltaTcpNet.WriteAsync(address, value);
var result = ConvertResult(operateResult);
return result;
}
/// <summary>
/// 写入byte值
/// </summary>
/// <param name="address">写入地址</param>
/// <param name="value"></param>
public async Task<PLCResult> WriteAsync(string address, byte value)
{
var operateResult = await deltaTcpNet.WriteAsync(address, value);
var result = ConvertResult(operateResult);
return result;
}
/// <summary>
/// 写入Int16值
/// </summary>
/// <param name="address">写入地址</param>
/// <param name="value"></param>
public async Task<PLCResult> WriteAsync(string address, Int16 value)
{
var operateResult = await deltaTcpNet.WriteAsync(address, value);
var result = ConvertResult(operateResult);
return result;
}
/// <summary>
/// 写入Int32值
/// </summary>
/// <param name="address">写入地址</param>
/// <param name="value"></param>
public async Task<PLCResult> WriteAsync(string address, Int32 value)
{
var operateResult = await deltaTcpNet.WriteAsync(address, value);
var result = ConvertResult(operateResult);
return result;
}
/// <summary>
/// 写入float值
/// </summary>
/// <param name="address">写入地址</param>
/// <param name="value"></param>
public async Task<PLCResult> WriteAsync(string address, float value)
{
var operateResult = await deltaTcpNet.WriteAsync(address, value);
var result = ConvertResult(operateResult);
return result;
}
/// <summary>
/// 写入double值
/// </summary>
/// <param name="address">写入地址</param>
/// <param name="value"></param>
public async Task<PLCResult> WriteAsync(string address, double value)
{
var operateResult = await deltaTcpNet.WriteAsync(address, value);
var result = ConvertResult(operateResult);
return result;
}
/// <summary>
/// 写入long值
/// </summary>
/// <param name="address">写入地址</param>
/// <param name="value"></param>
public async Task<PLCResult> WriteAsync(string address, long value)
{
var operateResult = await deltaTcpNet.WriteAsync(address, value);
var result = ConvertResult(operateResult);
return result;
}
#endregion
/// <summary>
/// 转换 result (将框架结果结构转换成当前程序结果结构)
/// </summary>
/// <param name="result"></param>
/// <returns></returns>
private PLCResult ConvertResult(OperateResult result)
{
var retResult = ModelTools.PubClone<OperateResult, PLCResult>.Trans(result);
return retResult;
}
/// <summary>
/// 转换 result (将框架结果结构转换成当前程序结果结构)
/// </summary>
/// <param name="result"></param>
/// <returns></returns>
private PLCResult<T> ConvertResult<T>(OperateResult<T> result)
{
var retResult = ModelTools.PubClone<OperateResult<T>, PLCResult<T>>.Trans(result);
retResult.Content = result.Content;
return retResult;
}
}
}

@ -0,0 +1,489 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Sockets;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using PLCCommunication;
using HslCommunication.Profinet.Siemens;
using HslCommunication;
using PLCCommunication.Common;
namespace PLCCommunication.Impl
{
/// <summary>
/// PLC通信服务 SiemensS7 smart200 实现
/// </summary>
internal class SiemensCommunicationService : IPLCCommunicationService
{
private SiemensS7Net siemensS7Net = null;
/// <summary>
/// 是否已连接
/// </summary>
public bool isConnected { get; private set; }
public SiemensCommunicationService()
{
siemensS7Net = new SiemensS7Net(SiemensPLCS.S200Smart);
siemensS7Net.ConnectTimeOut = 3000;
}
#region 同步
/// <summary>
/// 连接PLC长连接
/// </summary>
/// <param name="address"></param>
/// <param name="port"></param>
public PLCResult Connection(string address, int port = 0)
{
siemensS7Net.IpAddress = address;
if (port > 0)
{
siemensS7Net.Port = port;
}
var operateResult = siemensS7Net.ConnectServer();
var result = ConvertResult(operateResult);
if (result.IsSuccess)
{
isConnected = true;
}
return result;
}
/// <summary>
/// 关闭连接PLC长连接
/// </summary>
public PLCResult ColseConnection()
{
var operateResult = siemensS7Net.ConnectClose();
var result = ConvertResult(operateResult);
if (result.IsSuccess)
{
isConnected = false;
}
return result;
}
/// <summary>
/// 读取指定地址的byte[]值
/// </summary>
/// <param name="address"></param>
/// <returns></returns>
public PLCResult<byte[]> ReadBytes(string address, ushort length)
{
var operateResult = siemensS7Net.Read(address, length);
var result = ConvertResult(operateResult);
return result;
}
/// <summary>
/// 读取指定地址的bool值
/// </summary>
/// <param name="address"></param>
/// <returns></returns>
public PLCResult<bool> ReadBool(string address)
{
var operateResult = siemensS7Net.ReadBool(address);
var result = ConvertResult(operateResult);
return result;
}
/// <summary>
/// 读取指定地址的byte值
/// </summary>
/// <param name="address"></param>
/// <returns></returns>
public PLCResult<byte> ReadByte(string address)
{
var operateResult = siemensS7Net.ReadByte(address);
var result = ConvertResult(operateResult);
return result;
}
/// <summary>
/// 读取指定地址的Int16值
/// </summary>
/// <param name="address"></param>
/// <returns></returns>
public PLCResult<short> ReadInt16(string address)
{
var operateResult = siemensS7Net.ReadInt16(address);
var result = ConvertResult(operateResult);
return result;
}
/// <summary>
/// 读取指定地址的Int32值
/// </summary>
/// <param name="address"></param>
/// <returns></returns>
public PLCResult<int> ReadInt32(string address)
{
var operateResult = siemensS7Net.ReadInt32(address);
var result = ConvertResult(operateResult);
return result;
}
/// <summary>
/// 读取指定地址的long值
/// </summary>
/// <param name="address"></param>
/// <returns></returns>
public PLCResult<long> ReadLong(string address)
{
var operateResult = siemensS7Net.ReadInt64(address);
var result = ConvertResult(operateResult);
return result;
}
/// <summary>
/// 读取指定地址的Float值
/// </summary>
/// <returns></returns>
public PLCResult<float> ReadFloat(string address)
{
var operateResult = siemensS7Net.ReadFloat(address);
var result = ConvertResult(operateResult);
return result;
}
/// <summary>
/// 读取指定地址的double值
/// </summary>
/// <returns></returns>
public PLCResult<double> ReadDouble(string address)
{
var operateResult = siemensS7Net.ReadDouble(address);
var result = ConvertResult(operateResult);
return result;
}
/// <summary>
/// 写入bool值
/// </summary>
/// <param name="address">写入地址</param>
/// <param name="value"></param>
public PLCResult Write(string address, bool value)
{
var operateResult = siemensS7Net.Write(address, value);
var result = ConvertResult(operateResult);
return result;
}
/// <summary>
/// 写入byte值
/// </summary>
/// <param name="address">写入地址</param>
/// <param name="value"></param>
public PLCResult Write(string address, byte value)
{
var operateResult = siemensS7Net.Write(address, value);
var result = ConvertResult(operateResult);
return result;
}
/// <summary>
/// 写入Int16值
/// </summary>
/// <param name="address">写入地址</param>
/// <param name="value"></param>
public PLCResult Write(string address, Int16 value)
{
var operateResult = siemensS7Net.Write(address, value);
var result = ConvertResult(operateResult);
return result;
}
/// <summary>
/// 写入Int32值
/// </summary>
/// <param name="address">写入地址</param>
/// <param name="value"></param>
public PLCResult Write(string address, Int32 value)
{
var operateResult = siemensS7Net.Write(address, value);
var result = ConvertResult(operateResult);
return result;
}
/// <summary>
/// 写入float值
/// </summary>
/// <param name="address">写入地址</param>
/// <param name="value"></param>
public PLCResult Write(string address, float value)
{
var operateResult = siemensS7Net.Write(address, value);
var result = ConvertResult(operateResult);
return result;
}
/// <summary>
/// 写入double值
/// </summary>
/// <param name="address">写入地址</param>
/// <param name="value"></param>
public PLCResult Write(string address, double value)
{
var operateResult = siemensS7Net.Write(address, value);
var result = ConvertResult(operateResult);
return result;
}
/// <summary>
/// 写入long值
/// </summary>
/// <param name="address">写入地址</param>
/// <param name="value"></param>
public PLCResult Write(string address, long value)
{
var operateResult = siemensS7Net.Write(address, value);
var result = ConvertResult(operateResult);
return result;
}
#endregion
#region 异步
/// <summary>
/// 连接PLC长连接
/// </summary>
/// <param name="address"></param>
/// <param name="port"></param>
public async Task<PLCResult> ConnectionAsync(string address, int port = 0)
{
siemensS7Net.IpAddress = address;
if (port > 0)
{
siemensS7Net.Port = port;
}
var operateResult = await siemensS7Net.ConnectServerAsync();
var result = ConvertResult(operateResult);
if (operateResult.IsSuccess)
{
isConnected = true;
}
return result;
}
/// <summary>
/// 关闭连接PLC长连接
/// </summary>
public async Task<PLCResult> ColseConnectionAsyn()
{
var operateResult = await siemensS7Net.ConnectCloseAsync();
var result = ConvertResult(operateResult);
if (operateResult.IsSuccess)
{
isConnected = false;
}
return result;
}
/// <summary>
/// 读取指定地址的byte[]值
/// </summary>
/// <param name="address"></param>
/// <returns></returns>
public async Task<PLCResult<byte[]>> ReadBytesAsync(string address, ushort length)
{
var operateResult = await siemensS7Net.ReadAsync(address, length);
var result = ConvertResult(operateResult);
return result;
}
/// <summary>
/// 读取指定地址的bool值
/// </summary>
/// <param name="address"></param>
/// <returns></returns>
public async Task<PLCResult<bool>> ReadBoolAsync(string address)
{
var operateResult = await siemensS7Net.ReadBoolAsync(address);
var result = ConvertResult(operateResult);
return result;
}
/// <summary>
/// 读取指定地址的byte值
/// </summary>
/// <param name="address"></param>
/// <returns></returns>
public async Task<PLCResult<byte>> ReadByteAsync(string address)
{
var operateResult = await siemensS7Net.ReadByteAsync(address);
var result = ConvertResult(operateResult);
return result;
}
/// <summary>
/// 读取指定地址的Int16值
/// </summary>
/// <param name="address"></param>
/// <returns></returns>
public async Task<PLCResult<short>> ReadInt16Async(string address)
{
var operateResult = await siemensS7Net.ReadInt16Async(address);
var result = ConvertResult(operateResult);
return result;
}
/// <summary>
/// 读取指定地址的Int32值
/// </summary>
/// <param name="address"></param>
/// <returns></returns>
public async Task<PLCResult<int>> ReadInt32Async(string address)
{
var operateResult = await siemensS7Net.ReadInt32Async(address);
var result = ConvertResult(operateResult);
return result;
}
/// <summary>
/// 读取指定地址的long值
/// </summary>
/// <param name="address"></param>
/// <returns></returns>
public async Task<PLCResult<long>> ReadLongAsync(string address)
{
var operateResult = await siemensS7Net.ReadInt64Async(address);
var result = ConvertResult(operateResult);
return result;
}
/// <summary>
/// 读取指定地址的Float值
/// </summary>
/// <returns></returns>
public async Task<PLCResult<float>> ReadFloatAsync(string address)
{
var operateResult = await siemensS7Net.ReadFloatAsync(address);
var result = ConvertResult(operateResult);
return result;
}
/// <summary>
/// 读取指定地址的double值
/// </summary>
/// <returns></returns>
public async Task<PLCResult<double>> ReadDoubleAsync(string address)
{
var operateResult = await siemensS7Net.ReadDoubleAsync(address);
var result = ConvertResult(operateResult);
return result;
}
/// <summary>
/// 写入bool值
/// </summary>
/// <param name="address">写入地址</param>
/// <param name="value"></param>
public async Task<PLCResult> WriteAsync(string address, bool value)
{
var operateResult = await siemensS7Net.WriteAsync(address, value);
var result = ConvertResult(operateResult);
return result;
}
/// <summary>
/// 写入byte值
/// </summary>
/// <param name="address">写入地址</param>
/// <param name="value"></param>
public async Task<PLCResult> WriteAsync(string address, byte value)
{
var operateResult = await siemensS7Net.WriteAsync(address, value);
var result = ConvertResult(operateResult);
return result;
}
/// <summary>
/// 写入Int16值
/// </summary>
/// <param name="address">写入地址</param>
/// <param name="value"></param>
public async Task<PLCResult> WriteAsync(string address, Int16 value)
{
var operateResult = await siemensS7Net.WriteAsync(address, value);
var result = ConvertResult(operateResult);
return result;
}
/// <summary>
/// 写入Int32值
/// </summary>
/// <param name="address">写入地址</param>
/// <param name="value"></param>
public async Task<PLCResult> WriteAsync(string address, Int32 value)
{
var operateResult = await siemensS7Net.WriteAsync(address, value);
var result = ConvertResult(operateResult);
return result;
}
/// <summary>
/// 写入float值
/// </summary>
/// <param name="address">写入地址</param>
/// <param name="value"></param>
public async Task<PLCResult> WriteAsync(string address, float value)
{
var operateResult = await siemensS7Net.WriteAsync(address, value);
var result = ConvertResult(operateResult);
return result;
}
/// <summary>
/// 写入double值
/// </summary>
/// <param name="address">写入地址</param>
/// <param name="value"></param>
public async Task<PLCResult> WriteAsync(string address, double value)
{
var operateResult = await siemensS7Net.WriteAsync(address, value);
var result = ConvertResult(operateResult);
return result;
}
/// <summary>
/// 写入long值
/// </summary>
/// <param name="address">写入地址</param>
/// <param name="value"></param>
public async Task<PLCResult> WriteAsync(string address, long value)
{
var operateResult = await siemensS7Net.WriteAsync(address, value);
var result = ConvertResult(operateResult);
return result;
}
#endregion
/// <summary>
/// 转换 result (将框架结果结构转换成当前程序结果结构)
/// </summary>
/// <param name="result"></param>
/// <returns></returns>
private PLCResult ConvertResult(OperateResult result)
{
var retResult = ModelTools.PubClone<OperateResult, PLCResult>.Trans(result);
return retResult;
}
/// <summary>
/// 转换 result (将框架结果结构转换成当前程序结果结构)
/// </summary>
/// <param name="result"></param>
/// <returns></returns>
private PLCResult<T> ConvertResult<T>(OperateResult<T> result)
{
var retResult = ModelTools.PubClone<OperateResult<T>, PLCResult<T>>.Trans(result);
retResult.Content = result.Content;
return retResult;
}
}
}

@ -0,0 +1,56 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{0A7F9893-61CC-4188-8285-1E6C0B916B1A}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>PLCCommunication</RootNamespace>
<AssemblyName>PLCCommunication</AssemblyName>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="HslCommunication">
<HintPath>..\packages\HslCommunication.11.0.6.0\HslCommunication.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Common\ModelTools.cs" />
<Compile Include="Impl\DeltaCommunicationService.cs" />
<Compile Include="Impl\SiemensCommunicationService.cs" />
<Compile Include="Common\PLCResult.cs" />
<Compile Include="IPLCCommunicationService.cs" />
<Compile Include="PLCCommunicationFactory.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

@ -0,0 +1,27 @@
using PLCCommunication.Impl;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PLCCommunication
{
public static class PLCCommunicationFactory
{
public static IPLCCommunicationService pLCCommunicationService = null;
public static IPLCCommunicationService Instance
{
get
{
if (pLCCommunicationService == null)
{
pLCCommunicationService = new DeltaCommunicationService();
pLCCommunicationService.Connection("192.168.0.50",502);
}
return pLCCommunicationService;
}
}
}
}

@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// 有关程序集的一般信息由以下
// 控制。更改这些特性值可修改
// 与程序集关联的信息。
[assembly: AssemblyTitle("PLCCommunication")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("PLCCommunication")]
[assembly: AssemblyCopyright("Copyright © 2023")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// 将 ComVisible 设置为 false 会使此程序集中的类型
//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型
//请将此类型的 ComVisible 特性设置为 true。
[assembly: ComVisible(false)]
// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
[assembly: Guid("0a7f9893-61cc-4188-8285-1e6c0b916b1a")]
// 程序集的版本信息由下列四个值组成:
//
// 主版本
// 次版本
// 生成号
// 修订号
//
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值
//通过使用 "*",如下所示:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

@ -19,6 +19,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ZWGXPICK_SYS.SerialPort", "
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "test_serialPort", "test_serialPort\test_serialPort.csproj", "{F3D367EA-BA7F-44C9-91CD-409AA53C024B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PLCCommunication", "PLCCommunication\PLCCommunication.csproj", "{0A7F9893-61CC-4188-8285-1E6C0B916B1A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -57,6 +59,10 @@ Global
{F3D367EA-BA7F-44C9-91CD-409AA53C024B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F3D367EA-BA7F-44C9-91CD-409AA53C024B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F3D367EA-BA7F-44C9-91CD-409AA53C024B}.Release|Any CPU.Build.0 = Release|Any CPU
{0A7F9893-61CC-4188-8285-1E6C0B916B1A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0A7F9893-61CC-4188-8285-1E6C0B916B1A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0A7F9893-61CC-4188-8285-1E6C0B916B1A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0A7F9893-61CC-4188-8285-1E6C0B916B1A}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

@ -0,0 +1,95 @@
//using EPSON_SOCKET;
//using PLCCommunication;
//using System;
//using System.Collections.Generic;
//using System.Linq;
//using System.Text;
//using System.Threading.Tasks;
//namespace ZWGXPICK_SYS
//{
// internal static class AndroidPLCChannel
// {
// private static List<KeyValuePair<string, string>> pointPapping;
// static AndroidPLCChannel()
// {
// pointPapping = new List<KeyValuePair<string, string>>
// {
// new KeyValuePair<string, string>("RO589", "M5589"),
// new KeyValuePair<string, string>("RO590", "M590"),
// new KeyValuePair<string, string>("RO591", "M591"),
// new KeyValuePair<string, string>("RO592", "M592"),
// new KeyValuePair<string, string>("RO593", "M593"),
// new KeyValuePair<string, string>("RO594", "M594"),
// new KeyValuePair<string, string>("RO595", "M595"),
// new KeyValuePair<string, string>("RO596", "M596"),
// new KeyValuePair<string, string>("RO597", "M597"),
// new KeyValuePair<string, string>("RO598", "M598"),
// new KeyValuePair<string, string>("RO599", "M599"),
// new KeyValuePair<string, string>("RO600", "M600"),
// new KeyValuePair<string, string>("RO601", "M601"),
// new KeyValuePair<string, string>("RO602", "M602"),
// new KeyValuePair<string, string>("RO603", "M603"),
// new KeyValuePair<string, string>("RO604", "M604"),
// new KeyValuePair<string, string>("RO605", "M605"),
// new KeyValuePair<string, string>("RO606", "M606"),
// new KeyValuePair<string, string>("RO607", "M607"),
// new KeyValuePair<string, string>("RO608", "M608"),
// new KeyValuePair<string, string>("RO609", "M609"),
// new KeyValuePair<string, string>("RO610", "M610"),
// new KeyValuePair<string, string>("RO611", "M611"),
// new KeyValuePair<string, string>("RO612", "M612")
// };
// }
// public static List<KeyValuePair<string, string>> PointPapping
// {
// get
// {
// return pointPapping;
// }
// }
// // 接收到数据的响应函数.
// public static void EpsonSocketReceiveData(object sender, EventArgs e)
// {
// EventArgsCmd cmd = (EventArgsCmd)e;
// if (cmd == null) return;
// String str = cmd.Str;
// String[] result = str.Split(',');
// switch (cmd.Cmd)
// {
// case "execute":
// {
// if (str.IndexOf("execute,ro") >= 0)
// {
// var code = result[1].Split('=');
// if (code.Length >= 2)
// {
// SendPLC(code[0], code[1]);
// }
// }
// }
// break;
// default:
// break;
// }
// }
// public static void SendPLC(string point,string value)
// {
// ////获取映射的点位
// //var pointMapper = pointPapping.Where(f => f.Key == point.ToUpper()).FirstOrDefault();
// ////获取值
// //int val = 0;
// //int.TryParse(value, out val);
// //if (!string.IsNullOrEmpty(pointMapper.Value))
// //{
// // var result = PLCCommunicationFactory.Instance.Write(pointMapper.Value, val == 0 ? false : true);
// //}
// }
// }
//}

File diff suppressed because it is too large Load Diff

@ -36,12 +36,12 @@ namespace ZWGXPICK_SYS
private void btnrefresh_Click(object sender, EventArgs e)
{
this.progressBar1.Maximum = 24 + 16;
this.progressBar1.Maximum = 24 + 24;
this.progressBar1.Value = 0;
this.progressBar1.Show();
this.curIndex = 0;
// 发送所有输入查询指令.
string cmd = String.Format("$execute,\"print \"ri{0}=\", sw({0})\"", 0);
string cmd = String.Format("$execute,\"print \"ri{0}=\", sw({0})\"",559);
if (this.epsonSocket1.IsConnection)
this.epsonSocket1.tcp_send(cmd);
@ -98,16 +98,20 @@ namespace ZWGXPICK_SYS
{
if (str.IndexOf("execute,ri") >= 0)
{
System.Diagnostics.Debug.WriteLine( "RI:" + str);
String[] code = result[1].Split('=');
if (code.Length >= 2) updateRIStatus(code[0], code[1]);
if (code.Length >= 2)
{
updateRIStatus(code[0], code[1]);
}
String temp = code[1].Replace("RI", "");
int nIndex = 0; int.TryParse(temp, out nIndex);
//String temp = code[1].Replace("RI", "");
//int nIndex = 0; int.TryParse(temp, out nIndex);
this.curIndex++;
this.progressBar1.Value++;
if (this.curIndex < 24)
{
string send = String.Format("$execute,\"print \"ri{0}=\", sw({0})\"", this.curIndex);
string send = String.Format("$execute,\"print \"ri{0}=\", sw({0})\"", this.curIndex + 559);
if (this.epsonSocket1.IsConnection)
this.epsonSocket1.tcp_send(send);
}
@ -115,7 +119,7 @@ namespace ZWGXPICK_SYS
{
// 发送指令2
this.curIndex = 0;
string send = String.Format("$execute,\"print \"ro{0}=\", oport({0})\"", this.curIndex);
string send = String.Format("$execute,\"print \"ro{0}=\", oport({0})\"", this.curIndex + 589);
if (this.epsonSocket1.IsConnection)
this.epsonSocket1.tcp_send(send);
@ -124,17 +128,21 @@ namespace ZWGXPICK_SYS
}
else if (str.IndexOf("execute,ro") >= 0)
{
System.Diagnostics.Debug.WriteLine("RO:" + str);
String[] code = result[1].Split('=');
if (code.Length >= 2) updateROStatus(code[0], code[1]);
String temp = code[1].Replace("RO", "");
int nIndex = 0; int.TryParse(temp, out nIndex);
if (code.Length >= 2)
{
updateROStatus(code[0], code[1]);
}
//String temp = code[1].Replace("RO", "");
//int nIndex = 0; int.TryParse(temp, out nIndex);
this.curIndex++;
this.progressBar1.Value++;
if (this.curIndex < 16)
if (this.curIndex < 24)
{
// 发送指令2
string send = String.Format("$execute,\"print \"ro{0}=\", oport({0})\"", this.curIndex);
string send = String.Format("$execute,\"print \"ro{0}=\", oport({0})\"", this.curIndex + 589);
if (this.epsonSocket1.IsConnection)
this.epsonSocket1.tcp_send(send);
}

@ -97,11 +97,12 @@
//
this.1.Font = new System.Drawing.Font("微软雅黑", 15F);
this.1.HDADDR = "";
this.1.Location = new System.Drawing.Point(9, 212);
this.1.Location = new System.Drawing.Point(12, 265);
this.1.LockValue = ((uint)(0u));
this.1.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
this.1.Name = "轴1升点动";
this.1.PLC = ((uint)(0u));
this.1.Size = new System.Drawing.Size(169, 45);
this.1.Size = new System.Drawing.Size(225, 56);
this.1.TabIndex = 0;
this.1.Text = "轴1升点动";
this.1.UseVisualStyleBackColor = true;
@ -148,11 +149,12 @@
//
this.1.Font = new System.Drawing.Font("微软雅黑", 15F);
this.1.HDADDR = "";
this.1.Location = new System.Drawing.Point(218, 211);
this.1.Location = new System.Drawing.Point(291, 264);
this.1.LockValue = ((uint)(0u));
this.1.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
this.1.Name = "轴1降点动";
this.1.PLC = ((uint)(0u));
this.1.Size = new System.Drawing.Size(169, 45);
this.1.Size = new System.Drawing.Size(225, 56);
this.1.TabIndex = 1;
this.1.Text = "轴1降点动";
this.1.UseVisualStyleBackColor = true;
@ -199,10 +201,11 @@
//
this.1.Font = new System.Drawing.Font("微软雅黑", 15F);
this.1.HDADDR = "D4";
this.1.Location = new System.Drawing.Point(150, 25);
this.1.Location = new System.Drawing.Point(200, 31);
this.1.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
this.1.Name = "数据显示器1";
this.1.PLC = ((uint)(0u));
this.1.Size = new System.Drawing.Size(136, 34);
this.1.Size = new System.Drawing.Size(180, 42);
this.1.TabIndex = 2;
this.1.Text = "0.0000";
this.1.Value = ((ulong)(0ul));
@ -234,11 +237,12 @@
//
this..Font = new System.Drawing.Font("微软雅黑", 15F);
this..HDADDR = "";
this..Location = new System.Drawing.Point(8, 263);
this..Location = new System.Drawing.Point(11, 329);
this..LockValue = ((uint)(0u));
this..Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
this..Name = "一号库位点位示教";
this..PLC = ((uint)(0u));
this..Size = new System.Drawing.Size(183, 45);
this..Size = new System.Drawing.Size(244, 56);
this..TabIndex = 4;
this..Text = "一号库位点位示教";
this..UseVisualStyleBackColor = true;
@ -285,11 +289,12 @@
//
this..Font = new System.Drawing.Font("微软雅黑", 15F);
this..HDADDR = "";
this..Location = new System.Drawing.Point(428, 263);
this..Location = new System.Drawing.Point(571, 329);
this..LockValue = ((uint)(0u));
this..Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
this..Name = "报警复位";
this..PLC = ((uint)(0u));
this..Size = new System.Drawing.Size(169, 45);
this..Size = new System.Drawing.Size(225, 56);
this..TabIndex = 6;
this..Text = "报警复位";
this..UseVisualStyleBackColor = true;
@ -336,11 +341,12 @@
//
this..Font = new System.Drawing.Font("微软雅黑", 15F);
this..HDADDR = "";
this..Location = new System.Drawing.Point(218, 263);
this..Location = new System.Drawing.Point(291, 329);
this..LockValue = ((uint)(0u));
this..Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
this..Name = "库号清零";
this..PLC = ((uint)(0u));
this..Size = new System.Drawing.Size(169, 45);
this..Size = new System.Drawing.Size(225, 56);
this..TabIndex = 7;
this..Text = "库号清零";
this..UseVisualStyleBackColor = true;
@ -387,11 +393,12 @@
//
this..Font = new System.Drawing.Font("微软雅黑", 15F);
this..HDADDR = "";
this..Location = new System.Drawing.Point(638, 263);
this..Location = new System.Drawing.Point(851, 329);
this..LockValue = ((uint)(0u));
this..Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
this..Name = "手动换舟";
this..PLC = ((uint)(0u));
this..Size = new System.Drawing.Size(169, 45);
this..Size = new System.Drawing.Size(225, 56);
this..TabIndex = 8;
this..Text = "手动换舟";
this..UseVisualStyleBackColor = true;
@ -440,10 +447,11 @@
this.1.Font = new System.Drawing.Font("微软雅黑", 15F);
this.1.HDADDR = "";
this.1.Image = null;
this.1.Location = new System.Drawing.Point(10, 25);
this.1.Location = new System.Drawing.Point(13, 31);
this.1.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
this.1.Name = "标签1";
this.1.PLC = ((uint)(0u));
this.1.Size = new System.Drawing.Size(124, 27);
this.1.Size = new System.Drawing.Size(154, 32);
this.1.TabIndex = 3;
this.1.Text = "轴1当前位置";
this.1.Value = ((ulong)(0ul));
@ -511,10 +519,11 @@
this.2.Font = new System.Drawing.Font("微软雅黑", 15F);
this.2.HDADDR = "";
this.2.Image = null;
this.2.Location = new System.Drawing.Point(290, 25);
this.2.Location = new System.Drawing.Point(387, 31);
this.2.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
this.2.Name = "标签2";
this.2.PLC = ((uint)(0u));
this.2.Size = new System.Drawing.Size(50, 27);
this.2.Size = new System.Drawing.Size(60, 32);
this.2.TabIndex = 9;
this.2.Text = "mm";
this.2.Value = ((ulong)(0ul));
@ -582,10 +591,11 @@
this.3.Font = new System.Drawing.Font("微软雅黑", 15F);
this.3.HDADDR = "";
this.3.Image = null;
this.3.Location = new System.Drawing.Point(734, 25);
this.3.Location = new System.Drawing.Point(979, 31);
this.3.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
this.3.Name = "标签3";
this.3.PLC = ((uint)(0u));
this.3.Size = new System.Drawing.Size(50, 27);
this.3.Size = new System.Drawing.Size(60, 32);
this.3.TabIndex = 12;
this.3.Text = "mm";
this.3.Value = ((ulong)(0ul));
@ -653,10 +663,11 @@
this.4.Font = new System.Drawing.Font("微软雅黑", 15F);
this.4.HDADDR = "";
this.4.Image = null;
this.4.Location = new System.Drawing.Point(471, 25);
this.4.Location = new System.Drawing.Point(628, 31);
this.4.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
this.4.Name = "标签4";
this.4.PLC = ((uint)(0u));
this.4.Size = new System.Drawing.Size(117, 27);
this.4.Size = new System.Drawing.Size(145, 32);
this.4.TabIndex = 11;
this.4.Text = "1#库位位置";
this.4.Value = ((ulong)(0ul));
@ -722,10 +733,11 @@
//
this.2.Font = new System.Drawing.Font("微软雅黑", 15F);
this.2.HDADDR = "D206";
this.2.Location = new System.Drawing.Point(594, 25);
this.2.Location = new System.Drawing.Point(792, 31);
this.2.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
this.2.Name = "数据显示器2";
this.2.PLC = ((uint)(0u));
this.2.Size = new System.Drawing.Size(136, 34);
this.2.Size = new System.Drawing.Size(180, 42);
this.2.TabIndex = 10;
this.2.Text = "0.0000";
this.2.Value = ((ulong)(0ul));
@ -759,10 +771,11 @@
this.5.Font = new System.Drawing.Font("微软雅黑", 15F);
this.5.HDADDR = "";
this.5.Image = null;
this.5.Location = new System.Drawing.Point(734, 84);
this.5.Location = new System.Drawing.Point(979, 105);
this.5.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
this.5.Name = "标签5";
this.5.PLC = ((uint)(0u));
this.5.Size = new System.Drawing.Size(68, 27);
this.5.Size = new System.Drawing.Size(83, 32);
this.5.TabIndex = 15;
this.5.Text = "mm/s";
this.5.Value = ((ulong)(0ul));
@ -830,10 +843,11 @@
this.6.Font = new System.Drawing.Font("微软雅黑", 15F);
this.6.HDADDR = "";
this.6.Image = null;
this.6.Location = new System.Drawing.Point(471, 84);
this.6.Location = new System.Drawing.Point(628, 105);
this.6.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
this.6.Name = "标签6";
this.6.PLC = ((uint)(0u));
this.6.Size = new System.Drawing.Size(124, 27);
this.6.Size = new System.Drawing.Size(154, 32);
this.6.TabIndex = 14;
this.6.Text = "轴1运行速度";
this.6.Value = ((ulong)(0ul));
@ -899,10 +913,11 @@
//
this.3.Font = new System.Drawing.Font("微软雅黑", 15F);
this.3.HDADDR = "D200";
this.3.Location = new System.Drawing.Point(594, 84);
this.3.Location = new System.Drawing.Point(792, 105);
this.3.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
this.3.Name = "数据显示器3";
this.3.PLC = ((uint)(0u));
this.3.Size = new System.Drawing.Size(136, 34);
this.3.Size = new System.Drawing.Size(180, 42);
this.3.TabIndex = 13;
this.3.Text = "0.0000";
this.3.Value = ((ulong)(0ul));
@ -936,10 +951,11 @@
this.8.Font = new System.Drawing.Font("微软雅黑", 15F);
this.8.HDADDR = "";
this.8.Image = null;
this.8.Location = new System.Drawing.Point(10, 84);
this.8.Location = new System.Drawing.Point(13, 105);
this.8.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
this.8.Name = "标签8";
this.8.PLC = ((uint)(0u));
this.8.Size = new System.Drawing.Size(92, 27);
this.8.Size = new System.Drawing.Size(114, 32);
this.8.TabIndex = 17;
this.8.Text = "当前库号";
this.8.Value = ((ulong)(0ul));
@ -1005,10 +1021,11 @@
//
this.4.Font = new System.Drawing.Font("微软雅黑", 15F);
this.4.HDADDR = "D208";
this.4.Location = new System.Drawing.Point(150, 84);
this.4.Location = new System.Drawing.Point(200, 105);
this.4.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
this.4.Name = "数据显示器4";
this.4.PLC = ((uint)(0u));
this.4.Size = new System.Drawing.Size(136, 34);
this.4.Size = new System.Drawing.Size(180, 42);
this.4.TabIndex = 16;
this.4.Text = "0";
this.4.Value = ((ulong)(0ul));
@ -1040,11 +1057,12 @@
//
this.1.Font = new System.Drawing.Font("微软雅黑", 15F);
this.1.HDADDR = "";
this.1.Location = new System.Drawing.Point(427, 212);
this.1.Location = new System.Drawing.Point(569, 265);
this.1.LockValue = ((uint)(0u));
this.1.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
this.1.Name = "一键到达1号库位";
this.1.PLC = ((uint)(0u));
this.1.Size = new System.Drawing.Size(181, 45);
this.1.Size = new System.Drawing.Size(241, 56);
this.1.TabIndex = 18;
this.1.Text = "一键到达一号库位";
this.1.UseVisualStyleBackColor = true;
@ -1093,10 +1111,11 @@
this.9.Font = new System.Drawing.Font("微软雅黑", 15F);
this.9.HDADDR = "";
this.9.Image = null;
this.9.Location = new System.Drawing.Point(10, 143);
this.9.Location = new System.Drawing.Point(13, 179);
this.9.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
this.9.Name = "标签9";
this.9.PLC = ((uint)(0u));
this.9.Size = new System.Drawing.Size(92, 27);
this.9.Size = new System.Drawing.Size(114, 32);
this.9.TabIndex = 20;
this.9.Text = "库位间隔";
this.9.Value = ((ulong)(0ul));
@ -1162,10 +1181,11 @@
//
this.5.Font = new System.Drawing.Font("微软雅黑", 15F);
this.5.HDADDR = "D210";
this.5.Location = new System.Drawing.Point(150, 143);
this.5.Location = new System.Drawing.Point(200, 179);
this.5.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
this.5.Name = "数据显示器5";
this.5.PLC = ((uint)(0u));
this.5.Size = new System.Drawing.Size(136, 34);
this.5.Size = new System.Drawing.Size(180, 42);
this.5.TabIndex = 21;
this.5.Text = "0.0000";
this.5.Value = ((ulong)(0ul));
@ -1199,10 +1219,11 @@
this.7.Font = new System.Drawing.Font("微软雅黑", 15F);
this.7.HDADDR = "";
this.7.Image = null;
this.7.Location = new System.Drawing.Point(290, 143);
this.7.Location = new System.Drawing.Point(387, 179);
this.7.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
this.7.Name = "标签7";
this.7.PLC = ((uint)(0u));
this.7.Size = new System.Drawing.Size(50, 27);
this.7.Size = new System.Drawing.Size(60, 32);
this.7.TabIndex = 22;
this.7.Text = "mm";
this.7.Value = ((ulong)(0ul));
@ -1268,11 +1289,12 @@
//
this..Font = new System.Drawing.Font("微软雅黑", 15F);
this..HDADDR = "";
this..Location = new System.Drawing.Point(636, 212);
this..Location = new System.Drawing.Point(848, 265);
this..LockValue = ((uint)(0u));
this..Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
this..Name = "气缸复位";
this..PLC = ((uint)(0u));
this..Size = new System.Drawing.Size(169, 45);
this..Size = new System.Drawing.Size(225, 56);
this..TabIndex = 23;
this..Text = "气缸复位";
this..UseVisualStyleBackColor = true;
@ -1317,10 +1339,10 @@
//
// Dash_Change_Form
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(192)))), ((int)(((byte)(192)))), ((int)(((byte)(255)))));
this.ClientSize = new System.Drawing.Size(825, 320);
this.ClientSize = new System.Drawing.Size(1100, 400);
this.Controls.Add(this.);
this.Controls.Add(this.7);
this.Controls.Add(this.5);
@ -1343,6 +1365,7 @@
this.Controls.Add(this.1);
this.Controls.Add(this.1);
this.Controls.Add(this.1);
this.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
this.Name = "Dash_Change_Form";
this.Text = "换舟参数";
this.Load += new System.EventHandler(this.Dash_ChangeParam_Form_Load);

@ -38,8 +38,8 @@
this.btnYsub = new System.Windows.Forms.Button();
this.btnYplus = new System.Windows.Forms.Button();
this.panel3 = new System.Windows.Forms.Panel();
this.RO6 = new System.Windows.Forms.CheckBox();
this.RO5 = new System.Windows.Forms.CheckBox();
this.RO606 = new System.Windows.Forms.CheckBox();
this.RO605 = new System.Windows.Forms.CheckBox();
this.btnMotoOff = new System.Windows.Forms.Button();
this.btnMotoOn = new System.Windows.Forms.Button();
this.btnSetSpeed = new System.Windows.Forms.Button();
@ -215,8 +215,8 @@
// panel3
//
this.panel3.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.panel3.Controls.Add(this.RO6);
this.panel3.Controls.Add(this.RO5);
this.panel3.Controls.Add(this.RO606);
this.panel3.Controls.Add(this.RO605);
this.panel3.Controls.Add(this.btnMotoOff);
this.panel3.Controls.Add(this.btnMotoOn);
this.panel3.Controls.Add(this.btnSetSpeed);
@ -225,35 +225,35 @@
this.panel3.Size = new System.Drawing.Size(199, 308);
this.panel3.TabIndex = 233;
//
// RO6
//
this.RO6.Appearance = System.Windows.Forms.Appearance.Button;
this.RO6.FlatAppearance.CheckedBackColor = System.Drawing.Color.Red;
this.RO6.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.RO6.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.RO6.Location = new System.Drawing.Point(3, 228);
this.RO6.Name = "RO6";
this.RO6.Size = new System.Drawing.Size(191, 52);
this.RO6.TabIndex = 240;
this.RO6.Text = "RO6气爪";
this.RO6.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.RO6.UseVisualStyleBackColor = true;
this.RO6.Click += new System.EventHandler(this.RO0_Click);
//
// RO5
//
this.RO5.Appearance = System.Windows.Forms.Appearance.Button;
this.RO5.FlatAppearance.CheckedBackColor = System.Drawing.Color.Red;
this.RO5.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.RO5.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.RO5.Location = new System.Drawing.Point(3, 171);
this.RO5.Name = "RO5";
this.RO5.Size = new System.Drawing.Size(191, 52);
this.RO5.TabIndex = 241;
this.RO5.Text = "RO5真空";
this.RO5.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.RO5.UseVisualStyleBackColor = true;
this.RO5.Click += new System.EventHandler(this.RO0_Click);
// RO606
//
this.RO606.Appearance = System.Windows.Forms.Appearance.Button;
this.RO606.FlatAppearance.CheckedBackColor = System.Drawing.Color.Red;
this.RO606.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.RO606.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.RO606.Location = new System.Drawing.Point(3, 228);
this.RO606.Name = "RO606";
this.RO606.Size = new System.Drawing.Size(191, 52);
this.RO606.TabIndex = 240;
this.RO606.Text = "RO606气爪";
this.RO606.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.RO606.UseVisualStyleBackColor = true;
this.RO606.Click += new System.EventHandler(this.RO0_Click);
//
// RO605
//
this.RO605.Appearance = System.Windows.Forms.Appearance.Button;
this.RO605.FlatAppearance.CheckedBackColor = System.Drawing.Color.Red;
this.RO605.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.RO605.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.RO605.Location = new System.Drawing.Point(3, 171);
this.RO605.Name = "RO605";
this.RO605.Size = new System.Drawing.Size(191, 52);
this.RO605.TabIndex = 241;
this.RO605.Text = "RO605真空";
this.RO605.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.RO605.UseVisualStyleBackColor = true;
this.RO605.Click += new System.EventHandler(this.RO0_Click);
//
// btnMotoOff
//
@ -714,7 +714,7 @@
private System.Windows.Forms.Button btnUplus;
private System.Windows.Forms.Button btnSetSpeed;
private System.Windows.Forms.Button btnRealtimePoint;
private System.Windows.Forms.CheckBox RO6;
private System.Windows.Forms.CheckBox RO5;
private System.Windows.Forms.CheckBox RO606;
private System.Windows.Forms.CheckBox RO605;
}
}

@ -95,7 +95,7 @@ namespace ZWGXPICK_SYS
X = this.Width;
Y = this.Height;
String[] cnNames = { "等待位", "取件低位", "取件高位", "去毛刺低位", "去毛刺高位", "天平低位", "天平高位", "废品位", "取样低位", "取样高位", "摆件低件", "摆件高位", "安全位", "", "", "", "", "", "", "", "", "", "", "", "", "", "" };
String[] cnNames = { "等待位", "取件低位", "取件高位", "去毛刺低位", "去毛刺高位", "天平放件点", "天平高位", "废品位", "取样低位", "取样高位", "摆件低件", "摆件高位", "安全位", "天平取件点", "", "", "", "", "", "", "", "", "", "", "", "", "" };
// initialize the combo box item.
for (int i = 0; i <= 20; i++)
{

@ -61,6 +61,7 @@
<Compile Include="Alarm_Log_Form.Designer.cs">
<DependentUpon>Alarm_Log_Form.cs</DependentUpon>
</Compile>
<Compile Include="AndroidPLCChannel.cs" />
<Compile Include="Dash_Change_Form.cs">
<SubType>Form</SubType>
</Compile>
@ -139,6 +140,7 @@
</EmbeddedResource>
<EmbeddedResource Include="frmMain.resx">
<DependentUpon>frmMain.cs</DependentUpon>
<SubType>Designer</SubType>
</EmbeddedResource>
<EmbeddedResource Include="PLC_IO_Form.resx">
<DependentUpon>PLC_IO_Form.cs</DependentUpon>
@ -189,6 +191,10 @@
<Project>{50011230-779e-484e-9fed-1cf3086fa14e}</Project>
<Name>EPSON_SOCKET</Name>
</ProjectReference>
<ProjectReference Include="..\PLCCommunication\PLCCommunication.csproj">
<Project>{0A7F9893-61CC-4188-8285-1E6C0B916B1A}</Project>
<Name>PLCCommunication</Name>
</ProjectReference>
<ProjectReference Include="..\ZWGXPICK_SYS.DAL\ZWGXPICK_SYS.DAL.csproj">
<Project>{7357684A-0246-4A72-8189-4724BDFFA5D1}</Project>
<Name>ZWGXPICK_SYS.DAL</Name>

File diff suppressed because it is too large Load Diff

@ -1,6 +1,8 @@
using EPSON_SOCKET;
using Maticsoft.DBUtility;
using PCHMI;
using PLCCommunication;
using System;
using System.Collections.Generic;
using System.ComponentModel;
@ -88,6 +90,7 @@ namespace ZWGXPICK_SYS
this.mlbMatrix[row, col] = new GraphicsPath();
}
}
}
private void setTag(Control cons)
@ -727,6 +730,8 @@ namespace ZWGXPICK_SYS
{
WriteIniString("global", "txt_plan_placed_num", this.txt_plan_placed_num.Text);
WriteIniString("global", "txt_run_speed", this.txt_run_speed.Text);
PLCCommunicationFactory.Instance.ColseConnection();
}
// 数据端口有新的数据进来.
@ -1857,6 +1862,11 @@ namespace ZWGXPICK_SYS
PCHMI.TIRGGER m211 = new PCHMI.TIRGGER(0, "M211", "上升沿");
//外接报警复位按钮
PCHMI.TIRGGER m212 = new PCHMI.TIRGGER(0, "M212", "上升沿");
//外接紧急停止按钮
PCHMI.TIRGGER m218 = new PCHMI.TIRGGER(0, "M218", "上升沿");
//外接停止按钮
PCHMI.TIRGGER m219 = new PCHMI.TIRGGER(0, "M219", "上升沿");
private void Timer_PLCTick_Tick(object sender, EventArgs e)
{
for (int i = 0; i < lstTrigger.Count; i++)
@ -1899,6 +1909,26 @@ namespace ZWGXPICK_SYS
this.epsonSocket1.tcp_send(cmd);
}
}
//外接紧急停止按钮
if (m218.Enable)
{
if (this.epsonSocket1.IsConnection)
{
String cmd = "$stop";
this.epsonSocket1.tcp_send(cmd);
}
}
//外接停止按钮
if (m219.Enable)
{
String cmd = "$rest;";
if (this.epsonSocket2.IsConnection)
{
// 停止命令发送到5002端口.
this.epsonSocket2.tcp_send(cmd);
}
}
}
// 重置下一摆放位置参数.

@ -117,9 +117,6 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="PLC_Communication.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<metadata name="colID.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
@ -141,6 +138,9 @@
<metadata name="Timer_PLCTick.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>521, 17</value>
</metadata>
<metadata name="PLC_Communication.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>60</value>
</metadata>

Loading…
Cancel
Save