internal void ReadWrite(ref ReadWriteRequest[] values, bool suppressEthernetHeader) { lock (objectLocker) { m_BreakFlagCount++; } System.Diagnostics.Debug.Print("Entering Read Write. Count: " + m_BreakFlagCount.ToString()); Guid parentID = Guid.NewGuid(); List <ReadWriteRequest> requestsList = new List <ReadWriteRequest>(); try { ComDriverLogger.LogReadWriteRequest(DateTime.Now, m_channel.GetLoggerChannelText(), values, MessageDirection.Sent, parentID.ToString()); CheckReadWriteRequests(values); for (int i = 0; i < values.Length; i++) { ReadWriteRequest rw = values[i]; if ((rw is ReadOperands) || (rw is WriteOperands)) { requestsList.Add(rw); if (i == values.Length - 1) { if (requestsList.Count > 0) { ReadWriteRequest[] requestsArray = requestsList.ToArray(); if (OperandsExecuter != null) { OperandsExecuter.PerformReadWrite(ref requestsArray, parentID.ToString(), suppressEthernetHeader); } else { throw new ComDriveExceptions( "The PLC or the state the PLC is in does not support Read/Write Operands", ComDriveExceptions.ComDriveException.UnsupportedCommand); } requestsList.Clear(); } } } else if ((rw is ReadDataTables) || (rw is WriteDataTables)) { ReadWriteRequest[] requestsArray; if (requestsList.Count > 0) { requestsArray = requestsList.ToArray(); if (OperandsExecuter != null) { OperandsExecuter.PerformReadWrite(ref requestsArray, parentID.ToString(), suppressEthernetHeader); } else { throw new ComDriveExceptions( "The PLC or the state the PLC is in does not support Read/Write Operands", ComDriveExceptions.ComDriveException.UnsupportedCommand); } requestsList.Clear(); } requestsArray = new ReadWriteRequest[] { rw }; if (DataTablesExecuter != null) { DataTablesExecuter.PerformReadWrite(ref requestsArray, parentID.ToString(), suppressEthernetHeader); } else { throw new ComDriveExceptions( "The PLC or the state the PLC is in does not support Read/Write Data Tables", ComDriveExceptions.ComDriveException.UnsupportedCommand); } } else if (rw is BinaryRequest) { ReadWriteRequest[] requestsArray; if (requestsList.Count > 0) { requestsArray = requestsList.ToArray(); if (OperandsExecuter != null) { OperandsExecuter.PerformReadWrite(ref requestsArray, parentID.ToString(), suppressEthernetHeader); } else { throw new ComDriveExceptions( "The PLC or the state the PLC is in does not support Read/Write Operands", ComDriveExceptions.ComDriveException.UnsupportedCommand); } requestsList.Clear(); } requestsArray = new ReadWriteRequest[] { rw }; BinaryRequest br = rw as BinaryRequest; switch (br.CommandCode) { case 0x1: //Read Ram/Flash case 0x41: //Write Ram/Flash case 62: //Set Password case 0x2: //verify password case 0x9: //Download Start case 0x45: //Download End case 0xA: //Erase Flash case 0x7: //Wait for flash idle case 0xB: //Blind mode case 0x13: //UnBlind mode case 0xF: //Put PLC in state (Preebot, boot, OS Stop, OS Run) case 0xC: //Get PLC Name if (BasicBinaryExecuter != null) { BasicBinaryExecuter.PerformReadWrite(ref requestsArray, parentID.ToString(), suppressEthernetHeader); } else { throw new ComDriveExceptions( "The PLC or the state the PLC is in does not support Basic Binary commands", ComDriveExceptions.ComDriveException.UnsupportedCommand); } break; default: if (BinaryExecuter != null) { BinaryExecuter.PerformReadWrite(ref requestsArray, parentID.ToString(), suppressEthernetHeader); } else { throw new ComDriveExceptions( "The PLC or the state the PLC is in does not support Binary Commands", ComDriveExceptions.ComDriveException.UnsupportedCommand); } break; } } } } catch (Exception ex) { ComDriveExceptions comDriveException = ex as ComDriveExceptions; if (comDriveException != null) { if ((comDriveException.ErrorCode == ComDriveExceptions.ComDriveException.AbortedByUser) || m_BreakFlag) { throw; } else if (m_BreakFlag) { throw new ComDriveExceptions("Request aborted by user", ComDriveExceptions.ComDriveException.AbortedByUser); } else { throw; } } else if (m_BreakFlag) { throw new ComDriveExceptions("Request aborted by user", ComDriveExceptions.ComDriveException.AbortedByUser); } else { throw; } } finally { lock (objectLocker) { m_BreakFlagCount--; } System.Diagnostics.Debug.Print("Exiting Read Write. Count: " + m_BreakFlagCount.ToString()); ComDriverLogger.LogReadWriteRequest(DateTime.Now, m_channel.GetLoggerChannelText(), values, MessageDirection.Received, parentID.ToString()); } }