2026-03-30 17:09:29 +09:00

131 lines
4.4 KiB
C#

using Aurora.Api;
using Aurora.Api.Devices;
using PropertyTools.DataAnnotations;
using System.Collections.Generic;
using System.Linq;
namespace AuroraPLC
{
// Memory Map 파일 방식
public enum PLCMMapFileType
{
CSV,
EXCEL,
}
public class PLCMelsecNetConnConfig : IConnConfig
{
[Category("MELSECNet")]
// MelsecNet: station No: own : 255 or other
public short StationNumber { get; set; } = 255; // 255 : Own station
public short ChannelNumber { get; set; } = 151; // 151 : CC-Link IE Channel 1
[Category("Common")]
// LPC 장비: CC-Link IE Control, B/W 각각 2048 points 조건: 약 350 [Hz] 이상의 통신속도 확인함
[DisplayName("Update rate [ms]")]
public int UpdateRateMS { get; set; } = 10; // 100 [Hz]
//[Category("MappingFileDirctoryPath")]
//[DirectoryPath]
//public string PLCDirectoryPath { get; set; } = "";
}
public class PLCMXComponentConnConfig : IConnConfig
{
[Category("MXComponent")]
// MxComponent: ActUtlType64Lib: logical station No : 1
public short StationNumber { get; set; } = 1; // Logical statoin No. (By PC Tool: Communication Setting Utility)
[Category("Common")]
[DisplayName("Update rate [ms]")]
public int UpdateRateMS { get; set; } = 50; // CPU 모듈의 이더넷 사용 시, MXComponent 로 약 20 [Hz] 확인 (이더넷 확장모듈: 약 3 [Hz])
//[Category("MappingFileDirctoryPath")]
//[DirectoryPath]
//public string PLCDirectoryPath { get; set; } = "";
}
public class PLCMelsecNetConfig : IDeviceConfig
{
public IConnConfig ConnConfig { get; set; }
public PLCMelsecNetConfig()
{
ConnConfig = new PLCMelsecNetConnConfig();
}
public static PLCMelsecNetConfig GetDefaultConfig()
{
return new PLCMelsecNetConfig();
}
}
public class PLCMxComponentConfig : IDeviceConfig
{
public IConnConfig ConnConfig { get; set; }
public PLCMxComponentConfig()
{
ConnConfig = new PLCMXComponentConnConfig();
}
public static PLCMxComponentConfig GetDefaultConfig()
{
return new PLCMxComponentConfig();
}
}
public class AddrCommentList
{
public string Comment_EN;
public string Comment_KR;
//public string Comment_CN;
public AddrCommentList(string commentEng, string commentKor)
{
Comment_EN = commentEng;
Comment_KR = commentKor;
}
}
public abstract partial class PLCBase
{
#region Memory Map Config
public IList<(int address, AddrCommentList description)> BitInputs { get; set; }
= new List<(int, AddrCommentList)>();
public IList<(int address, AddrCommentList description)> BitOutputs { get; set; }
= new List<(int, AddrCommentList)>();
public IList<(int address, AddrCommentList description)> MBitInputs { get; set; }
= new List<(int, AddrCommentList)>();
public IList<(int address, AddrCommentList description)> MBitOutputs { get; set; }
= new List<(int, AddrCommentList)>();
public IList<(int address, AddrCommentList description)> WordInputs { get; set; }
= new List<(int, AddrCommentList)>();
public IList<(int address, AddrCommentList description)> WordOutputs { get; set; }
= new List<(int, AddrCommentList)>();
public IList<(int address, AddrCommentList description)> DWordInputs { get; set; }
= new List<(int, AddrCommentList)>();
public IList<(int address, AddrCommentList description)> DWordOutputs { get; set; }
= new List<(int, AddrCommentList)>();
/// <summary>
/// PLC 통신 data 의 개수 카운팅 : 마지막 메모리 주소 - 시작 메모리 주소 + 1 = 총 개수
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="io"></param>
/// <returns></returns>
public static int Length<T>(T io)
where T : IList<(int address, AddrCommentList description)>
=> io.Count == 0 ? 0 :
io.OrderBy(x => x.address).Last().address - io.OrderBy(x => x.address).First().address + 1;
#endregion
}
}