Monthly Archives: October 2007

Serial Port Code Library

Need to interact with some hardware via serial port? I’m having to do some serial port communications in a project at work, and it is officially Not Fun. There was some original code that was doing only reads from the port, and I needed to some significant functionality that would not be possible with the existing code. So rather than writing a ton of code from scratch (well, other than what I will have to do anyway), I tried to find some open-source, commercial-friendly serial port libraries on the Internet.

The only one I could find that seemed to be perfectly suited to the task at hand was Serial Library for C++ by Ramon de Klein. It has a number of classes for various ways of accessing the serial port and handling events, interacting with Windows. It also supports MFC.

The license is LGPL, which makes it’s ok for me to use in the project. As Ramon’s article notes, doing serial port communications from scratch is hard. So reuse what is out there.

If you’re in .Net, you already have some nice classes in the form of System.IO.Ports.SerialPort, which was added in 2.0.

Technorati Tags: , , ,

Getting the most out of Outlook 2007

I’ve been trying to organize my life lately, and this weekend, I decided to get my Outlook under control–respond, file, or delete the hundreds of e-mails in my inbox, create necessary tasks, delete obsolete ones, reorganize the folder hierarchy, etc. Also, I’ve recently been introduced to the Getting Things Done methodology and was interested in that. Some of these sites use GTD as their basis, but all the tips are useful even if you’re not specifically using Getting Things Done. In any case, all of these are focused on personal productivity.

In addition, I decided to figure out how to use some features more effectively than I do. Like categories. Outlook has always had categories, but they work so much better in the 2007 version. The To-Do bar has also been visible the whole time I’ve had Outlook 2007, but I haven’t used it effectively. Until now.

What follows are some links to articles and blogs that can help rein in Outlook and make it work for you.

Organization Basics

Advanced Organization

Getting Things Done

I’ve recently become interested in this methodology, after reading the recent article in Wired magazine.

General

Macros

Blogs

Got some other really good tips or sites? Did I leave out an area of Outlook? Post them in the comments and I’ll add them to the list.

Have you checked out my Buy Me a Lego site? If not, please do so!

Technorati Tags: , , , ,

A DC Video Production Company

Here’s a shout-out to “Memories in Motion”, Video Production Technology, a great videography and production company in the metro Washington, DC area. Frank also does great video work for the news wire service my wife works for. They were generous with a donation to my BuyMeALego campaign, and I wish them the best of luck.

If you need a video of a wedding, birthday, party, religious events, reunions, live music, or any other event in the DC area, please go look them up. There are some sample pics and screengrabs at the site.

What is Lupus?

One of my donors to my Buy Me a Lego campaign was a representative of the Lupus Erythematosus Society of Saskatchewan (L.E.S.S.). I appreciate this opportunity to give them so more publicity. I had heard the word “Lupus” but I was not familiar with exactly this disease was, so I looked it up on their site.

According to the site,

Systemic Lupus Erythematosus (SLE) is a chronic inflammatory disease which may affect many different organs and tissues in the body. Women of child bearing age are typically affected, but individuals of any age, sex or race may develop the disease.

SLE while uncommon, is not rare, with an estimated disease prevalence of 1 in every 2,000 population. It is a condition which appears to be increasing in prominence especially over the last 15 – 20 years. This is likely explained by the earlier recognition of milder cases because of increased patient and physician awareness and by the enhanced availability of sensitive laboratory tests helpful in the diagnosis.

I was interested in the derivation of the word “lupus”, which obviously means wolf from Latin. From what I can tell, the rash you can get causes you to appear vaguely wolf-like. From one of the symptoms:

Skin rash – a very common feature occurring in many patients. The classic rash is called a “butterfly rash” because it occurs in a butterfly- like a patch over the bridge of the nose and cheeks. This type of rash is in fact quite common with most lupus rashes being far less specific and accruing anywhere on the body but especially over sun exposed areas.

You can find more information about the disease, including the symptoms, here. Thankfully, it seems that most people have mild cases which can be easily controlled. I encourage you to go check them out.

Technorati Tags: , , , ,

What’s Wrong with this Code 2 (Answer)

In my previous post, I showed some code that we “fixed” and it caused problems–it actually broke the algorithm.

The bug was in relying on some compiler behavior and the usage of the stack.

Here’s the original (pre-“fix”) code again for reference:

                 for(i = 0; i < overlaySize.cx; i++) {
                    long i1 = (long)((double)i / numXTimes);
                    double xPercent = (double)i / numXTimes - i1;

                    // get the indeces into the data array
                    long lIndex1 = i1 + (j1 * m_DataSize.cx);
                    long lIndex2 = lIndex1 + m_DataSize.cx;

                    double yVal1, yVal2;
                    if(i1 != oldi1) {
                        yVal1 = m_DataArray[lIndex1] + //etc...
                        yVal2 = m_DataArray[lIndex1 + 1] + //etc...

oldi1 = i1; } // figure out the value double theVal = yVal1 + (yVal2 - yVal1) * xPercent;
                }

The answer lies in the realization that yVal1 and yVal2 need to retain their values through each iteration of the loop. It always worked before because the compiler ensured that each time those variables are used, even if they’re not initialized after declaration, they reference the same place in the stack on each loop iteration. By setting them to 0.0 each time, we’re breaking the reuse functionality. Finding this, we realized that is horrible! At the very least, it’s brittle, prone to break if anything went into the loop which altered the stack differently on different iterations.

Thankfully, it was easy to fix. Just move the declarations and initialize them outside the loop.

                double yVal1 = 0.0, yVal2 = 0.0;
                for(i = 0; i < overlaySize.cx; i++) {
                    long i1 = (long)((double)i / numXTimes);
                    double xPercent = (double)i / numXTimes - i1;

                    // get the indeces into the data array
                    long lIndex1 = i1 + (j1 * m_DataSize.cx);
                    long lIndex2 = lIndex1 + m_DataSize.cx;


                    if(i1 != oldi1) {
                        yVal1 = m_DataArray[lIndex1] + //etc...

yVal2 = m_DataArray[lIndex1 + 1] + //etc...
                        oldi1 = i1;
                    }

                    // figure out the value
                    double theVal = yVal1 + (yVal2 - yVal1) * xPercent;
                                
                  }

I don’t know who wrote the brain-dead code in the first place, but…wow.

Anyway, lessons learned?

  1. Test a change like this–I had put some asserts there because I didn’t fully understand what was going on, but it was so long until I ran the code after making the change that I had mostly forgotten about the change.
  2. Turn on strict compiler settings from the get-go. Make it force you to be ultra-precise. It can be VERY painful changing 120,000 lines of C++ code to be warning-free at L4. (But we did it!)
  3. Implement and change separate things separately. While removing compiler warnings, we also converted the codebase to Unicode–most places were using _T(“”), but a few places such as file handling needed special attention. That distracted from finding this problem sooner (“Could it be a file reading problem?”)

Shout-out to Sweet St Music Technology

I want to thank Chuck Brown of Sweet St. Music Technology for sponsoring my Buy Me a Lego campaign. I took a look around his site, interested as I was, because I’m an amateur musician myself (I play piano). I used to play alto sax in middle school, but never became great at it.

Anyway, Sweet St. has a large collection of band instruments, recording gear, studio gear, DJ equipment, guitars, digital pianos, and more–you name it. I liked looking through the band instruments–took me back. And the digital pianos. But if you need anything at all, take a look.

Technorati Tags: , , , ,

Some more stores at BrickLink

I received a couple more donations (for http://www.BuyMeALego.com) from stores at BrickLink–thanks guys!

First, eBricksOnline for a wonderful $25.00 donation! thanks! They also gave me a coupon to their store.

And also, Ash’s Extras, for a $2.00 donation. Thank you very much!

So check them out if you need some Lego bricks.

 

Technorati Tags: , , ,