/** * dataTemp : 資料來源為 (UInt16[])ValueRead.getText() **/ /// <summary> /// Converts to string. /// </summary> /// <param name="dataTemp">The data temporary.</param> /// <param name="iStartIndex">Start index of the i.</param> /// <param name="iEndIndex">End index of the i.</param> /// <returns>String.</returns> public String convertToString(UInt16[] dataTemp, int iStartIndex, int iEndIndex) { int[] rangeData = BCFUtility.getArrayRange(dataTemp, iStartIndex, iEndIndex); foreach (int loopInt in rangeData) { if (loopInt != 0) { return(((String)BCFUtility.convertInt2TextByType(vr.MPLCConfigDevice.DeviceBitCount, Type.GetType("System.String"), rangeData)).Trim()); } } return(" "); }
/** * dataTemp : 資料來源為 (UInt16[])ValueRead.getText() **/ /// <summary> /// Converts to date time. /// </summary> /// <param name="dataTemp">The data temporary.</param> /// <param name="iStartIndex">Start index of the i.</param> /// <param name="iEndIndex">End index of the i.</param> /// <returns>DateTime.</returns> public DateTime convertToDateTime(UInt16[] dataTemp, int iStartIndex, int iEndIndex) { int[] rangeData = BCFUtility.getArrayRange(dataTemp, iStartIndex, iEndIndex); String sTimeArray = (String)BCFUtility.convertInt2TextByType(vr.MPLCConfigDevice.DeviceBitCount, Type.GetType("System.String"), rangeData); try { IFormatProvider timeStyle = new System.Globalization.CultureInfo("zh-TW", true); return(DateTime.ParseExact(sTimeArray, "yyyyMMddHHmmssff", timeStyle)); } catch (Exception ex) { logger.Error(ex, "Exception:"); //格式錯誤 } return(new DateTime()); }
/** * 取得陣列範圍轉換成BCD **/ /// <summary> /// Converts to BCD. /// </summary> /// <param name="dataTemp">The data temporary.</param> /// <param name="iStartIndex">Start index of the i.</param> /// <param name="iEndIndex">End index of the i.</param> /// <returns>System.Char[].</returns> public static char[] convertToBCD(UInt16[] dataTemp, int iStartIndex, int iEndIndex) { int[] rangeData = BCFUtility.getArrayRange(dataTemp, iStartIndex, iEndIndex); int icount = iEndIndex - iStartIndex + 1; int iarrayCount = 0; char[] returnData = new char[icount * 4];//由於一個Word可由4個BCD碼組成,固可令它*4 for (int j = 0; j < icount; j++) { char[] cTemp = rangeData[j].ToString("X4").ToCharArray(0, 4); for (int i = 0; i < 4; i++) { returnData[iarrayCount] = cTemp[i]; iarrayCount++; } } return(returnData); }
/** * dataTemp : 資料來源為 (UInt16[])ValueRead.getText() **/ /// <summary> /// Converts to int16. /// </summary> /// <param name="dataTemp">The data temporary.</param> /// <param name="iStartIndex">Start index of the i.</param> /// <param name="iEndIndex">End index of the i.</param> /// <returns>UInt16.</returns> public UInt16 convertToInt16(UInt16[] dataTemp, int iStartIndex, int iEndIndex) { int[] rangeData = BCFUtility.getArrayRange(dataTemp, iStartIndex, iEndIndex); return((UInt16)rangeData[0]); }
/** * dataTemp : 資料來源為 (UInt16[])ValueRead.getText() **/ /// <summary> /// Converts to booleans. /// </summary> /// <param name="dataTemp">The data temporary.</param> /// <param name="iStartIndex">Start index of the i.</param> /// <param name="iEndIndex">End index of the i.</param> /// <returns>Boolean[].</returns> public Boolean[] convertToBooleans(UInt16[] dataTemp, int iStartIndex, int iEndIndex) { int[] rangeData = BCFUtility.getArrayRange(dataTemp, iStartIndex, iEndIndex); return((Boolean[])BCFUtility.convertInt2TextByType(vr.MPLCConfigDevice.DeviceBitCount, Type.GetType("System.Boolean[]"), rangeData)); }