![]() |
Forum Index : Microcontroller and PC projects : String problem
![]() ![]() |
|||||
Author | Message | ||||
palcal![]() Guru ![]() Joined: 12/10/2011 Location: AustraliaPosts: 1993 |
@ TassyJim Do If Loc(#1)<>0 Then D$=Input$(1,#1) Weather$=Weather$+D$ ' Weather$ contains all the data EndIf Loop Until D$=Chr$(13) D$="" 'clear end of line flag Close #1 Print "Weather$ ";Weather$ Print Len(Weather$) If Asc(Weather$)<32 Then Weather$=Mid$(Weather$,2,13) OutTemp$=Left$(Weather$,2)+"`" 'split up Weather$ to regain data OutHum$=Mid$(Weather$,3,2)+"%" Rain$=Mid$(Weather$,5,3) RY$=Mid$(Weather$,8,3) RYear$=Right$(Weather$,3) Rainfall$=Rain$+" "+RY$+" "+RYear$ Weather$="" 'clear Weather$ This is the code, I don't see what else I can do to clear the buffer. "It is better to be ignorant and ask a stupid question than to be plain Stupid and not ask at all" |
||||
TassyJim![]() Guru ![]() Joined: 07/08/2011 Location: AustraliaPosts: 6283 |
This should clear any left over characters in the system. pause 20 junk$=Input$(Loc(#1),#1) An alternative way to capture the data: If Loc(#1)<>0 Then pause 100 ' wait long enough for all text to arrive. Time depends on baud rate Weather$==Input$(Loc(#1,#1) ' grab everything ' Weather$ contains all the data EndIf ... RYear$=Mid$(Weather$,11,3) In both cases, the PAUSE time depends on the number of characters and the baud rate. The values given are probably way too high (but longer than needed works OK) Jim VK7JH MMedit |
||||
palcal![]() Guru ![]() Joined: 12/10/2011 Location: AustraliaPosts: 1993 |
@ TassyJim. Thanks I think that has fixed it. "It is better to be ignorant and ask a stupid question than to be plain Stupid and not ask at all" |
||||
Turbo46![]() Guru ![]() Joined: 24/12/2017 Location: AustraliaPosts: 1642 |
Palcal, I don't know if this helps but it works for me: It's part of a Modbus slave. The messages are variable in length and can end in any character (ie. a CRC). The end of the message is detected by waiting for a period of more that two character lengths with no character being received. The message is received in an interrupt routine - it's a bit long but the slave has nothing else to do until the master tells it what to do anyway. Bill Keep safe. Live long and prosper. |
||||
palcal![]() Guru ![]() Joined: 12/10/2011 Location: AustraliaPosts: 1993 |
Thanks for that Bill but my code is working OK now, I have saved your code and will keep it in mind. "It is better to be ignorant and ask a stupid question than to be plain Stupid and not ask at all" |
||||
![]() ![]() |
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |