internal void Upload()
        {
            DTPMaster.CheckConnAndVal();
            var file = Master.CreateFileHandler(ConfigFileName).Open(true);

            if (!file.BinnaryFile.Write(ToByteArray()))
            {
                throw new FailOperationException("Не удалось записать данные таблицы векторов");
            }
            file.Close();
            CountOfVectors = (UInt16)VectorAdresses.Count;
        }
示例#2
0
        public void DownloadConfig()
        {
            DTPMaster.CheckConnAndVal();
            var file    = Master.CreateFileHandler(ConfigFileName).Open(false);
            var readRes = file.BinnaryFile.ReadByteArray(ConfigFileLength);

            if (readRes.Succeed)
            {
                Options = new PlotterConfigOptions(readRes.Result);
            }
            else
            {
                throw new FailOperationException("Не удалось получить массив байтов конфиг-файла.");
            }
            file.Close();
        }
示例#3
0
        public void UploadConfig()
        {
            DTPMaster.CheckConnAndVal();
            var file = Master.CreateFileHandler(ConfigFileName).Open(true);

            if (!file.BinnaryFile.Write(Options.ToByteArray()))
            {
                throw new FailOperationException("Не удалось записать данные конфиг-файла");
            }
            file.Close();
            var ph = new PlotterPacketHandler(Master.Sender, Master.Listener);

            if (!ph.RefreshConfig())
            {
                throw new FailOperationException("Не удалось обновить конфиг");
            }
        }
示例#4
0
        public void BeginPrinting(UInt16 Index, PlotterPenInfo Pen)
        {
            DTPMaster.CheckConnAndVal();

            StartTime = DateTime.Now;
            if (ContentMaster == null)
            {
                ContentMaster = new PlotterContent(Master);
            }

            if (!ContentMaster.ContentTable.VectorAdresses.Contains(Index))
            {
                RaiseErrorEvent(PrintErrorType.CantFoundFileWithSpecifiedIndex);
                return;
            }
            VectorMetaData metaData = ContentMaster.GetVectorMetaData(Index);

            if (XSize == 0)
            {
                XSize = GetXsize(metaData.Width, metaData.Height, YSize);
            }
            else
            {
                YSize = GetYsize(metaData.Width, metaData.Height, XSize);
            }
            GetCoefficients(new SizeF(metaData.Width, metaData.Height));
            try
            {
                ph.StartPrinting(Pen.ElevationDelta, Pen.ElevationCorrection, (UInt16)XCoef, (UInt16)YCoef, Index);
            }
            catch
            {
                RaiseErrorEvent(PrintErrorType.CantFoundFileWithSpecifiedIndex);
                return;
            }
            Printing = true;

            Thread.Sleep(1000);

            StatusRequestTimer = new Thread(StatusRequestTimerHandler);
            StatusRequestTimer.Start();
        }
示例#5
0
        private void button_mc_Click(object sender, EventArgs e)
        {
            if (button_mc.Text == TB.L.Phrase["Form_PrintMaster.Disconnect"])
            {
                combobox_bdrate.Enabled = true;
                combobox_com.Enabled    = true;
                master?.CloseConnection();
                button_mc.Text = TB.L.Phrase["Form_PrintMaster.Connect"];
                return;
            }
            try
            {
                var port = new SerialPort(combobox_com.Text, int.Parse(combobox_bdrate.Text.Remove(0, 2)));
                port.Open();
                var Listener = new PacketListener(new SerialPacketReader(port, 3000), new SerialPacketWriter(port));
                master        = new DTPMaster(new Sender("Coestar"), Listener);
                Pens          = master.PlotterConfig().Pens;
                movingControl = master.PlotterMovingControl();
                comboBox1.Items.Clear();
                comboBox1.Items.AddRange(Pens.Select(p => p.Name).ToArray());
                comboBox1.SelectedIndex = 0;
                //Control.Enabled = true;
                combobox_bdrate.Enabled = false;
                combobox_com.Enabled    = false;
                button_mc.Text          = TB.L.Phrase["Form_PrintMaster.Disconnect"];

                if (master.SecurityManager.IsValidationRequired)
                {
                    if (new ValidateForm(master).ShowDialog() != DialogResult.OK)
                    {
                        combobox_bdrate.Enabled = true;
                        combobox_com.Enabled    = true;
                        master?.CloseConnection();
                        button_mc.Text = TB.L.Phrase["Form_PrintMaster.Connect"];
                    }
                }
            }
            catch { MessageBox.Show(
                        string.Format(TB.L.Phrase["Connection.UnableToOpenPort"], combobox_com.Text),
                        TB.L.Phrase["Connection.Error"],
                        MessageBoxButtons.OK, MessageBoxIcon.Error); }
        }
示例#6
0
        public void UploadPenProfiles()
        {
            DTPMaster.CheckConnAndVal();
            List <byte> data = new List <byte>();

            foreach (var a in Pens)
            {
                data.AddRange(a.ToByteArray());
                data.AddRange(Separator);
            }
            var file = Master.CreateFileHandler(PensConfigFileName);

            if (!file.IsExists)
            {
                file.Create();
            }
            file.Open(true);
            file.BinnaryFile.Write(data.ToArray());
            file.Close();
        }
示例#7
0
 public Form_Dialog_PrintEnterNames(DTPMaster master)
 {
     this.master = master;
     InitializeComponent();
 }
示例#8
0
 public bool TurnOffEngines()
 {
     DTPMaster.CheckConnAndVal();
     return(ph.TurnOnEngines());
 }
示例#9
0
 public bool MoveTool(PlotterPenInfo pen, bool UpDirrection)
 {
     DTPMaster.CheckConnAndVal();
     return(ph.MoveTool(0, 0, UpDirrection ? (Int16)(pen.ElevationCorrection + pen.ElevationDelta) : (Int16)pen.ElevationDelta));
 }
示例#10
0
 public bool MoveTool(Int16 dx, Int16 dy, Int16 dz)
 {
     DTPMaster.CheckConnAndVal();
     return(ph.MoveTool(dx, dy, dz));
 }
示例#11
0
        private void MainFormLoad(object sender, EventArgs e)
        {
            string DllName = "Lib\\FileBrowserResources.dll";

            if (!File.Exists(DllName))
            {
                throw new DllNotFoundException($"Dll {DllName} not found");
            }

            var ie = new IconExtractor(DllName);

            backImage    = ie.GetIcon(0).ToBitmap();
            forwardImage = ie.GetIcon(1).ToBitmap();
            folderImage  = ie.GetIcon(2).ToBitmap();

            emptyImage = new Bitmap(5, 5);

            //folderImage = new Bitmap("Icons\\folder.png");
            //backImage = new Bitmap("Icons\\back.png");
            //forwardImage = new Bitmap("Icons\\forward.png");

            MainForm_SizeChanged(null, null);
            try
            {
                port?.Close();
                port   = new SerialPort(portName, 115200);
                Master = new DTPMaster(new SerialPacketReader(port, 4000), new SerialPacketWriter(port));
                Master.Device.SyncTyme();
            }
            catch (SecurityException)
            {
                if (new ValidateForm(Master).ShowDialog() == DialogResult.Cancel)
                {
                    Master.CloseConnection();
                    Close();
                    return;
                }
            }
            catch (WrongPacketInputException ex)
            {
                if (System.Windows.Forms.MessageBox.Show(
                        string.Format("Невозможно получить данные. Произошла ошибка типа WrongPacketInputException (причина {0}. Сообщение: {1}), это может означать что устройство работает не коректно и не грамотно обрабатывает входящие и исходящие пакеты. Попробуйте перезагрузить его и нажать \"Повтор\"", ex.Type.ToString(), ex.Message), "Error", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error) == DialogResult.Retry)
                {
                    MainFormLoad(null, null);
                }
                else
                {
                    Close();
                    return;
                }
            }
            catch (Exception ex)
            {
                if (System.Windows.Forms.MessageBox.Show(
                        string.Format("Произошла ошибка типа {0}.\n{2}\n\nНажмите \"Повтор\" для повторной попытки. Стек вызовов:\n{1}", ex.GetType().FullName, ex.StackTrace, ex.Message), "Error", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error) == DialogResult.Retry)
                {
                    MainFormLoad(null, null);
                }
                else
                {
                    Close();
                    return;
                }
            }

            try
            {
                GetData();
            }
            catch (WrongPacketInputException ex)
            {
                if (System.Windows.Forms.MessageBox.Show(
                        string.Format("Невозможно получить данные. Произошла ошибка типа WrongPacketInputException (причина {0}. Сообщение: {1}), это может означать что устройство работает не коректно и не грамотно обрабатывает входящие и исходящие пакеты. Попробуйте перезагрузить его и нажать \"Повтор\"", ex.Type.ToString(), ex.Message), "Error", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error) == DialogResult.Retry)
                {
                    MainFormLoad(null, null);
                }
                else
                {
                    Close();
                    return;
                }
            }
            catch (Exception ex)
            {
                if (System.Windows.Forms.MessageBox.Show(
                        string.Format("Невозможно получить данные.\n{2}\n\nПроизошла ошибка типа {0}, нажмите \"Повтор\" для повторной попытки. Стек вызовов:\n{1}", ex.GetType().FullName, ex.StackTrace, ex.Message), "Error", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error) == DialogResult.Retry)
                {
                    MainFormLoad(null, null);
                }
                else
                {
                    Close();
                    return;
                }
            }
        }
 internal PlotterContentTable(DTPMaster master) : base(master)
 {
     Download();
 }
示例#13
0
 internal PlotterContent(DTPMaster master) : base(master)
 {
     ContentTable = new PlotterContentTable(Master);
 }
示例#14
0
        public bool ReceiveFileSync(string pcName, string DeviceName)
        {
            //if (ParentMaster.isClosed)
            //TODO: –азобратьс¤ с мастерами
            //throw .CloseEx;
            DTPMaster.CheckConnAndVal();

            TimerThread = new Thread(TimerThreadMethod);
            TimerThread.Start();
            DateTime startTime = DateTime.Now;

            MainFile = new SdCardFile(DeviceName, Master);
            //TODO: сделать мастер/ MainFile!

            try
            {
                if (!MainFile.IsExists)
                {
                    RaiseErrorEvent(new FileReceiverErrorArgs(FileReceiverError.FileNotExists, true));
                    return(false);
                }
            }
            catch
            {
                RaiseErrorEvent(new FileReceiverErrorArgs(FileReceiverError.CantOpenFile, true));
                return(false);
            }
            try { MainFile.Open(false); }
            catch
            {
                RaiseErrorEvent(new FileReceiverErrorArgs(FileReceiverError.CantOpenFile, true));
                return(false);
            }
            var bf = MainFile.BinnaryFile;

            bf.CursorPos = 0;
            UInt32 len = 0;

            try { len = MainFile.Length; }
            catch
            {
                RaiseErrorEvent(new FileReceiverErrorArgs(FileReceiverError.CantGetFileSize, true));
                return(false);
            }
            byte[] buffer = new byte[len];
            UInt32 currentPacket = 0;
            UInt32 totalPackets = (UInt32)(len / PacketLength);
            UInt32 currIndex = 0, delta = 0, index = 0;

            while (currIndex < len)
            {
                if (currIndex + PacketLength > len)
                {
                    delta     = len - currIndex;
                    currIndex = len;
                }
                else
                {
                    currIndex += (UInt32)PacketLength;
                    delta      = (UInt32)PacketLength;
                }
                SdCardBinnaryFileReadResult <byte[]> res;
                try { res = bf.ReadByteArray(delta); }
                catch
                {
                    RaiseErrorEvent(new FileReceiverErrorArgs(FileReceiverError.CantGetPacket, true));
                    return(false);
                }
                if (!res.Succeed)
                {
                    RaiseErrorEvent(new FileReceiverErrorArgs(FileReceiverError.CantGetPacket, true));
                    return(false);
                }
                else
                {
                    if (ForceStop)
                    {
                        try { MainFile.Close(); }
                        catch { RaiseErrorEvent(new FileReceiverErrorArgs(FileReceiverError.CantCloseFile, true)); }
                        RaiseEndEvent(new FileTransferEndArgs((DateTime.Now - startTime).TotalSeconds, true));
                        return(false);
                    }

                    currentPacket++;
                    RaiseProcessEvent(new FileTransferProcessArgs((long)(DateTime.Now - startTime).TotalSeconds, LeftTime, totalPackets - currentPacket, currentPacket, Speed, PacketLength));
                    Buffer.BlockCopy(res.Result, 0, buffer, (int)index, (int)delta);
                    index += delta;
                }
            }
            File.Create(pcName).Close();
            File.WriteAllBytes(pcName, buffer);
            if (CheckLen)
            {
                if (len != new FileInfo(pcName).Length)
                {
                    RaiseErrorEvent(new FileReceiverErrorArgs(FileReceiverError.NotEqualSizes, false));
                }
            }
            if (CheckSum)
            {
                UInt32 localHash  = CrCHandler.CRC32(pcName);
                UInt32 deviceHash = 0;
                try
                {
                    deviceHash = MainFile.CRC32;
                }
                catch
                {
                    RaiseErrorEvent(new FileReceiverErrorArgs(FileReceiverError.CantGetHashOfFile, true));
                    return(false);
                }
                if (localHash != deviceHash)
                {
                    RaiseErrorEvent(new FileReceiverErrorArgs(FileReceiverError.HashesNotEqual, false));
                }
            }
            try { MainFile.Close(); } catch
            {
                RaiseErrorEvent(new FileReceiverErrorArgs(FileReceiverError.CantCloseFile, true));
                return(false);
            }
            RaiseEndEvent(new FileTransferEndArgs((DateTime.Now - startTime).TotalSeconds, false));
            return(true);
        }
示例#15
0
 internal PlotterConfig(DTPMaster master) : base(master)
 {
     DownloadConfig();
     DownloadPenProfiles();
 }
示例#16
0
 public Form_DeviceInfo(DTPMaster master)
 {
     this.master = master;
     InitializeComponent();
 }
示例#17
0
        private void button_open_Click(object sender, EventArgs e)
        {
            if (button_open.Text == TB.L.Phrase["Form_PrintMaster.Disonnect"])
            {
                ResetConntection();
                button_tab1_next.Enabled = false;
                comboBox_bdrate.Enabled  = true;
                comboBox_com.Enabled     = true;
                button_open.Text         = TB.L.Phrase["Form_PrintMaster.Connect"];
            }
            else
            {
                if (comboBox_bdrate.Text == "")
                {
                    MessageBox.Show(
                        TB.L.Phrase["Connection.EnterBDRate"],
                        TB.L.Phrase["Connection.Error"],
                        MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                ResetConntection();
                button_tab1_next.Enabled = false;

                if (comboBox_com.Text == "")
                {
                    MessageBox.Show(
                        TB.L.Phrase["Connection.EnterPort"],
                        TB.L.Phrase["Connection.Error"],
                        MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                SerialPort port = new SerialPort(comboBox_com.Text, int.Parse(comboBox_bdrate.Text));
                try
                {
                    port.Open();
                    port.DiscardInBuffer();
                    port.DiscardOutBuffer();
                    System.Threading.Thread.Sleep(200);
                }
                catch
                {
                    MessageBox.Show(
                        string.Format(TB.L.Phrase["Connection.UnableToOpenPort"], comboBox_com.Text),
                        TB.L.Phrase["Connection.Error"],
                        MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                DTPMaster._this = null;

                try
                {
                    master = new DTPMaster(
                        new SerialPacketReader(port, 2500),
                        new SerialPacketWriter(port));

                    if (!master.Device.Test())
                    {
                        MessageBox.Show(
                            TB.L.Phrase["Connection.DeviceNotAnswered"],
                            TB.L.Phrase["Connection.Error"],
                            MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                }
                catch (TimeoutException)
                {
                    MessageBox.Show(
                        TB.L.Phrase["Connection.DeviceNotAnswered"],
                        TB.L.Phrase["Connection.Error"],
                        MessageBoxButtons.OK, MessageBoxIcon.Error);

                    if (port.IsOpen)
                    {
                        port.Close();
                    }

                    return;
                }
                button_tab1_next.Enabled = true;
                comboBox_bdrate.Enabled  = false;
                comboBox_com.Enabled     = false;
                button_open.Text         = TB.L.Phrase["Form_PrintMaster.Disonnect"];

                if (!master.SecurityManager.IsValidated)
                {
                    if (new ValidateForm(master).ShowDialog() != DialogResult.OK)
                    {
                        //запуск стандартной процедуры отключения
                        ResetConntection();
                        button_tab1_next.Enabled = false;
                        comboBox_bdrate.Enabled  = true;
                        comboBox_com.Enabled     = true;
                        button_open.Text         = TB.L.Phrase["Form_PrintMaster.Connect"];
                    }
                }
                ;
            }
        }
示例#18
0
 public MovingControl(DTPMaster master) : base(master)
 {
 }
 public FlFormatPrintMaster(DTPMaster master) : base(master)
 {
     Content = new PlotterContent(master);
 }
示例#20
0
 private void button_connect_Click(object sender, EventArgs e)
 {
     if (button_connect.Text == TB.L.Phrase["Connection.Disconnect"])
     {
         Master?.CloseConnection();
         groupBox_presets.Enabled = false;
         groupBox_macro.Enabled   = false;
         button_connect.Text      = TB.L.Phrase["Connection.Connect"];
         comboBox_bd.Enabled      = true;
         comboBox_port.Enabled    = true;
     }
     else
     {
         if (comboBox_bd.Text == "")
         {
             MessageBox.Show(
                 TB.L.Phrase["Connection.EnterBDRate"],
                 TB.L.Phrase["Connection.Error"],
                 MessageBoxButtons.OK, MessageBoxIcon.Error);
             return;
         }
         Master?.CloseConnection();
         groupBox_presets.Enabled = false;
         groupBox_macro.Enabled   = false;
         SerialPort port = new SerialPort(comboBox_port.Text, int.Parse(comboBox_bd.Text));
         try
         {
             port.Open();
         }
         catch
         {
             MessageBox.Show(
                 string.Format(TB.L.Phrase["Connection.UnableToOpenPort"], comboBox_port.Text),
                 TB.L.Phrase["Connection.Error"],
                 MessageBoxButtons.OK, MessageBoxIcon.Error);
             return;
         }
         Master = new DTPMaster(
             new SerialPacketReader(port),
             new SerialPacketWriter(port));
         try
         {
             if (!Master.Device.Test())
             {
                 MessageBox.Show(
                     TB.L.Phrase["Connection.DeviceNotAnswered"],
                     TB.L.Phrase["Connection.Error"],
                     MessageBoxButtons.OK, MessageBoxIcon.Error);
                 return;
             }
         }
         catch
         {
             MessageBox.Show(
                 TB.L.Phrase["Connection.DeviceNotAnswered"],
                 TB.L.Phrase["Connection.Error"],
                 MessageBoxButtons.OK, MessageBoxIcon.Error);
             return;
         }
         groupBox_presets.Enabled          = true;
         groupBox_macro.Enabled            = true;
         comboBox_bd.Enabled               = false;
         comboBox_port.Enabled             = false;
         button_connect.Text               = TB.L.Phrase["Connection.Disconnect"];
         ContentMaster                     = new PlotterContent(Master);
         tabControl1.Enabled               = false;
         loadingCircle_previewLoad.Visible = true;
         backgroundWorker1.RunWorkerAsync();
     }
 }