Compare commits

...

11 Commits

Author SHA1 Message Date
backuppc
82bca1c90b .. 2025-12-10 17:30:25 +09:00
backuppc
4f360f33a7 agv 정보 전송 수정 2025-11-14 15:03:41 +09:00
backuppc
6c8ed6d2f2 프로토콜 문서 업데이트 - AGV Status 명령어 정의 수정
- LastTag 필드 크기 수정: 4바이트 → 6바이트 (실제 구현 반영)
- CurrentPath 필드 제거 (실제 구현에 없음)
- 총 13바이트 데이터 구조 명시

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-12 17:36:12 +09:00
JiWoong 이지웅 Lee
ac8077d06b . 2025-11-10 15:22:18 +09:00
JiWoong 이지웅 Lee
986412338f (jwlee) DeviceAlias Enum 추가함. 2025-11-10 15:08:30 +09:00
backuppc
070aa848c9 remove readme.md 2025-11-05 14:33:28 +09:00
backuppc
1eb59a0127 .. 2025-11-05 14:28:32 +09:00
backuppc
77a9d40662 .net standard 2.0 -> net fx 4.0 class 2025-07-03 11:03:07 +09:00
chi
cc7b742a61 .. 2025-06-20 16:38:14 +09:00
chi
f127a7b5b2 Merge branch 'master' of https://gitlab.com/amk4/enigprotocol 2025-05-27 16:35:52 +09:00
Arin(asus)
0936d075b9 .. 2025-05-25 23:23:00 +09:00
11 changed files with 438 additions and 280 deletions

View File

@@ -1,14 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk" ToolsVersion="15.0">
<PropertyGroup> <PropertyGroup>
<TargetFramework>net6.0</TargetFramework> <TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<IsPackable>false</IsPackable> <IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject> <IsTestProject>true</IsTestProject>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileUpgradeFlags>
</FileUpgradeFlags>
<UpgradeBackupLocation>
</UpgradeBackupLocation>
<OldToolsVersion>2.0</OldToolsVersion>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.13.0" /> <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.13.0" />
<PackageReference Include="xunit" Version="2.9.3" /> <PackageReference Include="xunit" Version="2.9.3" />
@@ -21,13 +24,10 @@
<PrivateAssets>all</PrivateAssets> <PrivateAssets>all</PrivateAssets>
</PackageReference> </PackageReference>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\enigprotocol\enigprotocol.csproj" /> <ProjectReference Include="..\enigprotocol\enigprotocol.csproj" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Using Include="Xunit" /> <Using Include="Xunit" />
</ItemGroup> </ItemGroup>
</Project>
</Project>

View File

@@ -1,30 +1,26 @@
 
Microsoft Visual Studio Solution File, Format Version 12.00 Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17 # Visual Studio Express 15 for Windows Desktop
VisualStudioVersion = 17.9.34714.143 VisualStudioVersion = 15.0.28307.1000
MinimumVisualStudioVersion = 10.0.40219.1 MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ENIGProtocol", "enigprotocol\ENIGProtocol.csproj", "{B6FCA1B0-C9D1-4159-AB86-25E4BC598C01}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SampleProject", "sample\SampleProject.csproj", "{FAB31C8A-7DCF-4152-8A82-76F3C10BABA4}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ENIGProtocol.Tests", "ENIGProtocol.Tests\ENIGProtocol.Tests.csproj", "{3A677629-1F08-49B2-BC75-58282E439FD4}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "솔루션 항목", "솔루션 항목", "{0A11874A-E5C6-4170-9787-1FFF7AF0D289}" Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "솔루션 항목", "솔루션 항목", "{0A11874A-E5C6-4170-9787-1FFF7AF0D289}"
ProjectSection(SolutionItems) = preProject ProjectSection(SolutionItems) = preProject
.gitignore = .gitignore .gitignore = .gitignore
ReadMe.MD = ReadMe.MD ReadMe.MD = ReadMe.MD
EndProjectSection EndProjectSection
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SampleProject", "sample\SampleProject.csproj", "{FAB31C8A-7DCF-4152-8A82-76F3C10BABA4}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ENIGProtocol.Tests", "ENIGProtocol.Tests\ENIGProtocol.Tests.csproj", "{3A677629-1F08-49B2-BC75-58282E439FD4}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ENIGProtocol", "enigprotocol\ENIGProtocol.csproj", "{499D8912-4B96-41E5-A70D-CFE797883D65}"
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU Release|Any CPU = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution GlobalSection(ProjectConfigurationPlatforms) = postSolution
{B6FCA1B0-C9D1-4159-AB86-25E4BC598C01}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B6FCA1B0-C9D1-4159-AB86-25E4BC598C01}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B6FCA1B0-C9D1-4159-AB86-25E4BC598C01}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B6FCA1B0-C9D1-4159-AB86-25E4BC598C01}.Release|Any CPU.Build.0 = Release|Any CPU
{FAB31C8A-7DCF-4152-8A82-76F3C10BABA4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {FAB31C8A-7DCF-4152-8A82-76F3C10BABA4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FAB31C8A-7DCF-4152-8A82-76F3C10BABA4}.Debug|Any CPU.Build.0 = Debug|Any CPU {FAB31C8A-7DCF-4152-8A82-76F3C10BABA4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FAB31C8A-7DCF-4152-8A82-76F3C10BABA4}.Release|Any CPU.ActiveCfg = Release|Any CPU {FAB31C8A-7DCF-4152-8A82-76F3C10BABA4}.Release|Any CPU.ActiveCfg = Release|Any CPU
@@ -33,6 +29,10 @@ Global
{3A677629-1F08-49B2-BC75-58282E439FD4}.Debug|Any CPU.Build.0 = Debug|Any CPU {3A677629-1F08-49B2-BC75-58282E439FD4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3A677629-1F08-49B2-BC75-58282E439FD4}.Release|Any CPU.ActiveCfg = Release|Any CPU {3A677629-1F08-49B2-BC75-58282E439FD4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3A677629-1F08-49B2-BC75-58282E439FD4}.Release|Any CPU.Build.0 = Release|Any CPU {3A677629-1F08-49B2-BC75-58282E439FD4}.Release|Any CPU.Build.0 = Release|Any CPU
{499D8912-4B96-41E5-A70D-CFE797883D65}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{499D8912-4B96-41E5-A70D-CFE797883D65}.Debug|Any CPU.Build.0 = Debug|Any CPU
{499D8912-4B96-41E5-A70D-CFE797883D65}.Release|Any CPU.ActiveCfg = Release|Any CPU
{499D8912-4B96-41E5-A70D-CFE797883D65}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE

View File

@@ -41,23 +41,41 @@ This README provides a comprehensive overview of the `ENIGProtocol` library, mak
public enum DeviceType : byte public enum DeviceType : byte
{ {
ACS = 0, ACS = 0,
AGV1 = 10, AGV1 = 10+1,
AGV2 = 11, AGV2 = 10+2,
BUFFER1 = 20, BUFFER1 = 20+1,
BUFFER2 = 21, BUFFER2 = 20+2,
BUFFER3 = 22, BUFFER3 = 20+3,
BUFFER4 = 23, BUFFER4 = 20+4,
BUFFER5 = 24, BUFFER5 = 20+5,
DOOR = 30, DOOR = 30,
} }
``` ```
public enum DeviceAlias : byte
{
B1 = 20 + 1, //BUFFER1 ~ 5
B2 = 20 + 2,
B3 = 20 + 3,
B4 = 20 + 4,
B5 = 20 + 5,
C1 = 40 + 1, //충전소 1
C2 = 40 + 2, //충전소 2
C3 = 40 + 3, //충전소 3
C4 = 40 + 4, //충전소 4
E1 = 90 + 1, //장비1 (SSOTRON Loader)
E2 = 90 + 2, //장비2 (TOPS ENIG)
E3 = 90 + 3, //장비3 (SSOTRON DIVERTER)
}
//11번 AGV야! BUFFER1로 이동해라!
//0x02 0x03 0x0B 0x6B 0x42 0x31 {CRC} 0x03
### 기본 패킷 구조 ### 기본 패킷 구조
``` ```
[STX][LEN][ID][CMD][DATA][CRC16][ETX] [STX][LEN][ID][CMD][DATA][CRC16][ETX]
``` ```
- **STX (Start of Text)**: 0x02 - **STX (Start of Text)**: 0x02
- **ID (Client ID)**: 데이터 길이 (1바이트) : 디바이스식별코드(=DeviceType)
- **LEN (Length)**: 데이터 길이 (1바이트) = {CMD+DATA} - **LEN (Length)**: 데이터 길이 (1바이트) = {CMD+DATA}
- **ID (Client ID)**: 데이터 길이 (1바이트) : 디바이스식별코드(=DeviceType)
- **CMD (Command)**: 명령어 코드 (1바이트) - **CMD (Command)**: 명령어 코드 (1바이트)
- **DATA**: 명령어에 따른 데이터 (가변 길이) - **DATA**: 명령어에 따른 데이터 (가변 길이)
- **CRC16**: 데이터 무결성 검사 (2바이트) - **CRC16**: 데이터 무결성 검사 (2바이트)
@@ -81,24 +99,42 @@ public enum DeviceType : byte
3. **AGV** 3. **AGV**
- H -> E | Move : cmd(100) : 대상태그까지 이동(자동이동) - H -> E | Move : cmd(100) : 대상태그까지 이동(자동이동)
- Target[1] = {DeviceType} - Target[1] = {DeviceType}
- TagID[4] = 0000 - TagID[4] = "0000"
- H -> E | Stop : cmd(101) : 멈춤 - H -> E | Stop : cmd(101) : 멈춤
- H -> E | Reset : cmd(102) : 오류 소거 - H -> E | Reset : cmd(102) : 오류 소거
- H -> E | Charge On: cmd(103) : 충전실행(충전기 이동 후 자동 충전 진행)
- H -> E | SetCurrent : cmd(103) : 현재위치설정
- Target[1] = {DeviceType} - Target[1] = {DeviceType}
- Action[1] : 0=Charge Off, 1=Charge On - TagID[4] = "0000"
- H -> E | MoveManual : cmd(104) : 메뉴얼이동 - H -> E | MoveManual : cmd(104) : 메뉴얼이동
- Target[1] = {DeviceType} - Target[1] = {DeviceType}
- Direction[1] : 0=Backward, 1=Forward, 2=TurnLeft, 3=TurnRight - Direction[1] : 0=Backward, 1=Forward, 2=TurnLeft, 3=TurnRight
- Speed[1] : 0=Slow, 1=Normal, 2=Fast - Speed[1] : 0=Slow, 1=Normal, 2=Fast
- Runtime[1] : 0 second
- H -> E | MarkStop : cmd(105) : 마크센서스톱 - H -> E | MarkStop : cmd(105) : 마크센서스톱
- Target[1] = {DeviceType} - Target[1] = {DeviceType}
- H -> E | Lift Control : cmd(106) : 리프트제어 - H -> E | Lift Control : cmd(106) : 리프트제어
- Target[1] = {DeviceType} - Target[1] = {DeviceType}
- Action[1] : 0=STOP, 1=UP, 2=DOWN - Action[1] : 0=STOP, 1=UP, 2=DOWN
- H -> E | Move : cmd(107) : 대상별칭까지 이동(자동이동)
- Target[1] = {DeviceType}
- AliasName[n] = ".....
- H -> E | MoveAuto : cmd(108) : 자동이동
- Target[1] = {DeviceType}
- MotDirection[1] : 0=Backward, 1=Forward
- MagnetDirection[1] : 0=Straight,1=Left, 2=Right
- Speed[1] : 0=Slow, 1=Normal, 2=Fast
- H -> E | Charge On: cmd(109) : 충전실행(충전기 이동 후 자동 충전 진행)
- Target[1] = {DeviceType}
- Action[1] : 0=Charge Off, 1=Charge On
- E -> H | Move Complete : cmd(1) : 목적지이동완료 후 전송 - E -> H | Move Complete : cmd(1) : 목적지이동완료 후 전송
- TagID[4] : "0000" - TagID[4] : "0000"
- E -> H | TagID Received : cmd(2) : 태그값 인식시 전송 - E -> H | TagID Received : cmd(2) : 태그값 인식시 전송

View File

@@ -4,14 +4,41 @@ using System.Text;
namespace ENIGProtocol namespace ENIGProtocol
{ {
public enum AGVCommands /// <summary>
/// host -> eq
/// </summary>
public enum AGVCommandHE : byte
{ {
Goto = 100, Goto = 100,
Stop = 101, Stop = 101,
Reset, Reset = 102,
SetCurrent, SetCurrent = 103,
Manual, Manual = 104,
MarkStop, MarkStop = 105,
LiftControl LiftControl = 106,
GotoAlias = 107,
AutoMove=108,
ChargeControl=109,
}
/// <summary>
/// eq -> host
/// </summary>
public enum AGVCommandEH : byte
{
Error = 1,
Arrived = 2,
ReadRFID = 3,
Status = 9,
}
public enum AGVErrorCode : byte
{
PredictFix,
TurnTimeout,
TurnError,
EmptyNode,
Goto,
ManualMode,
} }
} }

View File

@@ -1,55 +1,55 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
namespace ENIG namespace ENIG
{ {
// 장비 타입 정의 // 장비 타입 정의
public enum DeviceType public enum DeviceType
{ {
ACS = 0, ACS = 0,
AGV1 = 10, AGV1 = 10,
AGV2 = 11, AGV2 = 11,
BUFFER1 = 20, BUFFER1 = 20,
BUFFER2 = 21, BUFFER2 = 21,
BUFFER3 = 22, BUFFER3 = 22,
BUFFER4 = 23, BUFFER4 = 23,
BUFFER5 = 24, BUFFER5 = 24,
DOOR = 30, DOOR = 30,
} }
public partial class EEProtocol public partial class EEProtocol
{ {
// 패킷 수신 이벤트 정의 // 패킷 수신 이벤트 정의
// 데이터 수신 이벤트 정의 // 데이터 수신 이벤트 정의
public event EventHandler<DataEventArgs> OnDataReceived; public event EventHandler<DataEventArgs> OnDataReceived;
public event EventHandler<MessageEventArgs> OnMessage; public event EventHandler<MessageEventArgs> OnMessage;
// CRC16 계산을 위한 테이블 // CRC16 계산을 위한 테이블
private static readonly ushort[] CRC16_TABLE = new ushort[256]; private static readonly ushort[] CRC16_TABLE = new ushort[256];
// CRC16 테이블 초기화 // CRC16 테이블 초기화
public EEProtocol() public EEProtocol()
{ {
const ushort polynomial = 0x7979; const ushort polynomial = 0x7979;
for (ushort i = 0; i < CRC16_TABLE.Length; i++) for (ushort i = 0; i < CRC16_TABLE.Length; i++)
{ {
ushort value = 0; ushort value = 0;
ushort temp = i; ushort temp = i;
for (byte j = 0; j < 8; j++) for (byte j = 0; j < 8; j++)
{ {
if (((value ^ temp) & 0x0001) != 0) if (((value ^ temp) & 0x0001) != 0)
{ {
value = (ushort)((value >> 1) ^ polynomial); value = (ushort)((value >> 1) ^ polynomial);
} }
else else
{ {
value >>= 1; value >>= 1;
} }
temp >>= 1; temp >>= 1;
} }
CRC16_TABLE[i] = value; CRC16_TABLE[i] = value;
} }
//// CRC 테이블 출력 //// CRC 테이블 출력
@@ -62,162 +62,169 @@ namespace ENIG
// } // }
// Console.Write($"0x{CRC16_TABLE[i]:X4}, "); // Console.Write($"0x{CRC16_TABLE[i]:X4}, ");
//} //}
//Console.WriteLine(); //Console.WriteLine();
} }
// CRC16 계산 메서드 // CRC16 계산 메서드
public ushort CalculateCRC16(byte[] data) public ushort CalculateCRC16(byte[] data)
{ {
ushort crc = 0xFFFF; ushort crc = 0xFFFF;
for (int i = 0; i < data.Length; i++) for (int i = 0; i < data.Length; i++)
{ {
byte index = (byte)(crc ^ data[i]); byte index = (byte)(crc ^ data[i]);
crc = (ushort)((crc >> 8) ^ CRC16_TABLE[index]); crc = (ushort)((crc >> 8) ^ CRC16_TABLE[index]);
} }
return crc; return crc;
} }
// 패킷 생성 메서드 // 패킷 생성 메서드
public byte[] CreatePacket(byte id, byte command, byte[] data) public byte[] CreatePacket(byte id, byte command, byte[] data)
{ {
var packet = new Packet var packet = new Packet
{ {
ID = id, ID = id,
Command = command, Command = command,
Data = data ?? new byte[0], Data = data ?? new byte[0],
Length = (byte)(1 + 1 + (data?.Length ?? 0)) // ID + Command + Data 길이 Length = (byte)(1 + 1 + (data?.Length ?? 0)) // ID + Command + Data 길이
}; };
// 패킷 조립 // 패킷 조립
List<byte> packetData = new List<byte>(); List<byte> packetData = new List<byte>();
packetData.Add(Packet.STX); packetData.Add(Packet.STX);
packetData.Add(packet.Length); packetData.Add(packet.Length);
packetData.Add(packet.ID); packetData.Add(packet.ID);
packetData.Add(packet.Command); packetData.Add(packet.Command);
if (packet.Data != null) if (packet.Data != null)
packetData.AddRange(packet.Data); packetData.AddRange(packet.Data);
// CRC16 계산 // CRC16 계산
packet.CRC16 = CalculateCRC16(packetData.Skip(1).ToArray()); // STX 제외하고 계산 packet.CRC16 = CalculateCRC16(packetData.Skip(1).ToArray()); // STX 제외하고 계산
packetData.AddRange(BitConverter.GetBytes(packet.CRC16)); packetData.AddRange(BitConverter.GetBytes(packet.CRC16));
packetData.Add(Packet.ETX); packetData.Add(Packet.ETX);
return packetData.ToArray(); return packetData.ToArray();
} }
//패킷테스트 //패킷테스트
public void PacketTest(byte[] rawData) public void PacketTest(byte[] rawData)
{ {
var hexstr = string.Join(" ", rawData.Select(t => t.ToString("X2"))); var hexstr = string.Join(" ", rawData.Select(t => t.ToString("X2")));
RaiseMessage( $"TestPacket : {hexstr}"); RaiseMessage( $"TestPacket : {hexstr}");
ParsePacket(rawData); ParsePacket(rawData);
} }
//메세지 발생 //메세지 발생
public void RaiseMessage(string message, bool isError = false) public void RaiseMessage(string message, bool isError = false)
{ {
OnMessage?.Invoke(this, new MessageEventArgs { IsError = isError, Message = message }); OnMessage?.Invoke(this, new MessageEventArgs { IsError = isError, Message = message });
} }
// 패킷 파싱 메서드 // 패킷 파싱 메서드
public bool ParsePacket(byte[] rawData) public bool ParsePacket(byte[] rawData)
{ {
try try
{ {
if (rawData.Length < 7) // 최소 패킷 크기 if (rawData.Length < 7) // 최소 패킷 크기
{ {
var hexstring = string.Join(" ", rawData.Select(t => t.ToString("X2"))); var hexstring = string.Join(" ", rawData.Select(t => t.ToString("X2")));
RaiseMessage($"Too Short Data:{hexstring}"); RaiseMessage($"Too Short Data:{hexstring}");
return false; return false;
} }
if (rawData[0] != Packet.STX || rawData[rawData.Length - 1] != Packet.ETX) if (rawData[0] != Packet.STX || rawData[rawData.Length - 1] != Packet.ETX)
{ {
var hexstring = string.Join(" ", rawData.Select(t => t.ToString("X2"))); var hexstring = string.Join(" ", rawData.Select(t => t.ToString("X2")));
RaiseMessage($"STX/ETX Error Data:{hexstring}"); RaiseMessage($"STX/ETX Error Data:{hexstring}");
return false; return false;
} }
byte length = rawData[1]; byte length = rawData[1];
if (length + 5 != rawData.Length) // STX + Length + CRC16(2) + ETX = 5 if (length + 5 != rawData.Length) // STX + Length + CRC16(2) + ETX = 5
{ {
var hexstring = string.Join(" ", rawData.Select(t => t.ToString("X2"))); var hexstring = string.Join(" ", rawData.Select(t => t.ToString("X2")));
RaiseMessage($"Length Error ({length+5} != {rawData.Length}) Data:{hexstring}"); RaiseMessage($"Length Error ({length+5} != {rawData.Length}) Data:{hexstring}");
return false; return false;
} }
// CRC16 검증 // CRC16 검증
byte[] dataForCrc = rawData.Skip(1).Take(length + 1).ToArray(); byte[] dataForCrc = rawData.Skip(1).Take(length + 1).ToArray();
ushort calculatedCrc = CalculateCRC16(dataForCrc); ushort calculatedCrc = CalculateCRC16(dataForCrc);
ushort receivedCrc = BitConverter.ToUInt16(rawData, rawData.Length - 3); ushort receivedCrc = BitConverter.ToUInt16(rawData, rawData.Length - 3);
if (receivedCrc != 0xFFFF && calculatedCrc != receivedCrc) //FF 무시 if (receivedCrc != 0xFFFF && calculatedCrc != receivedCrc) //FF 무시
{ {
RaiseMessage($"CRC Error ID:{rawData[2]:X2},CMD:{rawData[3]:X2}", true); RaiseMessage($"CRC Error ID:{rawData[2]:X2},CMD:{rawData[3]:X2}", true);
return false; return false;
} }
// 패킷 생성 // 패킷 생성
var packet = new Packet var packet = new Packet
{ {
Length = length, Length = length,
ID = rawData[2], ID = rawData[2],
Command = rawData[3], Command = rawData[3],
Data = rawData.Skip(4).Take(length - 2).ToArray(), // ID와 Command 길이(2) 제외 Data = rawData.Skip(4).Take(length - 2).ToArray(), // ID와 Command 길이(2) 제외
CRC16 = receivedCrc, CRC16 = receivedCrc,
RawData = rawData, RawData = rawData,
}; };
// 이벤트 발생 // 이벤트 발생
OnDataReceived?.Invoke(this, new DataEventArgs { ReceivedPacket = packet }); OnDataReceived?.Invoke(this, new DataEventArgs { ReceivedPacket = packet });
return true; return true;
} }
catch catch(Exception ex)
{ {
return false; RaiseMessage(ex.Message, true);
} return false;
} }
}
// 데이터 수신 처리 메서드 (시리얼 포트에서 데이터를 받았을 때 호출)
private List<byte> buffer = new List<byte>(); // 데이터 수신 처리 메서드 (시리얼 포트에서 데이터를 받았을 때 호출)
public void ProcessReceivedData(byte[] data) private List<byte> buffer = new List<byte>();
{ private int ProtocolParseError = 0;
buffer.AddRange(data); public void ProcessReceivedData(byte[] data)
{
while (buffer.Count > 0) buffer.AddRange(data);
{
// STX 찾기 while (buffer.Count > 0)
int stxIndex = buffer.FindIndex(b => b == Packet.STX); {
if (stxIndex == -1) // STX 찾기
{ int stxIndex = buffer.FindIndex(b => b == Packet.STX);
buffer.Clear(); if (stxIndex == -1)
break; {
} buffer.Clear();
break;
// 불필요한 데이터 제거 }
if (stxIndex > 0)
buffer.RemoveRange(0, stxIndex); // 불필요한 데이터 제거
if (stxIndex > 0)
// 패킷 길이 확인을 위한 최소 데이터 확인 buffer.RemoveRange(0, stxIndex);
if (buffer.Count < 2)
break; // 패킷 길이 확인을 위한 최소 데이터 확인
if (buffer.Count < 2)
int expectedLength = buffer[1] + 5; // 전체 패킷 길이 break;
if (buffer.Count < expectedLength)
break; int expectedLength = buffer[1] + 5; // 전체 패킷 길이
if (buffer.Count < expectedLength)
// 패킷 추출 및 처리 break;
byte[] packetData = buffer.Take(expectedLength).ToArray();
buffer.RemoveRange(0, expectedLength); // 패킷 추출 및 처리
byte[] packetData = buffer.Take(expectedLength).ToArray();
ParsePacket(packetData); buffer.RemoveRange(0, expectedLength);
}
} var parseOK = ParsePacket(packetData);
} if(parseOK==false) //분석이 실패되었다면 해당 데이터는 삭제한다.
{
ProtocolParseError += 1;
if (ProtocolParseError > 3) buffer.Clear();
} else ProtocolParseError = 0;
}
}
}
} }

View File

@@ -1,7 +1,56 @@
<Project Sdk="Microsoft.NET.Sdk"> <?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> <PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework> <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{9365803B-933D-4237-93C7-B502C855A71C}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>enigprotocol</RootNamespace>
<AssemblyName>enigprotocol</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
<TargetFrameworkProfile />
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
</Project> <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="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="Commands.cs" />
<Compile Include="EEProtocol.cs" />
<Compile Include="EventArgs.cs" />
<Compile Include="Packet.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include=".gitignore" />
<None Include="ReadMe.MD" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

View File

@@ -1,18 +1,18 @@
using System; using System;
namespace ENIG namespace ENIG
{ {
public partial class EEProtocol public partial class EEProtocol
{ {
public class MessageEventArgs : EventArgs public class MessageEventArgs : EventArgs
{ {
public string Message { get; set; } public string Message { get; set; }
public bool IsError { get; set; } public bool IsError { get; set; }
} }
public class DataEventArgs : EventArgs public class DataEventArgs : EventArgs
{ {
public Packet ReceivedPacket { get; set; } public Packet ReceivedPacket { get; set; }
} }
} }
} }

View File

@@ -1,20 +1,20 @@
namespace ENIG namespace ENIG
{ {
// 패킷 구조체 // 패킷 구조체
public class Packet public class Packet
{ {
public const byte STX = 0x02; public const byte STX = 0x02;
public const byte ETX = 0x03; public const byte ETX = 0x03;
public byte Length { get; set; } public byte Length { get; set; }
public byte ID { get; set; } public byte ID { get; set; }
public byte Command { get; set; } public byte Command { get; set; }
public byte[] Data { get; set; } public byte[] Data { get; set; }
public ushort CRC16 { get; set; } public ushort CRC16 { get; set; }
public byte[] RawData { get; set; } public byte[] RawData { get; set; }
public Packet() public Packet()
{ {
Data = new byte[0]; Data = new byte[0];
} }
} }
} }

View File

@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// 어셈블리에 대한 일반 정보는 다음 특성 집합을 통해
// 제어됩니다. 어셈블리와 관련된 정보를 수정하려면
// 이러한 특성 값을 변경하세요.
[assembly: AssemblyTitle("enigprotocol")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("enigprotocol")]
[assembly: AssemblyCopyright("Copyright © 2025")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// ComVisible을 false로 설정하면 이 어셈블리의 형식이 COM 구성 요소에
// 표시되지 않습니다. COM에서 이 어셈블리의 형식에 액세스하려면
// 해당 형식에 대해 ComVisible 특성을 true로 설정하세요.
[assembly: ComVisible(false)]
// 이 프로젝트가 COM에 노출되는 경우 다음 GUID는 typelib의 ID를 나타냅니다.
[assembly: Guid("9365803b-933d-4237-93c7-b502c855a71c")]
// 어셈블리의 버전 정보는 다음 네 가지 값으로 구성됩니다.
//
// 주 버전
// 부 버전
// 빌드 번호
// 수정 버전
//
// 모든 값을 지정하거나 아래와 같이 '*'를 사용하여 빌드 번호 및 수정 번호를
// 기본값으로 할 수 있습니다.
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

View File

@@ -41,13 +41,13 @@ This README provides a comprehensive overview of the `ENIGProtocol` library, mak
public enum DeviceType : byte public enum DeviceType : byte
{ {
ACS = 0, ACS = 0,
AGV1 = 10, AGV1 = 10+1,
AGV2 = 11, AGV2 = 10+2,
BUFFER1 = 20, BUFFER1 = 20+1,
BUFFER2 = 21, BUFFER2 = 20+2,
BUFFER3 = 22, BUFFER3 = 20+3,
BUFFER4 = 23, BUFFER4 = 20+4,
BUFFER5 = 24, BUFFER5 = 20+5,
DOOR = 30, DOOR = 30,
} }
``` ```
@@ -56,8 +56,8 @@ public enum DeviceType : byte
[STX][LEN][ID][CMD][DATA][CRC16][ETX] [STX][LEN][ID][CMD][DATA][CRC16][ETX]
``` ```
- **STX (Start of Text)**: 0x02 - **STX (Start of Text)**: 0x02
- **LEN (Length)**: 데이터 길이 (1바이트) = {ID+CMD+DATA}
- **ID (Client ID)**: 데이터 길이 (1바이트) : 디바이스식별코드(=DeviceType) - **ID (Client ID)**: 데이터 길이 (1바이트) : 디바이스식별코드(=DeviceType)
- **LEN (Length)**: 데이터 길이 (1바이트) = {CMD+DATA}
- **CMD (Command)**: 명령어 코드 (1바이트) - **CMD (Command)**: 명령어 코드 (1바이트)
- **DATA**: 명령어에 따른 데이터 (가변 길이) - **DATA**: 명령어에 따른 데이터 (가변 길이)
- **CRC16**: 데이터 무결성 검사 (2바이트) - **CRC16**: 데이터 무결성 검사 (2바이트)
@@ -81,7 +81,10 @@ public enum DeviceType : byte
3. **AGV** 3. **AGV**
- H -> E | Move : cmd(100) : 대상태그까지 이동(자동이동) - H -> E | Move : cmd(100) : 대상태그까지 이동(자동이동)
- Target[1] = {DeviceType} - Target[1] = {DeviceType}
- TagID[4] = 0000 - TagID[4] = "0000"
- H -> E | Move : cmd(107) : 대상별칭까지 이동(자동이동)
- Target[1] = {DeviceType}
- AliasName[n] = "....."
- H -> E | Stop : cmd(101) : 멈춤 - H -> E | Stop : cmd(101) : 멈춤
- H -> E | Reset : cmd(102) : 오류 소거 - H -> E | Reset : cmd(102) : 오류 소거
- H -> E | Charge On: cmd(103) : 충전실행(충전기 이동 후 자동 충전 진행) - H -> E | Charge On: cmd(103) : 충전실행(충전기 이동 후 자동 충전 진행)
@@ -104,16 +107,16 @@ public enum DeviceType : byte
- E -> H | TagID Received : cmd(2) : 태그값 인식시 전송 - E -> H | TagID Received : cmd(2) : 태그값 인식시 전송
- TagID[4] : "0000" - TagID[4] : "0000"
- E -> H | Status : cmd(3) - E -> H | Status : cmd(3) - 총 12바이트
- Mode[1] : 0=manual, 1=auto - Mode[1] : 0=manual, 1=auto
- RunSt[1] : 0=stop, 1=run, 2=error - RunSt[1] : 0=stop, 1=run, 2=error
- Diection[1] : 0=straight, 1=left, 2=right, 3=markstop MotDirection[1] : 0:Forward, 1:Backward, 0xFF:unknown
- MagDiection[1] : 0=straight, 1=left, 2=right , 0xFF:unknown
- Inposition[1] : 0=off, 1=on : 목적위치에 도달완료 시 설정 이동 이동시 OFF됨 - Inposition[1] : 0=off, 1=on : 목적위치에 도달완료 시 설정 이동 이동시 OFF됨
- ChargeSt[1] : 0=off, 1=on - ChargeSt[1] : 0=off, 1=on
- CartSt[1] : 0=off, 1=on, 2=unknown - CartSt[1] : 0=off, 1=on, 2=unknown
- LiftSt[1] : 0=down , 1=up, 2=unknown - LiftSt[1] : 0=down , 1=up, 2=unknown
- LastTag[4] : "0000" - LastTag[4] : "0000" (ASCII 4바이트)
- CurrentPath[1] : Path ID , 0=미설정, 1~255(순차증가)
4. **Door** 4. **Door**
- H -> E | cmd(1): 출입문 열기 - H -> E | cmd(1): 출입문 열기

View File

@@ -86,7 +86,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\enigprotocol\ENIGProtocol.csproj"> <ProjectReference Include="..\enigprotocol\ENIGProtocol.csproj">
<Project>{b6fca1b0-c9d1-4159-ab86-25e4bc598c01}</Project> <Project>{499d8912-4b96-41e5-a70d-cfe797883d65}</Project>
<Name>ENIGProtocol</Name> <Name>ENIGProtocol</Name>
</ProjectReference> </ProjectReference>
</ItemGroup> </ItemGroup>