public static string GetPLCResponseNocheck(int timeout, bool RemoveMessages = true) { PLCResponse item; string msg = ""; if (!PLCUtility.WaitForPLCResponse(timeout)) { msg = string.Concat("PLC has not responded within a timeout period of ", timeout, " seconds"); } else { lock (PLCUtility.PLCResponseBuffer) while (PLCUtility.PLCResponseBuffer.Count > 0) { item = PLCUtility.PLCResponseBuffer[0]; msg += item.Message + System.Environment.NewLine; if (RemoveMessages) { PLCUtility.PLCResponseBuffer.RemoveAt(0); } else { break; } } } return(msg); }
public static bool GetPLCResponse(PLCResponseType expectedResponse, int maxNoOfBufferedMessages, out string errorMessage, int timeout) { PLCResponse item; bool flag; errorMessage = ""; if (!PLCUtility.WaitForPLCResponse(timeout)) { errorMessage = string.Concat("PLC has not responded within a timeout period of ", timeout, " seconds"); flag = false; } else if (PLCUtility.PLCResponseBuffer.Count <= maxNoOfBufferedMessages) { lock (PLCUtility.PLCResponseBuffer) { item = PLCUtility.PLCResponseBuffer[0]; PLCUtility.PLCResponseBuffer.RemoveAt(0); } if (item.PLCResponseType == expectedResponse) { flag = true; } else { errorMessage = string.Concat("Response from PLC was not as expected. Actual response = \"", item.Message, "\" expected type of response = ", expectedResponse.ToString("g")); flag = false; } } else { object[] count = new object[] { "PLC has sent an unexpected no. of messages. Messages in buffer = ", PLCUtility.PLCResponseBuffer.Count, " expected no. of messages = ", maxNoOfBufferedMessages }; errorMessage = string.Concat(count); flag = false; } return(flag); }