コード例 #1
0
ファイル: Form1.cs プロジェクト: ademkaya/XYOSCPlotter
        private void fAnimationSend(ref List <Point> _blackPixels, SendArgs arguments)
        {
            byte lateACKcntr = 0;
            int  prv         = 0;
            int  fileCntr    = 0;

            int    listCount = 0;
            string fileName  = string.Empty;
            string path      = string.Empty;

            List <string> files = new List <string>();

            arguments.Update = true;

            while ((!arguments.IsDone) && (!arguments.Quitting))
            {
                if (arguments.Update)
                {
                    arguments.Update = false;
                    fileCntr         = 0;

                    path = key.GetValue(AnimFolder).ToString();

                    if (files.Count != 0)
                    {
                        files.Clear();
                    }

                    this.Invoke((MethodInvoker)(() => listCount = lstFiles.Items.Count));
                    for (int i = 0; i < listCount; i++)
                    {
                        this.Invoke((MethodInvoker)(() => fileName = lstFiles.Items[i].ToString()));
                        files.Add(path + "\\" + fileName);
                    }
                }

                Bitmap img = (Bitmap)Bitmap.FromFile(files[fileCntr]);
                AddBorder(ref img);
                _blackPixels = getBlackPixels(img);
                img.Dispose();

                if (prv != _blackPixels.Count)
                {
                    sendFrameSizeData(_blackPixels);
                    prv = _blackPixels.Count;
                    Thread.Sleep(1);
                }
                fileCntr += 1;
                if (fileCntr == files.Count)
                {
                    fileCntr = 0;
                }

                List <Point> castedList = ImageCasting(_blackPixels, MapText, chkRevX.Checked, chkRevY.Checked, chkBoxSwapXY.Checked);
                byte[]       temp       = new byte[3] {
                    0, 0, 0
                };
                StringBuilder line = new StringBuilder();
                foreach (Point p in castedList)
                {
                    temp[0] = (byte)'D';
                    temp[1] = (byte)p.X;
                    temp[2] = (byte)p.Y;
                    serPort.Write(temp, 0, temp.Length);
                }

                /*if ack not received ask again !!!*/
                while (((arguments.IsDone) || (!arguments.IsACKReceived)) && (!arguments.Quitting))
                {
                    if (!arguments.IsACKReceived)
                    {
                        lateACKcntr += 1;
                        if (lateACKcntr >= 100)
                        {
                            if (serPort.IsOpen)
                            {
                                serPort.Write(StateSend);
                            }
                            Thread.Sleep(100);
                        }
                    }
                }

                lateACKcntr             = 0;
                arguments.IsACKReceived = false;
            }
            AnimationSend.Abort();
        }