public bool ExeScriptFile(string FileName, ref string RdStr) { string SptFilePath = null, ErrInfo = null, CleanCmd = null; int ErrCode = 0; SL_IO_Util IOUtil = new SL_IO_Util(); List <ScriptInfo> lScriptInfo = new List <ScriptInfo>(); if (!IOUtil.FileExist(FileName, ref SptFilePath)) { RdStr += "Script not Exist"; return(false); } ErrInfo = ElecsSpt.ExamScript(IOUtil.ReadFile(SptFilePath), ref lScriptInfo); if (!String.IsNullOrEmpty(ErrInfo)) { RdStr = ErrInfo; return(false); } for (int i = 0; i < lScriptInfo.Count; i++) { if (ElecsSpt.ExamCmd(lScriptInfo[i].Command.Trim(), ref CleanCmd, ref ErrCode)) { if (ElecsSpt.GetCmdClass() == 0 || ElecsSpt.GetCmdClass() == 2 || ElecsSpt.GetCmdClass() == 3) { SetDevices(ElecsSpt.getCommAddr(), ref ElecsComm, ElecsSpt.getInstruAddr()); ProcessCmd(ElecsSpt.GetElecsCmd(), ElecsSpt.GetElecsClass(), ref RdStr); Thread.Sleep(20); } } } return(true); }
public bool SaveTxtResult(string FilePath, ref List <string> lCmpInfo, bool delFile) { SL_IO_Util imgUtil = new SL_IO_Util(); string Addr = string.Format("{0,8}", "Addr"); Addr += "\t,\t"; Addr += string.Format("{0,12}", "(R,G,B)"); Addr += "\t,\t"; Addr += string.Format("{0,12}", "(CR,CG,CB)"); string TxtPath = Path.ChangeExtension(FilePath, "txt"); if (lCmpInfo.Count == 0) { lCmpInfo.Add(BMPCMPMATCH); } if (delFile) { imgUtil.FileDelete(TxtPath); } lCmpInfo.Insert(0, Addr); FileStream fs = new FileStream(TxtPath, FileMode.Append, FileAccess.Write); StreamWriter sw = new StreamWriter(fs, System.Text.Encoding.Default); foreach (string item in lCmpInfo) { sw.WriteLine(item); } sw.Close(); lCmpInfo.Clear(); return(true); }
private int MassRdToFile(int[] lXferData, string RdPath, ref List <ResultInfo> lResultInfo, ref string Msg) { int ret = 0; int RdNum = CalculateRdNum(lXferData, RdPath); byte[] rdData = new byte[RdNum]; SL_IO_Util ArrangeOut = new SL_IO_Util(); ret = SL_Comm_Base.SL_CommBase_MassRead(ref rdData, RdNum, true); if (ret != Chip.ERROR_RESULT_OK) { return(ret); } if (String.IsNullOrEmpty(RdPath)) { OrderTxt(rdData, ref Msg); Msg += SplitLineChars[0]; } else { ResultInfo FileInfo = new ResultInfo(); FileInfo.FileName = new SL_IO_Util().GetFileName(RdPath); FileInfo.FilePath = RdPath; FileInfo.FileType = new SL_IO_Util().GetExtName(RdPath); FileInfo.Width = (lXferData.Length > 0) ? lXferData[0] : 0; FileInfo.Heigth = (lXferData.Length > 1) ? lXferData[1] : 0; lResultInfo.Add(FileInfo); DataToFile(rdData, FileInfo, ref Msg); } return(Chip.ERROR_RESULT_OK); }
public bool VerifySpt(string SptNamePath, ref string FileFullPath) { SL_IO_Util IoUtil = new SL_IO_Util(); string rootName = Path.GetDirectoryName(SptNamePath); string fileName = Path.GetFileName(SptNamePath); if (String.IsNullOrEmpty(rootName)) { string FullPath = Path.Combine(Setting.ExeImgDirPath, fileName); if (IoUtil.isFileExist(FullPath)) { FileFullPath = FullPath; return(true); } FullPath = Path.Combine(Setting.ExeSysDirPath, fileName); if (IoUtil.isFileExist(FullPath)) { FileFullPath = FullPath; return(true); } } else { if (IoUtil.isFileExist(SptNamePath)) { FileFullPath = SptNamePath; return(true); } } return(false); }
public int ExeMassDataRd(int[] lXferData, string[] lXferFile, ref string Msg, ref bool Result, int Line, ref List <ResultInfo> lResultInfo) { int ret = 0; SL_IO_Util Util = new SL_IO_Util(); string RdPath = (lXferFile.Length != 0) ? lXferFile[0] : null; if (lXferData.Length == 0 && lXferFile.Length == 0) { Result = false; ErrResult(MASSDATARDTOKEN, NOPARAMETER, ref Msg, Line); return(SystemInfo.ERROR_DATAWR_NOPARAM); } if (Util.GetExtName(RdPath) == BMPEXTNAME && lXferData.Length < 2) { Result = false; ErrResult(DATARDTOKEN, NOPARAMETER, ref Msg, Line); return(SystemInfo.ERROR_DATAWR_NOPARAM); } if (Util.GetExtName(RdPath) == TXTEXTNAME && lXferData.Length < 1) { Result = false; ErrResult(DATARDTOKEN, NOPARAMETER, ref Msg, Line); return(SystemInfo.ERROR_DATAWR_NOPARAM); } if (lXferFile.Length == 0 && lXferData.Length > 1) { WarnResult(DATARDTOKEN, MUCHPARAMETER, ref Msg, Line); } ret = MassRdToFile(lXferData, RdPath, ref lResultInfo, ref Msg); return((ret != Chip.ERROR_RESULT_OK) ? Chip.ERROR_RESULT_FAIL : Chip.ERROR_RESULT_OK); }
public static void f(string funName, string message) { if (!OutLog) { return; } SL_IO_Util fileUtil = new SL_IO_Util(); if (!fileUtil.FileExist(FilePath)) { FilePath = LogFilePath; } if (string.IsNullOrEmpty(FilePath)) { FilePath = Directory.GetCurrentDirectory(); } FileInfo finfo = new FileInfo(FilePath); if (finfo.Directory.Exists == false) { finfo.Directory.Create(); } string writeString = string.Format("{0:yyyy/MM/dd HH:mm:ss} {1}: {2}", DateTime.Now, funName, message) + Environment.NewLine; File.AppendAllText(FilePath, writeString, Encoding.Unicode); }
public bool WriteImgToTxt(string FilePath, byte[] Pixel) { SL_IO_Util imgUtil = new SL_IO_Util(); string TxtPath = Path.ChangeExtension(FilePath, "txt"); imgUtil.WriteByteToTxt(TxtPath, Pixel, true); return(true); }
public bool isFileExist(string ImagePath) { SL_IO_Util imgUtil = new SL_IO_Util(); string fullPath = Setting.ExeImgDirPath + "\\" + ImagePath; if (imgUtil.isFileExist(ImagePath)) { this.ImgPath = ImagePath; return(true); } if (imgUtil.isFileExist(fullPath)) { this.ImgPath = fullPath; return(true); } return(false); }
public bool isFileExist(string ImagePath) { SL_IO_Util imgUtil = new SL_IO_Util(); string fullPath = System.IO.Directory.GetCurrentDirectory() + "\\" + ImagePath; if (imgUtil.isFileExist(ImagePath)) { this.ImgPath = ImagePath; return(true); } if (imgUtil.isFileExist(fullPath)) { this.ImgPath = fullPath; return(true); } return(false); }
private bool InstrScopeImage(int Count, string instruCmd, ref string RdStr) { bool ret = true; string strPath = null, FileName = null; SL_IO_Util IOUtil = new SL_IO_Util(); byte[] ScopeScreenResultsArray; // Screen Results array. int g_ScreenLength; VisaInstrument visaScope = new VisaInstrument(EquipUtil[Count].getInstrName()); //ScopeList.SimpleScopeGraph(devices[1], ":DISPLAY:DATA? PNG, SCREEN, COLOR\r\n"); // Download the screen image. // ----------------------------------------------------------- visaScope.SetTimeoutSeconds(30000); visaScope.DoCommand(":STOP"); visaScope.DoCommand(":HARDcopy:INKSaver OFF"); // Get the screen data. g_ScreenLength = visaScope.DoQueryIEEEBlock(":DISPlay:DATA? PNG, COLor", out ScopeScreenResultsArray); if (instruCmd.CompareTo("auto") == 0) { FileName = "Scope_" + DateTime.Now.ToLocalTime().ToString("yyyyMMdd-HHmmss") + ".png"; } else { FileName = instruCmd; } strPath = Setting.ExeScopeDirPath + "\\" + FileName; if (IOUtil.isFileExist(strPath)) { IOUtil.FileDelete(strPath); } if (IOUtil.GetExtName(strPath).CompareTo("png") != 0) { strPath += ".png"; } FileStream fStream = File.Open(strPath, FileMode.Create); fStream.Write(ScopeScreenResultsArray, 0, g_ScreenLength); fStream.Close(); visaScope.DoCommand(":RUN"); visaScope.Close(); return(ret); }
private int[] stringToInt(string[] WiskeyData) { SL_IO_Util Util = new SL_IO_Util(); int Value = 0; int[] WhiskyValue = new int[WiskeyData.Length]; for (int i = 0; i < WhiskyValue.Length; i++) { if (Util.isStrtoInt(WiskeyData[i], ref Value)) { WhiskyValue[i] = Value; } else { WhiskyValue[i] = 0; } } return(WhiskyValue); }
private byte[] stringToByte(string[] WiskeyData) { SL_IO_Util Util = new SL_IO_Util(); byte Value = 0; byte[] WhiskyValue = new byte[WiskeyData.Length]; for (int i = 0; i < WhiskyValue.Length; i++) { if (Util.isStrtoByte(WiskeyData[i], ref Value)) { WhiskyValue[i] = Value; } else { WhiskyValue[i] = 0; } } return(WhiskyValue); }
/* * Input : Image Path * Output: Image to Binary Array List */ private int ImageToXfer(string RdPath, ref List <byte> lXferData) { int ret = 0; string ExtName = new SL_IO_Util().GetExtName(RdPath); if (ExtName.ToLower().ToString() == TXTEXTNAME) { DatafromTxt(RdPath, ref lXferData); } else if (ExtName.ToLower().ToString() == BMPEXTNAME) { new SL_Img_Lib(RdPath).BmpToList(ref lXferData); } else { ret = SystemInfo.ERROR_IVALIDTOKEN; } return(ret); }
private bool DatafromTxt(string FilePath, ref List <byte> lXferData) { string line; uint value = 0; SL_IO_Util strUtil = new SL_IO_Util(); StreamReader sr = new StreamReader(FilePath, System.Text.Encoding.Default); while ((line = sr.ReadLine()) != null) { string[] words = line.Split(DelimiterChars); foreach (string word in words) { if (strUtil.isStrtoUInt(word, ref value)) { lXferData.Add((byte)value); } } } return(true); }
private int CalculateRdNum(int[] lXferData, string Path) { int RdNum = 0; if (Path != null) { string ExtName = new SL_IO_Util().GetExtName(Path); if (ExtName == BMPEXTNAME) { RdNum = lXferData[0] * lXferData[1] * 3 * 2; } else if (ExtName == TXTEXTNAME) { RdNum = lXferData[0] * 2; } } else { RdNum = (lXferData[0] % 2 == 1) ? lXferData[0] + 1 : lXferData[0]; } return(RdNum); }
private byte[] RdBytefromTxt(string FilePath) { string line; bool isRight = true; uint value = 0; SL_IO_Util Util = new SL_IO_Util(); List <byte> lXferData = new List <byte>(); StreamReader sr = new StreamReader(FilePath, System.Text.Encoding.Default); while ((line = sr.ReadLine()) != null) { string[] words = line.Split(DelimiterChars); foreach (string word in words) { isRight = Util.isStrtoUInt(word, ref value); if (isRight) { lXferData.Add((byte)value); } } } return(lXferData.ToArray()); }
public int CompareGrpah(string CmpGraphFile, ref string SysMsg, ref List <string> lCmpInfo) { int ret = SystemInfo.ERROR_RESULT_OK; string AddrTmp = null; SL_IO_Util FileVerfiy = new SL_IO_Util(); if (!FileVerfiy.isFileExist(ImgPath)) { return(SystemInfo.ERROR_CMP_FILENOTEXIST); } if (!FileVerfiy.isFileExist(CmpGraphFile)) { return(SystemInfo.ERROR_CMP_FILENOTEXIST); } Bitmap DefaultBmp = new Bitmap(ImgPath); Bitmap CmpBmp = new Bitmap(CmpGraphFile); Rectangle DefaultRect = new Rectangle(0, 0, DefaultBmp.Width, DefaultBmp.Height); Rectangle CmpRect = new Rectangle(0, 0, CmpBmp.Width, CmpBmp.Height); System.Drawing.Imaging.BitmapData DefaultBmpData = DefaultBmp.LockBits(DefaultRect, System.Drawing.Imaging.ImageLockMode.ReadWrite, DefaultBmp.PixelFormat); System.Drawing.Imaging.BitmapData CmpBmpData = CmpBmp.LockBits(CmpRect, System.Drawing.Imaging.ImageLockMode.ReadWrite, CmpBmp.PixelFormat); // Get the address of the first line. IntPtr DefualtPtr = DefaultBmpData.Scan0; IntPtr CmpPtr = CmpBmpData.Scan0; // Declare an array to hold the bytes of the bitmap. int DefaultBytes = Math.Abs(DefaultBmpData.Stride) * DefaultBmp.Height; int CmpBytes = Math.Abs(CmpBmpData.Stride) * CmpBmpData.Height; int ResultBytes = Math.Abs(DefaultBmpData.Stride) * DefaultBmpData.Height; byte[] DrgbValues = new byte[DefaultBytes]; byte[] CrgbValues = new byte[CmpBytes]; byte[] RrgbValues = new byte[ResultBytes]; // Copy the RGB values into the array. System.Runtime.InteropServices.Marshal.Copy(DefualtPtr, DrgbValues, 0, DefaultBytes); System.Runtime.InteropServices.Marshal.Copy(CmpPtr, CrgbValues, 0, CmpBytes); // Set every third value to 255. A 24bpp bitmap will look red. for (int Counter = 0; Counter < DrgbValues.Length; Counter += 3) { if (DrgbValues[Counter] == CrgbValues[Counter] && DrgbValues[Counter + 1] == CrgbValues[Counter + 1] && DrgbValues[Counter + 2] == CrgbValues[Counter + 2]) { RrgbValues[Counter] = RrgbValues[Counter + 1] = RrgbValues[Counter + 2] = 255; } else { RrgbValues[Counter + 2] = 255; RrgbValues[Counter + 1] = RrgbValues[Counter] = 0; AddrTmp = CountLocation(DefaultBmp.Width, DefaultBmp.Height, Counter); ShowCmpMsg(ref lCmpInfo, AddrTmp, DrgbValues[Counter + 2], DrgbValues[Counter + 1], DrgbValues[Counter], CrgbValues[Counter + 2], CrgbValues[Counter + 1], CrgbValues[Counter]); ret = SystemInfo.ERROR_CMP_ERROR; } } // Copy the RGB values back to the bitmap System.Runtime.InteropServices.Marshal.Copy(DrgbValues, 0, DefualtPtr, DefaultBytes); System.Runtime.InteropServices.Marshal.Copy(CrgbValues, 0, CmpPtr, CmpBytes); // Unlock the bits. DefaultBmp.UnlockBits(DefaultBmpData); CmpBmp.UnlockBits(CmpBmpData); ResultBmp = CreateBmp(RrgbValues, DefaultBmp.Width, DefaultBmp.Height); return(ret); }
public bool ExcuteCmd(string Cmd, byte CmdType, ref string RdStr) { bool ret = false; SL_IO_Util Util = new SL_IO_Util(); string[] WhiskyCmd = (string[])MergeElecsCmds(Cmd.Trim()).ToArray(typeof(string)); string[] WhiskyData = new string[WhiskyCmd.Length - 1]; Array.Copy(WhiskyCmd, 1, WhiskyData, 0, WhiskyData.Length); if (WhiskyCmd[0].CompareTo(SSL_GPIOH_WRITE) == 0) { ret = SLFpgaGpioH(WhiskyData, ref RdStr); } if (WhiskyCmd[0].CompareTo(SSL_GPIOL_WRITE) == 0) { ret = SLFpgaGpioL(WhiskyData, ref RdStr); } if (WhiskyCmd[0].CompareTo(SSL_GPIO_DIR) == 0) { ret = SLFpgaGpioDir(WhiskyData, ref RdStr); } if (WhiskyCmd[0].CompareTo(SSL_MIPI_VIDEO) == 0) { ret = SetMipiVideo(WhiskyData); } if (WhiskyCmd[0].CompareTo(SSL_MIPI_DSI) == 0) { ret = SetMipiDsi(WhiskyData); } if (WhiskyCmd[0].CompareTo(SSL_FPGA_SET) == 0) { ret = SetFpgaParm(WhiskyData, ref RdStr); } if (WhiskyCmd[0].CompareTo(SSL_BRIDGE_WR) == 0) { ret = SLBrigeWrite(WhiskyData, ref RdStr); } if (WhiskyCmd[0].CompareTo(SSL_BRIDGE_RD) == 0) { ret = SLBrigeRead(WhiskyData, ref RdStr); } if (WhiskyCmd[0].CompareTo(SSL_BRIDGE_SEL) == 0) { ret = SLBridgeSelect(WhiskyData, ref RdStr); } if (WhiskyCmd[0].CompareTo(SSL_MIPI_WR) == 0) { ret = SLMipiWrite(WhiskyData, ref RdStr); } if (WhiskyCmd[0].CompareTo(SSL_I2C_WR) == 0) { ret = SLI2CWrite(WhiskyData, ref RdStr); } if (WhiskyCmd[0].CompareTo(SSL_PMIC_WR) == 0) { ret = SLPmicWrite(WhiskyData, ref RdStr); } if (WhiskyCmd[0].CompareTo(SSL_I2C_RD) == 0) { ret = SLI2CRead(WhiskyData, ref RdStr); } if (WhiskyCmd[0].CompareTo(SSL_IMAGE_FILL) == 0) { ret = SLImageFill(WhiskyData, ref RdStr); } if (WhiskyCmd[0].CompareTo(SSL_MIPI_READ) == 0) { ret = SLMipiRead(WhiskyData, ref RdStr); } if (WhiskyCmd[0].CompareTo(SSL_IMAGE_SHOW) == 0) { ret = SLImageShow(WhiskyData, ref RdStr); } if (WhiskyCmd[0].CompareTo(SSL_FPGA_WRITE) == 0) { ret = SLFpgaWrite(WhiskyData, ref RdStr); } if (WhiskyCmd[0].CompareTo(SSL_FPGA_READ) == 0) { ret = SLFpgaRead(WhiskyData, ref RdStr); } if (WhiskyCmd[0].CompareTo(SSL_SLEEP_CMD) == 0) { ret = SLFpgaSleep(WhiskyData, ref RdStr); } if (WhiskyCmd[0].CompareTo(SSL_USB_WRITE) == 0) { ret = SLFpgaCommandWrite(WhiskyData, ref RdStr); } if (WhiskyCmd[0].CompareTo(SSL_HMIPI_WR) == 0) { ret = SLHightMipiWrite(WhiskyData, ref RdStr); } if (WhiskyCmd[0].CompareTo(SSL_HMIPI_READ) == 0) { ret = SLHighMipiRead(WhiskyData, ref RdStr); } if (WhiskyCmd[0].CompareTo(SSL_MIPI_ULP) == 0) { ret = SLMipiUlp(WhiskyData, ref RdStr); } if (WhiskyCmd[0].CompareTo(SSL_MIPI_BTA) == 0) { ret = SLMipiBta(WhiskyData, ref RdStr); } return(ret); }
public bool ExcuteCmd(string Cmd, byte CmdType, byte CmdReg, ref string RdStr) { bool ret = false; byte Value = 0; SL_IO_Util Util = new SL_IO_Util(); string[] WhiskyCmd = (string[])MergeElecsCmds(Cmd.Trim()).ToArray(typeof(string)); string[] WhiskyData = new string[WhiskyCmd.Length - 1]; Array.Copy(WhiskyCmd, 1, WhiskyData, 0, WhiskyData.Length); if (WhiskyCmd[0].CompareTo(SSL_GPIOH_WRITE) == 0 || WhiskyCmd[0].CompareTo(SSL_GPIOL_WRITE) == 0 || WhiskyCmd[0].CompareTo(SSL_GPIO_DIR) == 0) { if (!Util.isStrtoByte(WhiskyCmd[1], ref Value)) { return(false); } SL_Comm_Base.SL_CommBase_WriteReg(CmdReg, Value); ret = true; } if (WhiskyCmd[0].CompareTo(SSL_MIPI_VIDEO) == 0) { ret = SetMipiVideo(WhiskyData); } if (WhiskyCmd[0].CompareTo(SSL_MIPI_DSI) == 0) { ret = SetMipiDsi(WhiskyData); } if (WhiskyCmd[0].CompareTo(SSL_FPGA_SET) == 0) { ret = SetFpgaParm(WhiskyData, ref RdStr); } if (WhiskyCmd[0].CompareTo(SSL_BRIDGE_WR) == 0) { ret = SLBrigeWrite(WhiskyData, ref RdStr); } if (WhiskyCmd[0].CompareTo(SSL_BRIDGE_RD) == 0) { ret = SLBrigeRead(WhiskyData, ref RdStr); } if (WhiskyCmd[0].CompareTo(SSL_BRIDGE_SEL) == 0) { ret = SLBridgeSelect(WhiskyData, ref RdStr); } if (WhiskyCmd[0].CompareTo(SSL_MIPI_WR) == 0) { ret = SLMipiWrite(WhiskyData, ref RdStr); } if (WhiskyCmd[0].CompareTo(SSL_I2C_WR) == 0) { ret = SLI2CWrite(WhiskyData, ref RdStr); } if (WhiskyCmd[0].CompareTo(SSL_IMAGE_FILL) == 0) { ret = SLImageFill(WhiskyData, ref RdStr); } if (WhiskyCmd[0].CompareTo(SSL_MIPI_READ) == 0) { ret = SLMipiRead(WhiskyData, ref RdStr); } if (WhiskyCmd[0].CompareTo(SSL_IMAGE_SHOW) == 0) { ret = SLImageShow(WhiskyData, ref RdStr); } if (WhiskyCmd[0].CompareTo(SSL_FPGA_WRITE) == 0) { ret = SLFpgaWrite(WhiskyData, ref RdStr); } if (WhiskyCmd[0].CompareTo(SSL_FPGA_READ) == 0) { ret = SLFpgaRead(WhiskyData, ref RdStr); } return(ret); }