using System; using System.Collections; using System.Globalization; using System.Runtime.InteropServices; using System.Text; using csRepeat; namespace AsciiCmdUtilities { public class CommandFilters { public string CreateResTestReadBackCmd(bool bSendCoarseFineGain, int DppType) { string strCfg = ""; bool isINOF; isINOF = (DppType != FW6DppStatus.dppDP5G) && (DppType != FW6DppStatus.dppTB5); strCfg = ""; strCfg += "CLCK=?;"; strCfg += "TPEA=?;"; if (bSendCoarseFineGain) { strCfg += "GAIF=?;"; } if (!bSendCoarseFineGain) { strCfg += "GAIN=?;"; } strCfg += "RESL=?;"; strCfg += "TFLA=?;"; strCfg += "TPFA=?;"; strCfg += "PURE=?;"; strCfg += "RTDE=?;"; strCfg += "MCAS=?;"; strCfg += "MCAC=?;"; strCfg += "SOFF=?;"; strCfg += "AINP=?;"; if (isINOF) { strCfg += "INOF=?;"; } if (bSendCoarseFineGain) { strCfg += "GAIA=?;"; } return strCfg; } public string CreateFullReadBackCmd(bool PC5_PRESENT, int DppType, bool isDP5_RevDxGains, byte DPP_ECO) { string strCfg = ""; bool isHVSE; bool isPAPS; bool isTECS; bool isVOLU; bool isCON1; bool isCON2; bool isINOF; bool isBOOT; bool isGATE; bool isPAPZ; bool isSCTC; bool isDP5_DxK = false; bool isDP5_DxL = false; if (DppType == FW6DppStatus.dppMCA8000D) { strCfg = CreateFullReadBackCmdMCA8000D(DppType); return strCfg; } // DP5 Rev Dx K,L needs PAPZ if ((DppType == FW6DppStatus.dppDP5) && isDP5_RevDxGains) { if ((DPP_ECO & 0x0F) == 0x0A) { isDP5_DxK = true; } if ((DPP_ECO & 0x0F) == 0x0B) { isDP5_DxL = true; } } isHVSE = (((DppType != FW6DppStatus.dppPX5) && PC5_PRESENT) || DppType == FW6DppStatus.dppPX5); isPAPS = (DppType != FW6DppStatus.dppDP5G) && (DppType != FW6DppStatus.dppTB5); isTECS = (((DppType == FW6DppStatus.dppDP5) && PC5_PRESENT) || (DppType == FW6DppStatus.dppPX5) || (DppType == FW6DppStatus.dppDP5X)); isVOLU = (DppType == FW6DppStatus.dppPX5); isCON1 = ((DppType != FW6DppStatus.dppDP5) && (DppType != FW6DppStatus.dppDP5X)); isCON2 = ((DppType != FW6DppStatus.dppDP5) && (DppType != FW6DppStatus.dppDP5X)); isINOF = (DppType != FW6DppStatus.dppDP5G) && (DppType != FW6DppStatus.dppTB5); isSCTC = (DppType == FW6DppStatus.dppDP5G) || (DppType == FW6DppStatus.dppTB5); isBOOT = ((DppType == FW6DppStatus.dppDP5) || (DppType == FW6DppStatus.dppDP5X)); isGATE = ((DppType == FW6DppStatus.dppDP5) || (DppType == FW6DppStatus.dppDP5X)); isPAPZ = (DppType == FW6DppStatus.dppPX5) || isDP5_DxK || isDP5_DxL; strCfg = ""; strCfg += "RESC=?;"; strCfg += "CLCK=?;"; strCfg += "TPEA=?;"; strCfg += "GAIF=?;"; strCfg += "GAIN=?;"; strCfg += "RESL=?;"; strCfg += "TFLA=?;"; strCfg += "TPFA=?;"; strCfg += "PURE=?;"; if (isSCTC) { strCfg += "SCTC=?;"; } strCfg += "RTDE=?;"; strCfg += "MCAS=?;"; strCfg += "MCAC=?;"; strCfg += "SOFF=?;"; strCfg += "AINP=?;"; if (isINOF) { strCfg += "INOF=?;"; } strCfg += "GAIA=?;"; strCfg += "CUSP=?;"; strCfg += "PDMD=?;"; strCfg += "THSL=?;"; strCfg += "TLLD=?;"; strCfg += "THFA=?;"; strCfg += "DACO=?;"; strCfg += "DACF=?;"; strCfg += "RTDS=?;"; strCfg += "RTDT=?;"; strCfg += "BLRM=?;"; strCfg += "BLRD=?;"; strCfg += "BLRU=?;"; if (isGATE) { strCfg += "GATE=?;"; } strCfg += "AUO1=?;"; strCfg += "PRET=?;"; strCfg += "PRER=?;"; strCfg += "PREC=?;"; strCfg += "PRCL=?;"; strCfg += "PRCH=?;"; if (isHVSE) { strCfg += "HVSE=?;"; } if (isTECS) { strCfg += "TECS=?;"; } if (isPAPZ) { strCfg += "PAPZ=?;"; } if (isPAPS) { strCfg += "PAPS=?;"; } strCfg += "SCOE=?;"; strCfg += "SCOT=?;"; strCfg += "SCOG=?;"; strCfg += "MCSL=?;"; strCfg += "MCSH=?;"; strCfg += "MCST=?;"; strCfg += "AUO2=?;"; strCfg += "TPMO=?;"; strCfg += "GPED=?;"; strCfg += "GPIN=?;"; strCfg += "GPME=?;"; strCfg += "GPGA=?;"; strCfg += "GPMC=?;"; strCfg += "MCAE=?;"; if (isVOLU) { strCfg += "VOLU=?;"; } if (isCON1) { strCfg += "CON1=?;"; } if (isCON2) { strCfg += "CON2=?;"; } if (isBOOT) { strCfg += "BOOT=?;"; } return strCfg; } string CreateFullReadBackCmdMCA8000D(int DppType) { string strCfg = ""; if (DppType == FW6DppStatus.dppMCA8000D) { strCfg += "RESC=?;"; strCfg += "PURE=?;"; strCfg += "MCAS=?;"; strCfg += "MCAC=?;"; strCfg += "SOFF=?;"; strCfg += "GAIA=?;"; strCfg += "PDMD=?;"; strCfg += "THSL=?;"; strCfg += "TLLD=?;"; strCfg += "GATE=?;"; strCfg += "AUO1=?;"; //strCfg += "PRET=?;"; strCfg += "PRER=?;"; strCfg += "PREL=?;"; strCfg += "PREC=?;"; strCfg += "PRCL=?;"; strCfg += "PRCH=?;"; strCfg += "SCOE=?;"; strCfg += "SCOT=?;"; strCfg += "SCOG=?;"; strCfg += "MCSL=?;"; strCfg += "MCSH=?;"; strCfg += "MCST=?;"; strCfg += "AUO2=?;"; strCfg += "GPED=?;"; strCfg += "GPIN=?;"; strCfg += "GPME=?;"; strCfg += "GPGA=?;"; strCfg += "GPMC=?;"; strCfg += "MCAE=?;"; //strCfg += "VOLU=?;"; //strCfg += "CON1=?;"; //strCfg += "CON2=?;"; strCfg += "PDMD=?;"; } return strCfg; } public static string RemoveCmd(string strCmd, string strCfgData) { int iStart, iEnd, iCmd; string strNew = ""; strNew = strCfgData; if (strCfgData.Length < 7) { return strCfgData; } // no data if (strCmd.Length != 4) { return strCfgData; } // bad command iCmd = (int)strCfgData.IndexOf(strCmd + "=", 0); if (iCmd == -1) { return strCfgData; } // cmd not found iStart = iCmd; iEnd = (int)strCfgData.IndexOf(";", iCmd); if (iEnd == -1) { return strCfgData; } // end not found if (iEnd <= iStart) { return strCfgData; } // unknown error strNew = strCfgData.Substring(0, iStart) + strCfgData.Substring(iEnd + 1); return strNew; } ////removes selected command by dpp device type public string RemoveCmdByDeviceType(string strCfgDataIn, bool PC5_PRESENT, int DppType, bool isDP5_RevDxGains, byte DPP_ECO) { string strCfgData; bool isHVSE; bool isPAPS; bool isTECS; bool isVOLU; bool isCON1; bool isCON2; bool isINOF; bool isBOOT; bool isGATE; bool isPAPZ; bool isSCTC; bool isPREL; bool isDP5_DxK = false; bool isDP5_DxL = false; strCfgData = strCfgDataIn; if (DppType == FW6DppStatus.dppMCA8000D) { strCfgData = Remove_MCA8000D_Cmds(strCfgData, DppType); return strCfgData; } // DP5 Rev Dx K,L needs PAPZ if ((DppType == FW6DppStatus.dppDP5) && isDP5_RevDxGains) { if ((DPP_ECO & 0x0F) == 0x0A) { isDP5_DxK = true; } if ((DPP_ECO & 0x0F) == 0x0B) { isDP5_DxL = true; } } isHVSE = (((DppType != FW6DppStatus.dppPX5) && PC5_PRESENT) || DppType == FW6DppStatus.dppPX5); isPAPS = (DppType != FW6DppStatus.dppDP5G) && (DppType != FW6DppStatus.dppTB5); isTECS = (((DppType == FW6DppStatus.dppDP5) && PC5_PRESENT) || (DppType == FW6DppStatus.dppPX5) || (DppType == FW6DppStatus.dppDP5X)); isVOLU = (DppType == FW6DppStatus.dppPX5); isCON1 = ((DppType != FW6DppStatus.dppDP5) && (DppType != FW6DppStatus.dppDP5X)); isCON2 = ((DppType != FW6DppStatus.dppDP5) && (DppType != FW6DppStatus.dppDP5X)); isINOF = (DppType != FW6DppStatus.dppDP5G) && (DppType != FW6DppStatus.dppTB5); isSCTC = (DppType == FW6DppStatus.dppDP5G) || (DppType == FW6DppStatus.dppTB5); isBOOT = ((DppType == FW6DppStatus.dppDP5) || (DppType == FW6DppStatus.dppDP5X)); isGATE = ((DppType == FW6DppStatus.dppDP5) || (DppType == FW6DppStatus.dppDP5X)); isPAPZ = (DppType == FW6DppStatus.dppPX5) || isDP5_DxK || isDP5_DxL; isPREL = (DppType == FW6DppStatus.dppMCA8000D); if (!isHVSE) { strCfgData = RemoveCmd("HVSE", strCfgData); } //High Voltage Bias if (!isPAPS) { strCfgData = RemoveCmd("PAPS", strCfgData); } //Preamp Voltage if (!isTECS) { strCfgData = RemoveCmd("TECS", strCfgData); } //Cooler Temperature if (!isVOLU) { strCfgData = RemoveCmd("VOLU", strCfgData); } //px5 speaker if (!isCON1) { strCfgData = RemoveCmd("CON1", strCfgData); } //connector 1 if (!isCON2) { strCfgData = RemoveCmd("CON2", strCfgData); } //connector 2 if (!isINOF) { strCfgData = RemoveCmd("INOF", strCfgData); } //input offset if (!isBOOT) { strCfgData = RemoveCmd("BOOT", strCfgData); } //PC5 On At StartUp if (!isGATE) { strCfgData = RemoveCmd("GATE", strCfgData); } //Gate input if (!isPAPZ) { strCfgData = RemoveCmd("PAPZ", strCfgData); } //Pole-Zero if (!isSCTC) { strCfgData = RemoveCmd("SCTC", strCfgData); } //Scintillator Time Constant if (!isPREL) { strCfgData = RemoveCmd("PREL", strCfgData); } //Preset Live Time return strCfgData; } ////removes MCA8000D commands string Remove_MCA8000D_Cmds(string strCfgDataIn, int DppType) { string strCfgData; strCfgData = strCfgDataIn; if (DppType == FW6DppStatus.dppMCA8000D) { strCfgData = RemoveCmd("CLCK", strCfgData); strCfgData = RemoveCmd("TPEA", strCfgData); strCfgData = RemoveCmd("GAIF", strCfgData); strCfgData = RemoveCmd("GAIN", strCfgData); strCfgData = RemoveCmd("RESL", strCfgData); strCfgData = RemoveCmd("TFLA", strCfgData); strCfgData = RemoveCmd("TPFA", strCfgData); //strCfgData = RemoveCmd("PURE", strCfgData); strCfgData = RemoveCmd("RTDE", strCfgData); strCfgData = RemoveCmd("AINP", strCfgData); strCfgData = RemoveCmd("INOF", strCfgData); strCfgData = RemoveCmd("CUSP", strCfgData); strCfgData = RemoveCmd("THFA", strCfgData); strCfgData = RemoveCmd("DACO", strCfgData); strCfgData = RemoveCmd("DACF", strCfgData); strCfgData = RemoveCmd("RTDS", strCfgData); strCfgData = RemoveCmd("RTDT", strCfgData); strCfgData = RemoveCmd("BLRM", strCfgData); strCfgData = RemoveCmd("BLRD", strCfgData); strCfgData = RemoveCmd("BLRU", strCfgData); strCfgData = RemoveCmd("PRET", strCfgData); strCfgData = RemoveCmd("HVSE", strCfgData); strCfgData = RemoveCmd("TECS", strCfgData); strCfgData = RemoveCmd("PAPZ", strCfgData); strCfgData = RemoveCmd("PAPS", strCfgData); strCfgData = RemoveCmd("TPMO", strCfgData); strCfgData = RemoveCmd("SCAH", strCfgData); strCfgData = RemoveCmd("SCAI", strCfgData); strCfgData = RemoveCmd("SCAL", strCfgData); strCfgData = RemoveCmd("SCAO", strCfgData); strCfgData = RemoveCmd("SCAW", strCfgData); strCfgData = RemoveCmd("BOOT", strCfgData); // added to list late, recheck at later date 20120817 strCfgData = RemoveCmd("CON1", strCfgData); strCfgData = RemoveCmd("CON2", strCfgData); // not implemented as of 20120817, will be implemented at some time strCfgData = RemoveCmd("VOLU", strCfgData); } return strCfgData; } public string GetCmdDesc(string strCmd) { string strCmdName = ""; if (strCmd == "RESC") { strCmdName = "Reset Configuration"; } else if (strCmd == "CLCK") { strCmdName = "20MHz/80MHz"; } else if (strCmd == "TPEA") { strCmdName = "Peaking Time"; } else if (strCmd == "GAIF") { strCmdName = "Fine Gain"; } else if (strCmd == "GAIN") { strCmdName = "Total Gain (Analog * Fine)"; } else if (strCmd == "RESL") { strCmdName = "Detector Reset Lockout"; } else if (strCmd == "TFLA") { strCmdName = "Flat Top"; } else if (strCmd == "TPFA") { strCmdName = "Fast Channel Peaking Time"; } else if (strCmd == "PURE") { strCmdName = "PUR Interval On/Off"; } else if (strCmd == "RTDE") { strCmdName = "RTD On/Off"; } else if (strCmd == "MCAS") { strCmdName = "MCA Source"; } else if (strCmd == "MCAC") { strCmdName = "MCA/MCS Channels"; } else if (strCmd == "SOFF") { strCmdName = "Set Spectrum Offset"; } else if (strCmd == "AINP") { strCmdName = "Analog Input Pos/Neg"; } else if (strCmd == "INOF") { strCmdName = "Input Offset"; } else if (strCmd == "GAIA") { strCmdName = "Analog Gain Index"; } else if (strCmd == "CUSP") { strCmdName = "Non-Trapezoidal Shaping"; } else if (strCmd == "PDMD") { strCmdName = "Peak Detect Mode (Min/Max)"; } else if (strCmd == "THSL") { strCmdName = "Slow Threshold"; } else if (strCmd == "TLLD") { strCmdName = "LLD Threshold"; } else if (strCmd == "THFA") { strCmdName = "Fast Threshold"; } else if (strCmd == "DACO") { strCmdName = "DAC Output"; } else if (strCmd == "DACF") { strCmdName = "DAC Offset"; } else if (strCmd == "RTDS") { strCmdName = "RTD Sensitivity"; } else if (strCmd == "RTDT") { strCmdName = "RTD Threshold"; } else if (strCmd == "RTDD") { strCmdName = "Custom RTD Oneshot Delay"; } else if (strCmd == "RTDW") { strCmdName = "Custom RTD Oneshot Width"; } else if (strCmd == "BLRM") { strCmdName = "BLR Mode"; } else if (strCmd == "BLRD") { strCmdName = "BLR Down Correction"; } else if (strCmd == "BLRU") { strCmdName = "BLR Up Correction"; } else if (strCmd == "GATE") { strCmdName = "Gate Control"; } else if (strCmd == "AUO1") { strCmdName = "AUX_OUT Selection"; } else if (strCmd == "PRET") { strCmdName = "Preset Time"; } else if (strCmd == "PRER") { strCmdName = "Preset Real Time"; } else if (strCmd == "PREL") { strCmdName = "Preset Live Time"; } else if (strCmd == "PREC") { strCmdName = "Preset Counts"; } else if (strCmd == "PRCL") { strCmdName = "Preset Counts Low Threshold"; } else if (strCmd == "PRCH") { strCmdName = "Preset Counts High Threshold"; } else if (strCmd == "HVSE") { strCmdName = "HV Set"; } else if (strCmd == "TECS") { strCmdName = "TEC Set"; } else if (strCmd == "PAPZ") { strCmdName = "Pole-Zero"; } else if (strCmd == "PAPS") { strCmdName = "Preamp 8.5/5 (N/A)"; } else if (strCmd == "SCOE") { strCmdName = "Scope Trigger Edge"; } else if (strCmd == "SCOT") { strCmdName = "Scope Trigger Position"; } else if (strCmd == "SCOG") { strCmdName = "Digital Scope Gain"; } else if (strCmd == "MCSL") { strCmdName = "MCS Low Threshold"; } else if (strCmd == "MCSH") { strCmdName = "MCS High Threshold"; } else if (strCmd == "MCST") { strCmdName = "MCS Timebase"; } else if (strCmd == "AUO2") { strCmdName = "AUX_OUT2 Selection"; } else if (strCmd == "TPMO") { strCmdName = "Test Pulser On/Off"; } else if (strCmd == "GPED") { strCmdName = "G.P. Counter Edge"; } else if (strCmd == "GPIN") { strCmdName = "G.P. Counter Input"; } else if (strCmd == "GPME") { strCmdName = "G.P. Counter Uses MCA_EN?"; } else if (strCmd == "GPGA") { strCmdName = "G.P. Counter Uses GATE?"; } else if (strCmd == "GPMC") { strCmdName = "G.P. Counter Cleared With MCA Counters?"; } else if (strCmd == "MCAE") { strCmdName = "MCA/MCS Enable"; } else if (strCmd == "VOLU") { strCmdName = "Speaker On/Off"; } else if (strCmd == "CON1") { strCmdName = "Connector 1"; } else if (strCmd == "CON2") { strCmdName = "Connector 2"; } else if (strCmd == "SCAH") { strCmdName = "SCAx High Threshold"; } else if (strCmd == "SCAI") { strCmdName = "SCA Index"; } else if (strCmd == "SCAL") { strCmdName = "SCAx Low Theshold"; } else if (strCmd == "SCAO") { strCmdName = "SCAx Output (SCA1-8 Only)"; } else if (strCmd == "SCAW") { strCmdName = "SCA Pulse Width (Not Indexed - SCA1-8)"; } else if (strCmd == "BOOT") { strCmdName = "Turn Supplies On/Off At Power Up"; } return strCmdName; } string AppendCmdDesc(string strCmd, string strCfgData) { int iStart,iEnd,iCmd; string strNew; string strDesc; strNew = ""; if (strCfgData.Length < 7) { return strCfgData; } // no data if (strCmd.Length != 4) { return strCfgData; } // bad command iCmd = (int)strCfgData.IndexOf(strCmd + "=", 0); if (iCmd == -1) { return strCfgData; } // cmd not found iEnd = (int)strCfgData.IndexOf(";", iCmd); if (iEnd == -1) { return strCfgData; } // data end found iStart = (int)strCfgData.IndexOf("=", iCmd); if (iStart != (iCmd + 4)) { return strCfgData; } // data start not found if (iStart >= iEnd) { return strCfgData; } // data error strDesc = GetCmdDesc(strCmd); if (strDesc.Length == 0) { return strCfgData; } // cmd desc not found strNew = strCfgData.Substring(0, iEnd + 1) + " " + strDesc + strCfgData.Substring(iEnd + 1); return strNew; } public string CreateSpectrumConfig(string strRawCfgIn) { string strDisplayCfgOut = ""; string strCmdD = ""; ArrayList Dp5CmdList; Dp5CmdList = MakeDp5CmdList(); strDisplayCfgOut = strRawCfgIn; if (Dp5CmdList.Count > 0) { foreach (object lstCmd in Dp5CmdList) { strCmdD = (string)lstCmd; if (strCmdD.Length > 0) { strDisplayCfgOut = AppendCmdDesc(strCmdD, strDisplayCfgOut); } } } return strDisplayCfgOut; } public ArrayList MakeDp5CmdList() { ArrayList strCfgArr = new ArrayList(); strCfgArr.Clear(); strCfgArr.Add("RESC"); strCfgArr.Add("CLCK"); strCfgArr.Add("TPEA"); strCfgArr.Add("GAIF"); strCfgArr.Add("GAIN"); strCfgArr.Add("RESL"); strCfgArr.Add("TFLA"); strCfgArr.Add("TPFA"); strCfgArr.Add("PURE"); strCfgArr.Add("RTDE"); strCfgArr.Add("MCAS"); strCfgArr.Add("MCAC"); strCfgArr.Add("SOFF"); strCfgArr.Add("AINP"); strCfgArr.Add("INOF"); strCfgArr.Add("GAIA"); strCfgArr.Add("CUSP"); strCfgArr.Add("PDMD"); strCfgArr.Add("THSL"); strCfgArr.Add("TLLD"); strCfgArr.Add("THFA"); strCfgArr.Add("DACO"); strCfgArr.Add("DACF"); strCfgArr.Add("RTDS"); strCfgArr.Add("RTDT"); strCfgArr.Add("BLRM"); strCfgArr.Add("BLRD"); strCfgArr.Add("BLRU"); strCfgArr.Add("GATE"); strCfgArr.Add("AUO1"); strCfgArr.Add("PRET"); strCfgArr.Add("PRER"); strCfgArr.Add("PREL"); strCfgArr.Add("PREC"); strCfgArr.Add("PRCL"); strCfgArr.Add("PRCH"); strCfgArr.Add("HVSE"); strCfgArr.Add("TECS"); strCfgArr.Add("PAPZ"); strCfgArr.Add("PAPS"); strCfgArr.Add("SCOE"); strCfgArr.Add("SCOT"); strCfgArr.Add("SCOG"); strCfgArr.Add("MCSL"); strCfgArr.Add("MCSH"); strCfgArr.Add("MCST"); strCfgArr.Add("AUO2"); strCfgArr.Add("TPMO"); strCfgArr.Add("GPED"); strCfgArr.Add("GPIN"); strCfgArr.Add("GPME"); strCfgArr.Add("GPGA"); strCfgArr.Add("GPMC"); strCfgArr.Add("MCAE"); strCfgArr.Add("VOLU"); strCfgArr.Add("CON1"); strCfgArr.Add("CON2"); strCfgArr.Add("BOOT"); return strCfgArr; } // replaces all occurrences of substring in string string ReplaceCmdText(string strInTextIn, string strFrom, string strTo) { string strReplaceText; string strInText; string strOutText; int lFromLen; int lMatchPos; strInText = strInTextIn; strOutText = ""; lFromLen = (int)strFrom.Length; while (strInText.Length > 0) { lMatchPos = (1 + (int)strInText.IndexOf(strFrom)); if (lMatchPos == 0) { strOutText = strOutText + strInText; strInText = ""; } else { strOutText = strOutText + strInText.Substring(0, lMatchPos - 1) + strTo; strInText = strInText.Substring(lMatchPos + lFromLen - 1); } } strReplaceText = strOutText; return strReplaceText; } // demonstrates replacing a ASCII configuration string values private void ReplaceCmdValues(string strCmdStringIn) { string strCfg = ""; int lLenCmdString; int lBlock1Length; strCmdStringIn = strCmdStringIn.Trim(); lLenCmdString = strCmdStringIn.Length; if (lLenCmdString > 0) { strCfg = strCmdStringIn; strCfg = ReplaceCmdText(strCfg, "US;", ";"); strCfg = ReplaceCmdText(strCfg, "OFF;", "OF;"); strCfg = ReplaceCmdText(strCfg, "RISING;", "RI;"); strCfg = ReplaceCmdText(strCfg, "FALLING;", "FA;"); lBlock1Length = strCfg.Length; } } // demonstrates splitting a ASCII configuration string private void SplitConfig(string strCmdStringIn) { string strConfigOutBlock1 = ""; string strConfigOutBlock2 = ""; int lLenCmdString; int lSplitPosition; int lBlock1Length; int lBlock2Length; int lTotalCfgOutLength; strCmdStringIn = strCmdStringIn.Trim(); lLenCmdString = strCmdStringIn.Length; lSplitPosition = GetCmdChunk(strCmdStringIn); strConfigOutBlock1 = strCmdStringIn.Substring(0, lSplitPosition); strConfigOutBlock2 = strCmdStringIn.Substring(lSplitPosition + 1); lBlock1Length = strConfigOutBlock1.Length; lBlock2Length = strConfigOutBlock2.Length; lTotalCfgOutLength = lBlock1Length + lBlock2Length; } // breaks ASCII Command string into two chuncks, returns split position int GetCmdChunk(string strCmd) { int GetCmdChunk = 0; int idxCfg; int lChunk; int lEnd; GetCmdChunk = 0; lChunk = 0; lEnd = 0; for (idxCfg = 1; idxCfg <= (int)strCmd.Length; idxCfg++) { lChunk = (int)(1 + strCmd.IndexOf(";", lEnd)); if ((lChunk == 0) || (lChunk > 512)) { break; } lEnd = lChunk; } GetCmdChunk = lEnd; return GetCmdChunk; } /// Convert unicode values to ASCII bytes for save/transfer bool CopyAsciiData(byte[] Data, string strCfg, long lLen) { if (strCfg.Length > 0) { Data = Encoding.ASCII.GetBytes(strCfg); return true; } else { return false; } } } }