Fractured Posted September 27, 2018 Posted September 27, 2018 Another quick question, is there anyway to have a result show its formating? i.e. string that im getting back from a unit under test is quit long. I know it has formatting that I can use to split it into an array but I dont have a clue how it is formatted.... Doubt that made any sense since im stream of thought typing, so if you need more info ill try and give it....and here is the obligatory code although without the unit it probly wont do much good.....and the responce from the unit in the RTF file.... expandcollapse popup#include <Array.au3> #include <ButtonConstants.au3> #include <CommInterface.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <GuiEdit.au3> #include <MsgBoxConstants.au3> #include <WinAPI.au3> #include <WindowsConstants.au3> #include <ColorConstants.au3> #include <GuiRichEdit.au3> ; Color Notes ...: Green = 65280 , Red = 255 , Blue = 16711680 #Region ### START Koda GUI section ### Form=k:\work\autoit scripts\mine\models\testing\showset.kxf $g_Core = GUICreate("Form1", 615, 437, 192, 124) $i_Model = GUICtrlCreateInput("model", 16, 16, 121, 21) $i_CommPort = GUICtrlCreateInput("port", 144, 16, 121, 21) $b_Connect = GUICtrlCreateButton("connect", 272, 16, 75, 25) $b_ShowSet = GUICtrlCreateButton("show set", 352, 16, 75, 25) $g_hRichEdit = _GUICtrlRichEdit_Create($g_Core, "", 16, 48, 585, 361, _ BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL, $ES_READONLY)) GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif") GUICtrlSetData(-1, "") GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### _DisplayPorts($g_hRichEdit) While 1 $msg = GUIGetMsg() Switch $msg Case $GUI_EVENT_CLOSE Exit Case $b_Connect $sUnit = GUICtrlRead($i_Model) $sCommPort = GUICtrlRead($i_CommPort) Local $aArray = IniReadSection(@ScriptDir & "\unitinfo.ini", $sUnit) ;Local Const $iPort = "" & IniRead(@ScriptDir & "\unitinfo.ini", $sUnit, "Port", "5") & "" ;IniRead ( "filename", "section", "key", "default" ) Local Const $iBaud = "" & IniRead(@ScriptDir & "\unitinfo.ini", $sUnit, "Baud", "11500") & "" ;IniRead ( "filename", "section", "key", "default" ) Local Const $iParity = "" & IniRead(@ScriptDir & "\unitinfo.ini", $sUnit, "Parity", "0") & "" ;IniRead ( "filename", "section", "key", "default" ) Local Const $iByteSize = "" & IniRead(@ScriptDir & "\unitinfo.ini", $sUnit, "ByteSize", "8") & "" ;IniRead ( "filename", "section", "key", "default" ) Local Const $iStopBits = "" & IniRead(@ScriptDir & "\unitinfo.ini", $sUnit, "StopBits", "1") & "" ;IniRead ( "filename", "section", "key", "default" ) ;Global Const $hFile = _CommAPI_OpenCOMPort($iPort, $iBaud, $iParity, $iByteSize, $iStopBits) ;Global $hFile = _CommAPI_OpenCOMPort($iPort, $iBaud, $iParity, $iByteSize, $iStopBits) Global $hFile = _CommAPI_OpenCOMPort($sCommPort, $iBaud, $iParity, $iByteSize, $iStopBits) _CommAPI_TransmitString($hFile, "*IDN?" & @CR) ; _CommAPI_TransmitData(Const $hFile, Const $sData) Local $sResult = _CommAPI_ReceiveString($hFile, 1000) ;_CommAPI_ReceiveString(Const $hFile[, $iTimeout = 1[, $iMaxLength = 0[, $sSeparator = ""]]]) _GUICtrlRichEdit_SetCharColor($g_hRichEdit, 16711680) _GUICtrlRichEdit_AppendText($g_hRichEdit, $sResult) _GUICtrlRichEdit_AppendText($g_hRichEdit, "---------------------------------------" & @CRLF) Case $b_ShowSet _CommAPI_ClearCommError($hFile) If @error Then Exit SetError(@error, @ScriptLineNumber) _CommAPI_PurgeComm($hFile) If @error Then Exit SetError(@error, @ScriptLineNumber) _CommAPI_TransmitString($hFile, "SHOW SET" & @CR) ; _CommAPI_TransmitData(Const $hFile, Const $sData) If @error Then Exit SetError(@error, @ScriptLineNumber) Sleep(500) Local $sResult = _CommAPI_ReceiveString($hFile, 1000) ;_CommAPI_ReceiveString(Const $hFile[, $iTimeout = 1[, $iMaxLength = 0[, $sSeparator = ""]]]) If @error Then Exit SetError(@error, @ScriptLineNumber, $sResult) _GUICtrlRichEdit_SetCharColor($g_hRichEdit, 16711680) _GUICtrlRichEdit_AppendText($g_hRichEdit, $sResult) _GUICtrlRichEdit_AppendText($g_hRichEdit, "---------------------------------------" & @CRLF) msgBox($MB_OK, "Result String",$sResult) $aResult = StringSplit($sResult,0x0A0D & @LF) _ArrayDisplay($aResult,"Possible Show Set Array") EndSwitch WEnd ; #FUNCTION# ============================================================================================== ; Name ..........: _DisplayPorts ; ========================================================================================================= Func _DisplayPorts($g_hRichEdit) Local $sCommPorts = _CommAPI_GetCOMPorts() ; ref https://www.autoitscript.com/wiki/CommAPI_Examples Local $uCommPorts = "COM Ports:" & @LF & $sCommPorts & @LF _GUICtrlRichEdit_AppendText($g_hRichEdit, "---------------------------------------" & @CRLF & @CRLF) _GUICtrlRichEdit_SetCharColor($g_hRichEdit, 16711680) _GUICtrlRichEdit_AppendText($g_hRichEdit, $uCommPorts) _GUICtrlRichEdit_AppendText($g_hRichEdit, "---------------------------------------" & @CRLF) EndFunc ;==>_DisplayPorts show set temp.rtf
Subz Posted September 27, 2018 Posted September 27, 2018 You can always use StringInStr function to check for @CRLF first and/or @LF, if you want to have these displayed, then I would suggest using StringReplace for example: Opt("ExpandVarStrings", 0) $sRawData = "First Line" & @LF & "Second Line" & @CRLF MsgBox(4096, "Raw Data", $sRawData) $sString = StringReplace(StringReplace($sRawData, @CRLF, "@CRLF@"), @LF, "@CRLF@") MsgBox(4096, "String Data", $sString) ;~ If you want to convert it back Opt("ExpandVarStrings", 1) $sString = $sString Opt("ExpandVarStrings", 0) MsgBox(4096, "String Data Updated", $sString) PS: Its generally best practice to not have Global variables within a function. Fractured 1
Fractured Posted September 28, 2018 Author Posted September 28, 2018 Hey @Subz... Yeah on the global vars...this is just a test script to see if I can figure out the formating of the result...Ive tried to stringsplit @CR, @LF, @CRLF,@LFCR, and remove whitespace...this thing is killing me!!! Ill try out the stringreplace to narrow it down...forgot all about that one!! Thanks!
Fractured Posted September 28, 2018 Author Posted September 28, 2018 Solved it!! Thanks again @Subz!!
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now