コード例 #1
0
        static async Task WaitForCommandResponse(Command com)
        {
            try {
                SendTimer.Stop();

                int i = 0;
                while (i < 5)
                {
                    bool repeated = false;
                    if (i > 0)
                    {
                        repeated = true;
                    }

                    AsyncCamCom.SendCurrent();

                    await Task.Delay(globalTime); // decreasing this will reduce the delay between it checking if it's done but will send more commands

                    if (com.done)
                    {
                        break;
                    }
                    else
                    {
                        await Task.Delay(globalTime);
                    }
                    i++;
                }

                //if(i > 1)
                //    MainForm.m.WriteToResponses("Sent command " + i + " times!", true, false);


                if (!com.done)
                {
                }
                else
                {
                    //MainForm.m.WriteToResponses(GetNameString() + "Received: " + com.myReturn.msg, false);
                }

                com.done = true;

                if (queueList.Contains(com))
                {
                    queueList.Remove(com);
                }


                SendTimer.Start();
            } catch (Exception e) {
                //MainForm.ShowPopup("Failed to process message return!\nShow more?", "Response Failed!", e.ToString());
            }
        }
コード例 #2
0
        public static async Task <List <string> > Stress_Test(byte[] code, string IP, string Port, int cycles, int waittime)
        {
            List <byte[]> commandlist = new List <byte[]>();


            Stopwatch stopwatch = new Stopwatch();

            //Peclo_Over_IP.Connect(IP, Port);
            AsyncCamCom.Connect(IP, Port);
            bool          validreply           = false;
            string        response             = "";
            int           tiltreply            = 0;
            string        conditioned_response = "";
            List <string> results = new List <string>();

            int count = 0;

            while (validreply == false && count < 5)
            {
                stopwatch.Reset();
                stopwatch.Start();
                //response = Peclo_Over_IP.GetResponseManual(code).Result;
                response = await AsyncCamCom.QueryNewCommand(code).ConfigureAwait(false);

                stopwatch.Stop();

                if (response == null)
                {
                    response = "null";
                }


                string[] responsearray = response.Split(' ');

                if (responsearray[0] == "FF" && responsearray[1] == "01")
                {
                    byte address          = Convert.ToByte(Convert.ToInt32(responsearray[1], 16));
                    byte command1         = Convert.ToByte(Convert.ToInt32(responsearray[2], 16));
                    byte command2         = Convert.ToByte(Convert.ToInt32(responsearray[3], 16));
                    byte data1            = Convert.ToByte(Convert.ToInt32(responsearray[4], 16));
                    byte data2            = Convert.ToByte(Convert.ToInt32(responsearray[5], 16));
                    byte returnedchecksum = Convert.ToByte(Convert.ToInt32(responsearray[6], 16));

                    byte CalculatedCheckSum = (byte)((address + command1 + command2 + data1 + data2) % 256);


                    if (returnedchecksum == CalculatedCheckSum)
                    {
                        conditioned_response = "FF " +
                                               responsearray[1] + " " +
                                               responsearray[2] + " " +
                                               responsearray[3] + " " +
                                               responsearray[4] + " " +
                                               responsearray[5] + " " +
                                               responsearray[6];

                        string data = responsearray[4] + responsearray[5];
                        tiltreply  = Convert.ToInt32(data, 16);
                        validreply = true;

                        results.Add(BitConverter.ToString(code).Replace('-', ' '));
                        results.Add(conditioned_response);
                        results.Add(response);
                        results.Add(count.ToString());
                        results.Add((stopwatch.Elapsed.TotalMilliseconds).ToString());

                        break;
                    }
                }
                else
                {
                    results.Add(BitConverter.ToString(code).Replace('-', ' '));
                    results.Add(conditioned_response);
                    results.Add(response);
                    results.Add(count.ToString());
                    results.Add((stopwatch.Elapsed.TotalMilliseconds).ToString());
                    count++;
                }



                // Thread.Sleep(500);
            }



            return(results);
        }