//---------------------------------------------------------------------- public void SetDevice(int aIndex, EMQDevice aDevice, UInt32 aAddr, bool aActive) { byte byActive = (byte)((aActive == false) ? 0x00 : 0x01); SetDevice(aIndex, aDevice, aAddr); sPacket.Byte(aIndex + 4, byActive); }
//---------------------------------------------------------------------- public void SetWord(EMQDevice aDevice, UInt32 aAddr, UInt16[] aValue) { UInt16 nCount = (UInt16)aValue.Length; serial = GenSerial(); lock (sPacket) { sPacket.Clear(); // Header부 Setting sPacket.Head1 = 0x0054; sPacket.Serial = serial; sPacket.Head2 = 0x0000; sPacket.Network = network; sPacket.IO = 0x03FF; sPacket.Plc = plc; sPacket.Station = station; sPacket.Length = Convert.ToUInt16(nCount * 2 + 12); sPacket.CpuWatchDog = 0x0010; // 주명령 일괄쓰기 sPacket.MainCmd = (UInt16)EMQMainCmd.BatchWrite; // 부명령 일반Word단위 sPacket.SubCmd = (UInt16)EMQSubCmd.NormalWord; // 시작 Address sPacket.DWord(0, aAddr); // PLC 내부 접점 Device - X, Y, D, M, ... sPacket.Byte(3, (byte)aDevice); // 쓰기 개수 sPacket.Word(4, nCount); // 쓰기 Data for (int i = 0; i < nCount; i++) { sPacket.Word(i * 2 + 6, aValue[i]); } // 명령 Packet 전송 Send(csSendHeadSize + 6 + nCount * 2); } }
//---------------------------------------------------------------------- public void GetWord(EMQDevice aDevice, UInt32 aAddr, UInt16 aCount = 1) { if (aCount < 1) { str = "Occurred 'aCount' is low error in UlMelsecQ.GetWord"; LogEvent(EMQLogID.Exception, str); throw new UlMelsecQException(str); } serial = GenSerial(); lock (sPacket) { sPacket.Clear(); // Header부 Setting sPacket.Head1 = 0x0054; sPacket.Serial = serial; sPacket.Head2 = 0x0000; sPacket.Network = network; sPacket.IO = 0x03FF; sPacket.Plc = plc; sPacket.Station = station; sPacket.Length = 12; sPacket.CpuWatchDog = 0x0010; // 주명령 일괄읽기 sPacket.MainCmd = (UInt16)EMQMainCmd.BatchRead; // 부명령 일반Word단위 sPacket.SubCmd = (UInt16)EMQSubCmd.NormalWord; // 시작 Address sPacket.DWord(0, aAddr); // PLC 내부 접점 Device - X, Y, D, M, ... sPacket.Byte(3, (byte)aDevice); // 읽기 개수 sPacket.Word(4, aCount); // 명령 Packet 전송 Send(csSendHeadSize + 6); } }
//---------------------------------------------------------------------- public void SetBit(EMQDevice aDevice, UInt32 aAddr, bool aActive) { byte byActive = (byte)((aActive == false) ? 0x00 : 0x10); serial = GenSerial(); lock (sPacket) { sPacket.Clear(); // Header부 Setting sPacket.Head1 = 0x0054; sPacket.Serial = serial; sPacket.Head2 = 0x0000; sPacket.Network = network; sPacket.IO = 0x03FF; sPacket.Plc = plc; sPacket.Station = station; sPacket.Length = 13; sPacket.CpuWatchDog = 0x0010; // 주명령 일괄쓰기 sPacket.MainCmd = (UInt16)EMQMainCmd.BatchWrite; // 부명령 일반Bit단위 sPacket.SubCmd = (UInt16)EMQSubCmd.NormalBit; // 시작 Address sPacket.DWord(0, aAddr); // PLC 내부 접점 Device - X, Y, D, M, ... sPacket.Byte(3, (byte)aDevice); // 쓰기 개수 sPacket.Word(4, 1); // 쓰기 Data sPacket.Byte(6, byActive); // 명령 Packet 전송 Send(csSendHeadSize + 7); } }
//---------------------------------------------------------------------- public void SetWord(EMQDevice aDevice, UInt32 aAddr, UInt16 aValue) { serial = GenSerial(); lock (sPacket) { sPacket.Clear(); // Header부 Setting sPacket.Head1 = 0x0054; sPacket.Serial = serial; sPacket.Head2 = 0x0000; sPacket.Network = network; sPacket.IO = 0x03FF; sPacket.Plc = plc; sPacket.Station = station; sPacket.Length = 14; sPacket.CpuWatchDog = 0x0010; // 주명령 일괄쓰기 sPacket.MainCmd = (UInt16)EMQMainCmd.BatchWrite; // 부명령 일반Word단위 sPacket.SubCmd = (UInt16)EMQSubCmd.NormalWord; // 시작 Address sPacket.DWord(0, aAddr); // PLC 내부 접점 Device - X, Y, D, M, ... sPacket.Byte(3, (byte)aDevice); // 쓰기 개수 sPacket.Word(4, 1); // 쓰기 Data sPacket.Word(6, aValue); // 명령 Packet 전송 Send(csSendHeadSize + 8); } }
//---------------------------------------------------------------------- public void SetDevice(int aIndex, EMQDevice aDevice, UInt32 aAddr) { sPacket.DWord(aIndex, aAddr); sPacket.Byte(aIndex + 3, (byte)aDevice); }