In part one of this project I created hardware for the Mail Light. The idea behind the Mail Light project is to indicate the presence of emails that are currently on my email server with a flashing LED. This software runs on my PC and drives the hardware I created featured in the last post.
The REALbasic development environment REAL Software is used for this development since it made the email code (pop protocol) very easy.
The goal of the software that I created was to connect to four different email accounts and monitor them for the presence of email. If email was found, a specific LED associated with that account should blink. The LED blinking rate should be changeable, the rate at which the email accounts are polled should be changeable, and the program should hide as a tray icon until needed.
Each of the four accounts has a quarter of the main window with a few text areas for account information. The quarter is pictured below.
Each account has a connect button for enabling that account. When connected, the email account is scanned for email. To the right of the connect button is a visual indicator that will blink in unison with the LED. To the right of that is a text field that shows the number of messages that are on the server of that account.
The box marked “server” should contain the server address. Something like “pop.flintstone.com”. This would need to be the right server for your email account. Below that is the name that you use to log in to your account. It might be “fred” or it might need to be “email@example.com”. Under that is the box for your password. It is a field that shows up as asterisks. My password happens to be: ******* 🙂
Under the password field is a box that contains the rate, in minutes, that the email address is queried. Below that are two connection status boxes.
The other three email addresses are repeated.
To the lower right of the main window there is a box for the blink rate in 1/100 of a second. A value of 50 is a 1/2 second blink rate. Above that is a button to exit the program.
On the upper right of the main window is a button to hide the main window. A double-click on the program’s tray icon will expose this main window again. Everything keeps running with the main window hidden.
When the program is run, it needs to build up a tray icon and set that tray icon to a graphic (in this case called cg4) that is included with the project:
When the program is closed, that icon needs to be removed from the tray:
The app tray object itself has only the task of making the main window visible when the user double-clicks on the tray icon:
The hide button on the main window just makes the main window not visible:
When the main form is made visible for the first time that the program is run, the U421 USB interface is discovered and the defaults for the program are loaded. Communication with the U421 is done through a DLL that is opened by REALbasic when the function inside that DLL is defined. The code first declares the three functions needed (and creates a return value for the function call) before using the functions:
USBm_FindDevices is the first call to USBm.dll. It searches the PC’s USB bus for U401 and U421 devices. In this simplified example code the true/false return code is not used. Non example code would want to process the return values for error. Port A of the U421 is set to output with this call: USBm_DirectionA(0, &HFF, &HFF). The 0 assumes that there is only 1 (indexed to 0) USBmicro device on the bus. If there were more, then additional code would be necessary to address the correct device. See the USBmicro information in the On-line Development Notebook (ODN) for all of the port direction command information.
Once the direction is set to output, all lines are turned off (0) to disable the LEDs:
After that a file called “maildata.txt” in the same folder/directory as the executable maillight.exe is searched for. Again, in a program other than example code, more code should exist to handle errors such as the file not being found.
The file contains text information that is read into the text boxes in the main window. The first line of the file should contain the server name for Email 1, the second line should have the user name, etc. The last line has the LED blink rate. The comments in the code show the format:
The file is opened and each line read into appropriate text boxes:
The LED blink rate is the last of the edit field elements that are loaded on startup by loading this file. Changing the values in the text fields after the file is loaded is also possible by editing those boxes.
Four mail-checking timers, four pop email objects, and the operation of the program will be described in part three of this project.