[quote:2a4c555e15]you suggest using waitkey rather than inkey but I don't understand the difference in this context [/quote:2a4c555e15] iskey first doest a check to see if any data is waiting. while waiting simply wait till data arrives. it uses less cycles/code when you know the data must be there since ischarwaiting is basically the same as inkey with the difference that it does not empty the buffer.
[code:1:5c0dcd311c] While Ischarwaiting(#3) <> 0 rxbyte = waitkey(#3) Select Case A Case 10: Case 13: Case 32: Case "E": Case "M": Case Else: If Index < 251 Then bArray(Index) = rxbyte incr index End If End Select Wend bArray(index) = &H0[/code:1:5c0dcd311c]
[quote:b085bca43b="njepsen"]I am doing what you advised against - is this what you had in mind?[/quote:b085bca43b] Yes, this is leaner, as it uses a dedicated pointer to the next char, while the concat '+' always needs to seek the end of string first. [quote:b085bca43b]I know you hate people posting code that won't complile but this function is hardware dependent and is 8000 lines long.[/quote:b085bca43b] I don't need the book, if everything's available in a chapter. If code is easy to read and it doesn't need to be simulated, I'm fine with that. Some minor suggestions: [code:1:b085bca43b]' sTemp = "" <-- can be left out, if the following is applied '... ' bArray(index) = &H0 <-- saves also some cycles to move it from here Wend bArray(index) = &H0 ' <-- to there[/code:1:b085bca43b]
Thanks for the comments chaps. This was an edited version of what i have running, and I do have a 2 sec timeout in the do loop in case nothing arrives, but you are correct - the LF does get added to the string and I remove it and spaces after the loop with delchars. Mark you suggest using waitkey rather than inkey but I don't understand the difference in this context - don't they effectively give the same result after the ischarwaiting? You make a good point if 'continuous' spurious data arrives and i had not though of that, but the timeout would exit after 2 secs.
I have this running at present.[code:1:435e0f0b6d] '************************************************************************************* Function Getmeterresponse(byval metercommandstr As String) As String
'meter response looks like E<space>57.9<cr><lf> 'Note that return to SU0 is 155 bytes long. 'note - if inner loop gets stuck, AIU watchdogs or times out.
' #if isnoise=1 Local Timedelay As Long local Index as byte Index = 1 'arrays are 1 based Tempstr2 = ""
Clear Serialin 'clear ser buffer Print #3 , "" 'clear meter buffer Print #3 , metercommandstr ' CRLF is added automatically
Timedelay = Local_secl + 2
While Ischarwaiting(#3) <> 0 rxbyte = inkey(#3) bArray(Index) = rxbyte 'save the byte overtop of the string incr index bArray(index) = &H0 'write new string terminator if rxbyte = 85 or rxbyte = 10 then exit do
Loop Until Local_secl >= Timedelay
Delchars tempstr2 , 10 'LF Delchars tempstr2 , 13 'CR delchars tempstr2 , 32 'spaces delchars tempstr2 , "E" 'valid response delchars tempstr2 , "M" 'overload print #1,">> meter said ";tempstr2 Getmeterresponse = Tempstr2 #endif End Function
I did this with the webserver code I created a 250 character string and overlaid the bytes as you have done, I needed to pull bytes from the wiznet chip , once the bytes were put into the overlay I could then use string functions to search the bytes (HTTP requests/posts). Note the MEGA1284p was good for this with its 16k of ram. Regards Paul
MWS, some time ago you commented in another post about the follies of building a string with string = String + newcharacter, for reasons that make really good sense, and you advised overlaying an array over the string. I am doing what you advised against - is this what you had in mind? I know you hate people posting code that won't complile but this function is hardware dependent and is 8000 lines long.
[code:1:0369e31da6]Function Getmeterresponse(byval metercommandstr As String) As String
dim sTemp as string * 250 dim bArray(250) as byte at sTemp overlay 'overlay the array at the string address local Index as byte local rxbyte as byte Index = 0 sTemp = "" Print #3 , "" 'clear meter buffer Print #3 , metercommandstr 'command to meter Do
waitms 100 'allow meter time to respond While Ischarwaiting(#3) <> 0 rxbyte = inkey(3) bArray(Index) = rxbyte 'save the byte overtop of the string bArray(index+1) = &H0 'write new string terminator incr index
Loop Until Rxbyte = 10 '10 = LF from Nor140 Getmeterresponse = sTemp
End Function [/code:1:0369e31da6]
[b:0369e31da6][color=red:0369e31da6](BASCOM-AVR version : 2082 , Latest : 188.8.131.52 )[/b:0369e31da6][/color:0369e31da6]