|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
|
Announcements
Chapters
Services
Feature Zones
|
IntroductionIn the spirit of Lava Lamp build monitoring and Automated Continuous Integration and the Ambient Orb, I purchased a BetaBrite one-line electronic LED sign. This two foot LED display beats the heck out of those retro-kitsch novelty build status indicators. The BetaBrite supports full text build status information in eight colors and 12 different font styles-- including animations! It's way cool; I have yet to see someone walk by my desk who isn't mesmerized by its hypnotic animation and colors. And it's not all that expensive, either. Sam's Club has the BetaBrite sign for a reasonable $160, and that includes the serial communication cable, handheld remote, and software. The BetaBrite is fully programmable via the infrared remote, but keying in long messages on the remote is a giant pain. It's a lot easier to connect the BetaBrite to your PC through a RS-232 Serial to RJ-12 cable, then use the bundled Windows software to program the sign:
The Windows software works fine, but what I really wanted was a native .NET API. So, armed with the protocol document and a functioning BetaBrite connection, I set out to write an easy to use .NET API for the BetaBrite. Understanding the BetaBrite LED SignThe BetaBrite understands a subset of the Alpha Sign Communications Protocol. We're talking about RS-232 serial communications to a device with a whopping 32 kilobytes of internal memory-- not exactly a supercomputer. So, as you might expect, the protocol is a little primitive and sometimes confusing. I spent the last week poring over the documentation; here's what I found:
ArchitectureEarly on, I made the decision to implement the API as a set of three classes:
Using BetaBrite.SignAs promised, this API is very simple to use. Here's the canonical "Hello, World" example -- assuming your BetaBrite is connected via the first serial port: Dim bb As New BetaBrite.Sign(1)
bb.Open()
bb.Display("I <extchar=heart> BetaBrite!")
bb.Close()
Now, this example cheats a bit because the The Text item is the most frequently used, and represents formatted text followed by a transition state: Dim bb As New BetaBrite.Sign(1)
With bb
.Open()
.UseMemoryText("D"c, 128)
.UseMemoryText("E"c, 128)
.UseMemoryText("F"c, 128)
.AllocateMemory()
.SetText("D"c, _
"<font=five><color=green>This is <font=seven>file D", _
Transition.Rotate)
.SetText("E"c, _
"<font=five><color=yellow>This is <font=seven>file E", _
Transition.WipeLeft)
SetText("F"c, _
"<font=five><color=red>time is <calltime>", _
Transition.RollDown)
.SetRunSequence("EDF")
.Close()
End With
If you run this code, you should see three different messages, with different colors, fonts, and transitions between the messages. Pay attention to the explicit memory allocation-- be sure you allocate enough memory for your text plus the one or two bytes of formatting codes per tag. As you may have noticed, text message strings support a set of lightweight HTML-style formatting codes, which you can find in the Text Formatting region of the The String item is a subset of text that acts like a variable: Dim bb As New BetaBrite.Sign(1)
With bb
.Open()
.UseMemoryText("A"c, 128)
.UseMemoryString("B"c, 32)
.AllocateMemory()
.SetText("A"c, "You are customer number <callstring=B>")
.Close()
End With
I didn't specify a run sequence here because file A always runs by default. The main advantage of strings is that they can be dynamically updated without making the sign "flash", so think of them as variables. They support a subset of the formatting codes that text messages support, so unless you need a variable, stick with text messages. The Picture item represents an 8-color bitmap of up to 80x7 pixels: Dim bb as New BetaBrite.Sign(1)
With bb
.Open()
.UseMemoryText("A"c, 128)
.UseMemoryPicture("B"c)
.UseMemoryPicture("C"c)
.UseMemoryPicture("D"c)
.AllocateMemory()
.SetPicture("B"c, "betabrite_picture_triangle.bmp", 35, 7)
.SetPicture("C"c, "betabrite_picture_smiley.bmp", 10, 7)
.SetPicture("D"c, "betabrite_picture_demo.bmp")
.SetText("A"c, _
"<callpic=C><callpic=C><callpic=B><callpic=C>" & _
"<callpic=C><newline><callpic=D>", _
Transition.RollUp)
.Close()
End With
Note that, unless you specify otherwise, the maximum amount of picture memory (80x7) will be allocated in that file label. Here's what you should see when this is run:
This will scroll up and be replaced by another full-size 80x7 picture of some "modern art" I created. Now, I know what you're thinking: yes, you can load any arbitrary 80x7 pixel image into the BetaBrite, in whatever file formats .NET supports. However, do not expect this to look good! 80x7 is a tiny number of pixels, and the BetaBrite has a very limited palette: essentially two reds, two greens, and four yellows (see Animated images (ala animated .gifs) isn't supported natively, but can be hacked in using the Some LimitationsI'm pretty happy with the way this API turned out, but I think it's worth mentioning a few of the things I decided not to do. Some of these might make sense as possible future enhancements, and some were intentionally avoided.
ConclusionIf you own a BetaBrite LED sign, I think you'll have a lot of fun with these classes; they make it easy to write .NET applications that support the BetaBrite sign. There are many more details and comments in the demonstration solution provided at the top of the article, so check it out. I hope you enjoyed this article. Please don't hesitate to provide feedback, good or bad! If you enjoyed this article, you may also like my other articles as well. History
|
||||||||||||||||||||||