public void DownloadPenProfiles() { DTPMaster.CheckConnAndVal(); Pens = new List <PlotterPenInfo>(); var file = Master.CreateFileHandler(PensConfigFileName); if (!file.IsExists) { return; } file.Open(false); var readRes = file.BinnaryFile.ReadByteArray(file.Length); file.Close(); if (readRes.Succeed) { if (readRes.Result.Length == 0) { return; } else { Pens = GetPensFromBytes(readRes.Result); } } else { throw new FailOperationException("Не удалось получить массив байтов конфиг-файла перьев."); } }
private void Download() { DTPMaster.CheckConnAndVal(); var file = Master.CreateFileHandler(ConfigFileName); if (!file.IsExists) { file.Create(); } file.Open(false); var readRes = file.BinnaryFile.ReadByteArray(file.Length); if (!readRes.Succeed) { throw new FailOperationException("Не удалось прочитать таблицы векторов"); } VectorAdresses = new List <UInt16>(); VectorHashes = new Dictionary <ushort, uint>(); PreviewHashes = new Dictionary <ushort, uint>(); if (readRes.Result.Length != 0) { readRes.Result.Split(10).ToList().ForEach(p => { var a = p.ToArray(); VectorAdresses.Add((UInt16)(a[0] | (a[1] << 8))); VectorHashes.Add(VectorAdresses.Last(), (UInt32)((a[5] << 24) | (a[4] << 16) | (a[3] << 8) | a[2])); PreviewHashes.Add(VectorAdresses.Last(), (UInt32)((a[9] << 24) | (a[8] << 16) | (a[7] << 8) | a[6])); }); } CountOfVectors = (UInt16)VectorAdresses.Count; file.Close(); }
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; }
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(); }
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("Не удалось обновить конфиг"); } }
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(); }
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(); }
public bool TurnOffEngines() { DTPMaster.CheckConnAndVal(); return(ph.TurnOnEngines()); }
public bool MoveTool(PlotterPenInfo pen, bool UpDirrection) { DTPMaster.CheckConnAndVal(); return(ph.MoveTool(0, 0, UpDirrection ? (Int16)(pen.ElevationCorrection + pen.ElevationDelta) : (Int16)pen.ElevationDelta)); }
public bool MoveTool(Int16 dx, Int16 dy, Int16 dz) { DTPMaster.CheckConnAndVal(); return(ph.MoveTool(dx, dy, dz)); }
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); }