Files
ENIG/AGVEmulator/RunCode/_XBEE.cs

70 lines
2.7 KiB
C#

using ENIG;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace AGVEmulator
{
public partial class fMain
{
private void CAL_Message(object sender, AR.Dev.RS232.MessageEventArgs e)
{
if (e.MsgType == AR.Dev.RS232.MessageType.Send)
logCAL.Add(">> " + System.Text.Encoding.Default.GetString(e.Data));
else if (e.MsgType == AR.Dev.RS232.MessageType.Recv)
logCAL.Add("<< " + System.Text.Encoding.Default.GetString( e.Data));
else logCAL.Add(e.Message);
}
private void CAL_ProtocReceived(object sender, ENIG.EEProtocol.DataEventArgs e)
{
// HMI(Host)에서 호스트로 취급되는 HMI가 보낸 패킷은 ID가 0(ACS)임.
// 하지만 xbee.cs에서 CreatePacket 시 PUB.setting.XBE_ID를 사용함.
// 에뮬레이터에서는 이 패킷들을 수신하여 상태를 업데이트함.
var cmd = (ENIGProtocol.AGVCommandEH)e.ReceivedPacket.Command;
var data = e.ReceivedPacket.Data;
if (cmd == ENIGProtocol.AGVCommandEH.Status)
{
if (data.Length >= 16)
{
_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();
}
}
else if (cmd == ENIGProtocol.AGVCommandEH.Error)
{
if (data.Length >= 1)
{
_remoteErrorCode = (ENIGProtocol.AGVErrorCode)data[0];
// _remoteErrorMessage = ... Error 메시지 자체는 패킷에 포함되지 않으므로 유틸리티 사용 가능
_remoteErrorMessage = ENIGProtocol.AGVUtility.GetAGVErrorMessage(_remoteErrorCode);
UpdateUIStatus();
}
}
}
}
}