You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

178 lines
5.8 KiB
C#

using HighWayIot.Plc.PlcEntity;
using HslCommunication;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HighWayIot.Plc.PlcHelper
{
/// <summary>
/// 中专信号点位读写
/// </summary>
public class TransferSingal
{
/// <summary>
/// 工位贴合开始信号写入
/// </summary>
/// <param name="stationNo"></param>
/// <returns></returns>
public bool WriteStationStickSingal(int stationNo)
{
bool result = false;
switch (stationNo)
{
case 1:
result = PlcConnect.MelsecInstance2.Write("B201", true).IsSuccess;
break;
case 2:
result = PlcConnect.MelsecInstance2.Write("B202", true).IsSuccess;
break;
case 3:
result = PlcConnect.MelsecInstance2.Write("B203", true).IsSuccess;
break;
case 4:
result = PlcConnect.MelsecInstance2.Write("B205", true).IsSuccess;
break;
case 5:
result = PlcConnect.MelsecInstance2.Write("B207", true).IsSuccess;
break;
default:
break;
}
return result;
}
/// <summary>
/// 工位贴合计数开始信号写入
/// </summary>
/// <param name="stationNo"></param>
/// <returns></returns>
public bool WriteStationStickCountSingal(int stationNo)
{
bool result = false;
switch (stationNo)
{
case 1:
result = PlcConnect.MelsecInstance2.Write("B211", true).IsSuccess;
break;
case 2:
result = PlcConnect.MelsecInstance2.Write("B212", true).IsSuccess;
break;
case 3:
result = PlcConnect.MelsecInstance2.Write("B213", true).IsSuccess;
break;
case 4:
result = PlcConnect.MelsecInstance2.Write("B215", true).IsSuccess;
break;
case 5:
result = PlcConnect.MelsecInstance2.Write("B217", true).IsSuccess;
break;
default:
break;
}
return result;
}
/// <summary>
/// 读取小车就绪信号(开始贴合) 鼓到位信号读取(开始横裁信号)和贴合计数信号读取(横裁结束信号)
/// </summary>
/// <returns>第一个Byte数组是第二个Byte数组是开始横裁信号第三个是结束横裁信号</returns>
public bool[][] ReadDrumReadyAndCountReadySignal()
{
OperateResult<byte[]> operateResult = PlcConnect.MelsecInstance2.Read("B980", 3);
if (!operateResult.IsSuccess)
{
return null;
}
byte[] data = operateResult.Content;
bool[][] result = new bool[3][];
result[0] = new bool[9];
result[1] = new bool[8];
result[2] = new bool[8];
//12345工位小车就绪
for (int i = 0; i < 6; i++)
{
result[0][i] = data[0].GetBoolByIndex(i);
}
//345称重工位就绪
for (int i = 0; i < 3; i++)
{
result[0][i + 6] = data[1].GetBoolByIndex(i);
}
//开始和结束横裁的信号
for (int i = 0; i < 8; i++)
{
result[1][i + 1] = data[2].GetBoolByIndex(i);
result[2][i + 1] = data[4].GetBoolByIndex(i);
}
return result;
}
/// <summary>
/// 监控中转信号
/// </summary>
/// <returns></returns>
public bool[][] ReadMonitorSingal()
{
OperateResult<byte[]> operateResult = PlcConnect.MelsecInstance2.Read("B9B1", 5);
if (!operateResult.IsSuccess)
{
return null;
}
byte[] data = operateResult.Content;
bool[][] result = new bool[5][];
for (int i = 0; i < 5; i++)
{
result[i] = new bool[5];
for (int j = 0; j < 5; j++)
{
result[i][j] = data[i * 2].GetBoolByIndex(j);
}
}
return result;
}
/// <summary>
/// 监控工位配方信息
/// </summary>
/// <returns></returns>
public List<StationRecipeEntity> ReadStationRecipeInfo()
{
OperateResult<byte[]> operateResult = PlcConnect.MelsecInstance2.Read("W950", 80);
if (!operateResult.IsSuccess)
{
return null;
}
byte[] data = operateResult.Content;
List<StationRecipeEntity> resultList = new List<StationRecipeEntity>();
for (int i = 0; i < 5; i++)
{
resultList.Add(new StationRecipeEntity()
{
StationRecipeDescripe = PlcConnect.MelsecInstance2.ByteTransform.TransString(data, (i * 16) + 0, 20, Encoding.ASCII),
StationRecipeNo = PlcConnect.MelsecInstance2.ByteTransform.TransInt16(data, (i * 16) + 20),
StationVehicleNo = PlcConnect.MelsecInstance2.ByteTransform.TransInt16(data, (i * 16) + 22),
StationTireWeight = PlcConnect.MelsecInstance2.ByteTransform.TransSingle(data, (i * 16) + 24),
});
}
return resultList;
}
}
}