' ' USB Thermometer ' ver 0.1 by Stelios M. (steliosm@steliosm.net) ' ' http://steliosm.net ' ' Read the ini file print "Reading ini file..." com$ = ReadIniFile$ ("serial", "port") ' Open the serial port print "Opening serial port..." open com$; ":2400,n,8,1,ds0,cs0,rs" for random as #commPort ' ' GUI PART ' ' Do not print the main window nomainwin [setup.main.Window] '-----Begin code for #main WindowWidth = 250 WindowHeight = 150 UpperLeftX=int((DisplayWidth-WindowWidth)/2) UpperLeftY=int((DisplayHeight-WindowHeight)/2) '-----Begin GUI objects code statictext #main.statictext1, "Temperature:", 5, 52, 81, 20 statictext #main.statictext2, "00.00", 95, 17, 130, 65 '-----End GUI objects code '-----Begin menu code menu #main, "Help",_ "About", [About],_ "Exit" , [UserQuit] '-----End menu code open "USB Thermometer" for window_nf as #main print #main, "font ms_sans_serif 10" print #main.statictext2, "!font century_gothic 36 bold" ' Trap user's quit action print #main, "trapclose [UserQuit]"; ' Set the timer to reald the serial port timer 500, [ReadSerial] ' Wait for user actions [UserWait] print "Waitting for data..." wait ' ' User Actions part [ReadSerial] ' Check serial buffer if lof (#commPort) > 5 then ' We have something in the buffer - check it out print "Got data in buffer" Response$ = input$ (#commPort, 7) print "Got Data: "; Response$ ' Update the StaticText print #main.statictext2, Response$ end if ' Wait again... wait [About] ' Print some info about the program notice "About" + chr$(13) + "USB Thermometer v0.1" + chr$(13) + "Copyright 2011, by Stelios M." wait [UserQuit] ' Exit the application confirm "Are you sure?"; answer$ if answer$ = "no" then wait close #commPort close #main end ' Function to read ini files function ReadIniFile$ (Section$, Entry$) ' Get values from ini file FileName$= DefaultDir$ + "\" + "usb_temp.ini" Default$ = "" + Chr$(0) SizeString = 100 ReturnString$=Space$(SizeString)+Chr$(0) ' Call the function CallDLL #kernel32, "GetPrivateProfileStringA", _ Section$ As ptr, _ Entry$ As ptr, _ Default$ As ptr, _ ReturnString$ As ptr, _ SizeString As long, _ FileName$ As ptr, _ result As long ' Return the value - trim the Chr$(0) character ReadIniFile$ = Left$ (ReturnString$, result) end function