I think you're doing way too much in the interval time, slowing your app down. Since you disconnected CTS, the PC will send stuff to the LCD whenever it can, even if the LCD isn't ready for the input, causing corruption.
Let's take a look at all the function calls you make every 250ms:
Winamp_gettrackposition calls sendmessage to Winamp, synchronous call
Winamp_gettracklength calls sendmessage to Winamp, synchronous call
getwinampsong calls getwindowtext, synchronous call
compilemessage calls:
readini 9 times, which calls getprivateprofilestring each time, synchronous call
hhmmss 8 times,
total/availphysmem 8 times, which calls globalmemorystatus, synchronous call
uptime 4 times, which calls gettickcount, synchronous call,
drawbar 4 times,
sendmessage 4 times
on every drawbar call:
winamp_tracklength twice and winamp_trackposition once, each which call sendmessage to winamp, synchronous call
on every sendmessage call:
you loop up to 20 times with (minor) string manipulation
call sleep for 1ms three times (why?)
send output to the comm port up to 3 times
so, in all, every 250ms, you effectively call functions around 68 times.. 36 of which are synchronous calls to the OS/Winamp which may take longer than execution within your program. This allows each function, on average, under 3.7ms. Sure, most of the functions are trivial, but you're definitely chewing up processor time where you don't have to.
Cache some strings where you can. Once you read the INI file, store the result into a module-level or static variable; there's no need to call readini all the time. Get the gettickcoutn once on startup, and calculate the startup date and store that as a module/global variable. Then do a datediff on that and now to get uptime. Call total/avail phys mem once every 3 seconds, or every 5 or however many you care, and store that in a variable you read on display; that stuff doesn't change so much that you'd care it's off by a few seconds. Don't call each function once per line in your compilemessage sub, call them once per call, store them in strings, and send the strings to sendmessage. Better yet, don't call sendmessage once per line, call it once per 4 lines when you have the whole screen ready to send in one string. Be smart about loops, they're costly when they have to be executed quickly every so often.. replace this:
Code:
For x = 1 To maxlength
If x <= Len(Msg) Then
tmpMsg = tmpMsg & Mid(Msg, x, 1)
Else
tmpMsg = tmpMsg & Chr$(32)
End If
Next x
With this:
Code:
tmpmsg = left(msg, maxlength)
if len(tmpmsg) < maxlength then tmpmsg = tmpmsg & space(maxlength - len(tmpmsg))
And you just saved yourself hundreds of cycles. In your case, memory is cheap; time is not.
Bookmarks