.NET (Visual Basic) CrystalFontz Socket to RS232 Service and Sample Application


New member
'PhatHack CrystalFontz 634 LCD Driver'

This is not exactly the most thrilling, or complicated bit of code you are ever likely to come across but as part of my CarPC project I want to drive a CrystalFontz 634 LCD through COM. :D

Because it's a CarPC, and therefore subject to the constraints of starting up / down as any PC I wanted to write something that was service based so I can have the LCD fire up as early as possible with at least the date and time... but also have my custom audio application drive the LCD showing relative media information.

I needed several basic features:

  • Standard text output
  • Large buffer scrolling
  • Character Flashing

I also wanted to be able to easily combine the 3 in a way that takes the load off my audio application and make life easier for generally extending the use of the LCD.

After a while nailing the basic functionality of the LCD, I finally decided upon a solution that would allow me to build all 3 functions I required into a socket based transport. I decided upon making a socket based solution as potentially I may have 3 separate applications simultaneously updating the LCD.

As I don't have my display currently backlit, it's difficult to show a sample of what I have been able to achieve with my code - based on what I want of it anyway. And it was suggested that perhaps the project may be of use/suitable for inclusion here.

I've GPL'd, commented and included all the source code I have been using whilst playing with my LCD so if it's useful to you - use it! (But I accept no responsibility for anything it does bad!) :p

It includes a lot of the first bits of code/classes I wrote to test the LCD out - basic output, basic scrolling, basic flashing....but I've tried to mark the relevant bits as obsolete in case they're useful for anyone wanting to get down to the very very basics.

If you do happen to use the code, and make any improvements upon it (which I am sure won't be difficult!) then please drop feel free to share them with me!

It's coded in Visual Basic.NET 2005 (sorry CF Tech!), and should be easily portable to both C# and 2008.

Here's a couple of snaps taken of the sample code in action, after a 15 hour testing period (before bug fixes):

...and a screenshot of the sample application:

Most importantly here's the source (a complete snapshot of my entire dev. folders including binaries):

Communication with the Service

The service is hard-coded to listen on port 6456 of 'localhost'. There's no specific reason for this other than it's 1 more than 6455.

Once connected to the service you then send a series of commands to it, to connect and interact with the LCD display. In the case of the sample application, here's a demonstration of the commands sent:

start /port 1 /baud 19200 /parity 0 /stopbits 1 /databits 8 /dtrOn 1 /rtsOn 1
content /line 0 /style [0]Album: [2*13]
content /line 1 /style [0]Track: [2*13]
content /line 0 /scroll 0 /value The Prodigy: Experience....
content /line 1 /scroll 0 /value Everybody in the Place (Let's Go!)
content /line 3 /style [0] {time}  [1] {16} [0]00:00

Connects the service to an LCD on COM port 1 using the specified COM settings
Clears the connected LCD
Sets up the display to display static text on line 1, followed by 13 scrolling characters
Sets up the display to display static text on line 2, followed by 13 scrolling characters
Sets the value for the first scrolling element on line 1 to the specified value
Sets the value for the first scrolling element on line 2 to the specified value
Sets up the display to display static text on line 1 containing the date, followed by a flashing 'play' symbol, followed by static text representing an elapsed time

Then, on 100 millisecond timer:

After 100, 200, 300 and 400 milliseconds:

scroll /line 0 - which modifies the scroll position of element 0 on line 1 (moves the display 1 character along)
scroll /line 1 - which modifies the scroll position of element 0 on line 2 (moves the display 1 character along)

After 500 milliseconds:

flash /line 3 - which toggles the flash state (on off) of any flashing elements on line 3
content /line 3 /static 0 /value {time} - which modifies static text element 0 on line 3 to the current time
content /line 3 /static 1 /value '<x>' - which modifies static text element 1 on line 3 to '<x>' which is the elapsed time since starting the demo

Every 100 milliseconds:

update - which forces the LCD to refresh

And there you have it! It can manage multiple-displays too, and can handle multiple-client-connectivity-per-display on the basis that your multiple clients are intended to work side by side and not cause each other problems!
Looking for additional LCD resources? Check out our LCD blog for the latest developments in LCD technology.


New member
I found a few bugs that cause a few minor issues the first time an LCD display is started after power up - but those have all been sorted.

I've been away for a little while as I had to re-build my machine which is now running Windows 7 x64, and I'm glad to say the service works without any issues.

I've also completed the phase 1 bolt-in to my CarPC application in the driver's current state (just missing configuration options in the application to complete the bolt-in), and have stress tested it for over 20 hours on VMWare workstation 6.5:

So now I can move on to Phase 2, looking at the backlighting control.
So far, I'm very happy with the results... :)