示例#1
0
        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);
        }
示例#2
0
 public static void SendPlcCommand(string cmd)
 {
     if ((PLCUtility.port == null ? true : PLCUtility.port.PortName != PortName))
     {
         PLCUtility.InitPort();
     }
     if (!PLCUtility.port.IsOpen)
     {
         PLCUtility.port.Open();
     }
     Debug.WriteLine(string.Concat("SendPLCCommand: |", cmd, "|"));
     PLCUtility.port.Write(cmd);
 }
示例#3
0
        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);
        }
示例#4
0
 public static bool GetPLCResponse(PLCResponseType expectedResponse, int maxNoOfBufferedMessages, out string errorMessage)
 {
     return(PLCUtility.GetPLCResponse(expectedResponse, maxNoOfBufferedMessages, out errorMessage, 30));
 }
示例#5
0
 public static void SendPlcStartCommand()
 {
     PLCUtility.SendPlcCommand("A");
 }