Join Now Join Now Home

SPARK Project #3, Post#4



In my previous post, I finally started to make some progress with my Windows Embedded CE project. I was able to get a simple test application running which could send and receive messages via a serial port on my iCop eBox 2300 computer. I first sent messages to a host computer using an RS232 crossover cable. Once I confirmed that there were no problems sending and receiving messages or changing the baud rate, I cut the cable and plugged in a pair of XBee modules in place of the crossover cable. I wasn't ready to install custom device drivers in my Windows Embedded CE operating system image, so I used an XBee serial explorer ordered from SparkFun to connect an XBee to the eBox computer. After confirming that everything was working as expected, I was ready to modify the serial port test application to run my wireless light controller.


The secret sauce is my home-brew Arduino clone running from a capacitive power supply.
More about that next week!

Before I continue, I want to briefly reflect on some of the steps required to get my program to finally work. I initially suspected that I had a serial port buffer overrun problem, since I couldn’t send messages longer than 16 characters. When I noticed that my serial port test program would hang at the end of a serial port transmission of any length, I started to think that the problem may be interrupt related instead of buffer related. If the serial port call was waiting for a “buffer empty” signal before it returned control to my program, hanging at the end of a transmission meant that it never got that signal. Since I had been editing a number of serial port settings in the BIOS and registry while trying to disable or reroute serial debugging messages, I might have inadvertently modified a critical registry key. Rather than retrace my steps and restore the factory settings, I started with a clean copy of the BSP to build the operating system image. I had also notice that many of the build directories for my Visual Studio 2005 installation were pointing to a more recent version of Visual Studio on my computer. After mapping all the directories to the correct location, I rebuilt the operating system using clean copies of all the drivers and BSP.

Finally, everything worked flawlessly when I tested the new operating system with the simple Visual Basic serial port terminal example from Samuel Phung's Windows Embedded CE 6.0 website.

I haven’t done much programming with Visual Basic, but VB seems to be good for very simple and quick GUI prototyping. I was able to easily modify the program to take inputs from three GUI buttons and send messages out of the serial port:



The code is shown below:

Private Sub btnLight1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLight1.Click
       
        If VBSerial.IsOpen Then
            If (currentLight And Light1On) = 0 Then
                serOut = Chr(currentLight + Light1On)    ' Add Light1On command to serial token
                currentLight = currentLight + Light1On  ' Add Light1On state to state variable
                btnLight1.BackColor = Color.Yellow
            Else
                serOut = Chr(currentLight - Light1On)
                currentLight = currentLight - Light1On
                btnLight1.BackColor = Color.Gray
            End If
            serOut = msgHeader + msgAddr + serOut            ' Add the message header and address strings to serial token
            VBSerial.Write(serOut)
            txtMsg.Text = serOut
           
        End If
    End Sub


When the button is pressed, a state variable is checked to see if the light corresponding to the button is on or off. If it is currently off, the command to turn it on is sent to the serial port, the state variable is updated, and the button background color is changed to yellow. If the light was on when the button was pressed, the off command is sent, the state variable is updated, and the background color is changed to gray.

I had to think about sending the command data in the appropriate format. My Arduino code is looking for byte values not ASCII text, but the VBSerial.Write() function needs a string as an argument. This is done very easily using the CHR() function.


Once that was done, I downloaded my code and was remotely turning lights on and off.
Woohoo! The future is bright indeed. Stay tuned for more next week.

Commentary

Text Comments (0)


2010 Challenge
NOW OPEN!
Round 1 in:
  Days
  Hours
  Minutes
  Seconds


Key Dates
  • April 27
    embeddedSPARK
    2010 SUMMER
    Challenge Opens
  • June 15
    R1 Closes
  • June 22
    R1 Winners
    Announced
  • August 31
    R2 Closes
  • September 7
    Winners/Finalists
    Announced
  • September 21
    Three Finalists Compete
    LIVE on Stage at
    ESC in Boston
This site hosted for Microsoft by Smooth Fusion, Inc.