test_acs 프로젝트 변경
This commit is contained in:
@@ -55,16 +55,35 @@ namespace Test_ACS
|
||||
// AGV 상태 수신 처리 (cmd = 3)
|
||||
var device = e.ReceivedPacket.ID;
|
||||
var command = (ENIGProtocol.AGVCommandEH)e.ReceivedPacket.Command;
|
||||
var data = e.ReceivedPacket.Data;
|
||||
|
||||
switch (command)
|
||||
{
|
||||
case AGVCommandEH.Status:
|
||||
UpdateAGVStatus(e.ReceivedPacket.Data);
|
||||
_remoteStatus.Mode = data[0];
|
||||
_remoteStatus.RunSt = data[1];
|
||||
_remoteStatus.HWError = BitConverter.ToUInt16(data, 2);
|
||||
_remoteStatus.RunStep = data[4];
|
||||
_remoteStatus.RunStepSeq = data[5];
|
||||
_remoteStatus.MotorDir = data[6];
|
||||
_remoteStatus.MagnetDir = data[7];
|
||||
_remoteStatus.ChargeSt = data[8];
|
||||
_remoteStatus.CartSt = data[9];
|
||||
_remoteStatus.LiftSt = data[10];
|
||||
_remoteStatus.ErrorCode = data[11];
|
||||
_remoteErrorCode = (ENIGProtocol.AGVErrorCode)data[11];
|
||||
_remoteErrorMessage = ENIGProtocol.AGVUtility.GetAGVErrorMessage(_remoteErrorCode);
|
||||
_remoteStatus.LastTag = Encoding.ASCII.GetString(data, 12, 4);
|
||||
|
||||
UpdateUIStatus();
|
||||
break;
|
||||
case AGVCommandEH.Error:
|
||||
var errorcode = (AGVErrorCode)e.ReceivedPacket.Data[0];
|
||||
var errorMessage = System.Text.Encoding.UTF8.GetString(e.ReceivedPacket.Data, 1, e.ReceivedPacket.Data.Length - 1);
|
||||
AddLog($"Error Received : {errorcode} ID:{e.ReceivedPacket.ID} MSG:{errorMessage}", LogType.Info);
|
||||
|
||||
_remoteErrorCode = (ENIGProtocol.AGVErrorCode)data[0];
|
||||
// _remoteErrorMessage = ... Error 메시지 자체는 패킷에 포함되지 않으므로 유틸리티 사용 가능
|
||||
_remoteErrorMessage = ENIGProtocol.AGVUtility.GetAGVErrorMessage(_remoteErrorCode);
|
||||
UpdateUIStatus();
|
||||
AddLog($"Error Received : {_remoteErrorCode} ID:{e.ReceivedPacket.ID} MSG:{_remoteErrorMessage}", LogType.Info);
|
||||
break;
|
||||
default:
|
||||
AddLog($"unknown command:{command}", LogType.Error);
|
||||
@@ -305,20 +324,21 @@ namespace Test_ACS
|
||||
|
||||
private void btnLiftUp_Click(object sender, EventArgs e)
|
||||
{
|
||||
SendLiftCommand(1); // Up
|
||||
SendLiftCommand( arDev.Narumi.LiftCommand.UP); // Up
|
||||
}
|
||||
|
||||
private void btnLiftDown_Click(object sender, EventArgs e)
|
||||
{
|
||||
SendLiftCommand(2); // Down
|
||||
SendLiftCommand( arDev.Narumi.LiftCommand.DN); // Down
|
||||
}
|
||||
|
||||
private void btnLiftStop_Click(object sender, EventArgs e)
|
||||
{
|
||||
SendLiftCommand(0); // Stop
|
||||
SendLiftCommand( arDev.Narumi.LiftCommand.STP); // Stop
|
||||
}
|
||||
|
||||
private void SendLiftCommand(byte liftCmd)
|
||||
|
||||
private void SendLiftCommand(arDev.Narumi.LiftCommand liftCmd)
|
||||
{
|
||||
// LiftControl: data = TargetID(2 hex) + LiftCommand(1 byte)
|
||||
var targetID = selectedAGV.ToString("X2");
|
||||
@@ -372,124 +392,56 @@ namespace Test_ACS
|
||||
AddLog($"전송 실패: {ex.Message}", LogType.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateAGVStatus(byte[] data)
|
||||
public ENIGProtocol.AGVErrorCode _remoteErrorCode = ENIGProtocol.AGVErrorCode.None;
|
||||
public string _remoteErrorMessage = "";
|
||||
public RemoteStatus _remoteStatus = new RemoteStatus();
|
||||
private void UpdateUIStatus()
|
||||
{
|
||||
if (data.Length < 12)
|
||||
if (this.InvokeRequired)
|
||||
{
|
||||
AddLog($"AGV 상태 데이터 길이 오류: {data.Length} bytes", LogType.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
if (InvokeRequired)
|
||||
{
|
||||
BeginInvoke(new Action(() => UpdateAGVStatus(data)));
|
||||
this.BeginInvoke(new Action(UpdateUIStatus));
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
// Mode[1]: 0=manual, 1=auto
|
||||
lblModeValue.Text = data[0] == 0 ? "수동" : "자동";
|
||||
lblModeValue.ForeColor = data[0] == 0 ? Color.Blue : Color.Green;
|
||||
|
||||
// RunSt[1]: 0=stop, 1=run, 2=error
|
||||
switch (data[1])
|
||||
rtStatus.Text = _remoteStatus.ToString();
|
||||
|
||||
string errCode = _remoteErrorCode.ToString();
|
||||
string errMsg = _remoteErrorMessage;
|
||||
|
||||
if (_remoteStatus.HWError > 0)
|
||||
{
|
||||
case 0:
|
||||
lblRunStValue.Text = "정지";
|
||||
lblRunStValue.ForeColor = Color.Gray;
|
||||
break;
|
||||
case 1:
|
||||
lblRunStValue.Text = "실행";
|
||||
lblRunStValue.ForeColor = Color.Green;
|
||||
break;
|
||||
case 2:
|
||||
lblRunStValue.Text = "에러";
|
||||
lblRunStValue.ForeColor = Color.Red;
|
||||
break;
|
||||
default:
|
||||
lblRunStValue.Text = "알 수 없음";
|
||||
lblRunStValue.ForeColor = Color.Black;
|
||||
break;
|
||||
errCode = $"HW:{_remoteStatus.HWError:X4}" + (errCode == "None" ? "" : $" | {errCode}");
|
||||
|
||||
StringBuilder sbHw = new StringBuilder();
|
||||
for (int i = 0; i < 16; i++)
|
||||
{
|
||||
if (((ushort)_remoteStatus.HWError & (1 << i)) != 0)
|
||||
{
|
||||
sbHw.Append($"{(arDev.Narumi.eflag)i}, ");
|
||||
}
|
||||
}
|
||||
errMsg = $"[HW] {sbHw}" + (string.IsNullOrEmpty(errMsg) ? "" : $" | {errMsg}");
|
||||
}
|
||||
|
||||
// Mot Direction[1]: 0=forward, 1:backward
|
||||
switch (data[2])
|
||||
tbErCode.Text = errCode;
|
||||
tbErmsg.Text = errMsg;
|
||||
|
||||
if (_remoteErrorCode != ENIGProtocol.AGVErrorCode.None || _remoteStatus.HWError > 0)
|
||||
{
|
||||
case 0:
|
||||
lblDirectionValue.Text = "전진";
|
||||
break;
|
||||
case 1:
|
||||
lblDirectionValue.Text = "후진";
|
||||
break;
|
||||
default:
|
||||
lblDirectionValue.Text = "??";
|
||||
break;
|
||||
tbErCode.BackColor = Color.Red;
|
||||
tbErCode.ForeColor = Color.White;
|
||||
}
|
||||
else
|
||||
{
|
||||
tbErCode.BackColor = SystemColors.Window;
|
||||
tbErCode.ForeColor = SystemColors.WindowText;
|
||||
}
|
||||
|
||||
// Direction[1]: 0=straight, 1=left, 2=right, 3=markstop
|
||||
switch (data[3])
|
||||
{
|
||||
case 0:
|
||||
lblDirectionValue.Text += "/직진";
|
||||
break;
|
||||
case 1:
|
||||
lblDirectionValue.Text += "/좌회전";
|
||||
break;
|
||||
case 2:
|
||||
lblDirectionValue.Text += "/우회전";
|
||||
break;
|
||||
default:
|
||||
lblDirectionValue.Text += "/??";
|
||||
break;
|
||||
}
|
||||
|
||||
// Inposition[1]: 0=off, 1=on
|
||||
lblInpositionValue.Text = data[4] == 0 ? "OFF" : "ON";
|
||||
lblInpositionValue.ForeColor = data[4] == 0 ? Color.Gray : Color.Green;
|
||||
|
||||
// ChargeSt[1]: 0=off, 1=on
|
||||
lblChargeStValue.Text = data[5] == 0 ? "OFF" : "ON";
|
||||
lblChargeStValue.ForeColor = data[5] == 0 ? Color.Gray : Color.Orange;
|
||||
|
||||
// CartSt[1]: 0=off, 1=on, 2=unknown
|
||||
switch (data[6])
|
||||
{
|
||||
case 0:
|
||||
lblCartStValue.Text = "없음";
|
||||
lblCartStValue.ForeColor = Color.Gray;
|
||||
break;
|
||||
case 1:
|
||||
lblCartStValue.Text = "있음";
|
||||
lblCartStValue.ForeColor = Color.Green;
|
||||
break;
|
||||
default:
|
||||
lblCartStValue.Text = "??";
|
||||
lblCartStValue.ForeColor = Color.Red;
|
||||
break;
|
||||
}
|
||||
|
||||
// LiftSt[1]: 0=down, 1=up, 2=unknown
|
||||
switch (data[7])
|
||||
{
|
||||
case 0:
|
||||
lblLiftStValue.Text = "하강";
|
||||
lblLiftStValue.ForeColor = Color.Blue;
|
||||
break;
|
||||
case 1:
|
||||
lblLiftStValue.Text = "상승";
|
||||
lblLiftStValue.ForeColor = Color.Green;
|
||||
break;
|
||||
default:
|
||||
lblLiftStValue.Text = "??";
|
||||
lblLiftStValue.ForeColor = Color.Red;
|
||||
break;
|
||||
}
|
||||
|
||||
string lastTag = Encoding.ASCII.GetString(data, 8, 4);
|
||||
lblLastTagValue.Text = lastTag;
|
||||
lblLastTagValue.ForeColor = Color.Black;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -585,6 +537,8 @@ namespace Test_ACS
|
||||
private void button7_Click(object sender, EventArgs e)
|
||||
{
|
||||
//lt180
|
||||
var dlg = MessageBox.Show("턴작업을 실행할까요? 회전반경에 장애물이 없어야 합니다", "확인", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
|
||||
if (dlg != DialogResult.Yes) return;
|
||||
var targetID = selectedAGV.ToString("X2");
|
||||
SendCommand(AGVCommandHE.LTurn180, targetID);
|
||||
}
|
||||
@@ -592,6 +546,8 @@ namespace Test_ACS
|
||||
private void button8_Click(object sender, EventArgs e)
|
||||
{
|
||||
//rt180
|
||||
var dlg = MessageBox.Show("턴작업을 실행할까요? 회전반경에 장애물이 없어야 합니다", "확인", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
|
||||
if (dlg != DialogResult.Yes) return;
|
||||
var targetID = selectedAGV.ToString("X2");
|
||||
SendCommand(AGVCommandHE.RTurn180, targetID);
|
||||
}
|
||||
@@ -599,6 +555,8 @@ namespace Test_ACS
|
||||
private void button9_Click(object sender, EventArgs e)
|
||||
{
|
||||
//l turn
|
||||
var dlg = MessageBox.Show("턴작업을 실행할까요? 회전반경에 장애물이 없어야 합니다", "확인", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
|
||||
if (dlg != DialogResult.Yes) return;
|
||||
var targetID = selectedAGV.ToString("X2");
|
||||
SendCommand(AGVCommandHE.LTurn, targetID);
|
||||
}
|
||||
@@ -606,8 +564,20 @@ namespace Test_ACS
|
||||
private void button10_Click(object sender, EventArgs e)
|
||||
{
|
||||
///r-turn
|
||||
var dlg = MessageBox.Show("턴작업을 실행할까요? 회전반경에 장애물이 없어야 합니다", "확인", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
|
||||
if (dlg != DialogResult.Yes) return;
|
||||
var targetID = selectedAGV.ToString("X2");
|
||||
SendCommand(AGVCommandHE.RTurn, targetID);
|
||||
}
|
||||
|
||||
private void button12_Click(object sender, EventArgs e)
|
||||
{
|
||||
SendLiftCommand(arDev.Narumi.LiftCommand.ON);
|
||||
}
|
||||
|
||||
private void button11_Click(object sender, EventArgs e)
|
||||
{
|
||||
SendLiftCommand(arDev.Narumi.LiftCommand.OFF);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user