Products Support Sales Company Scott Edwards Electronics, Inc.
 

Serial LCD DLL for 32-bit Windows

updated: December 10, 1999

Thousands of users have successfully interfaced our serial displays to everything from BASIC Stamps to high-end workstations. For most, the hardest part is determining how to configure and use the serial port with their programming language. This app note presents an ultra-simple dynamic link library (DLL) for Windows (95/98/NT/2000) computers that should allow any programming language that can use DLLs to talk to our displays.

Fine Print: This software is presented free to our customers for their own private, non-commercial use. Scott Edwards Electronics, Inc. accepts no liability for any consequences of its use, performance, or non-performance. Use this software at your own risk.

While we encourage you to report any problems you encounter with this software, we cannot provide tech assistance with the DLL-calling mechanism for the various Windows programming languages. Some provide no, partial, or buggy DLL support.

Installing the DLL

A DLL is a library of software functions that can be loaded and used by a program running on your Windows computer. Much of what we think of as the "Windows operating system" is made up of many DLLs.

The serial display DLL is a single, small (less than 30kB) file. To install it, just drop it into the folder "C:\Windows\System".

Using the DLL

Just five functions make up the serial display DLL:

  • SER_OPEN(port,baudrate) --Set up the comm port (1-8) for the specified baud rate (1200, 2400, 4800, or 9600). The port must be opened before data can be sent.
  • SER_SEND(textString$) --Send textString$ out via the serial port. Control characters can be embedded in the textString$ by enclosing their ASCII codes in < > brackets; e.g., < 13 > sends ASCII 13, which is the carriage return code. The function can also send multiple codes separated by commas, and recognize certain named codes; details below.
  • SER_RAWSEND(textString$) --Send textString$ out via the serial port. Same as SER_SEND above, but does not look for embedded codes enclosed in < > brackets.
  • SER_VERSINFO() --Return the version number and release date of the DLL. During program development lets you check to see whether the DLL is the most current version. As new displays are released, we will add new named codes to the SER_SEND feature.
  • SER_CLOSE() --Close the serial port.

Using the DLL just consists of calling SER_OPEN at the beginning of your program; using SER_SEND or SER_RAWSEND to send data and instructions to the display; then calling SER_CLOSE when your program is done. You cannot use SER_SEND or SER_RAWSEND if you have not called SER_OPEN, or if you have previously used SER_CLOSE. You should never allow your program to end without calling SER_CLOSE, as this will leave the port open, preventing its use by other programs until the computer is rebooted.

The SER_OPEN and SER_CLOSE functions return TRUE (-1) if successful, or FALSE (0) if not. If, as in our example, you don't want to use the return values, most languages allow you to Call the functions, which discards the result. A really robust program should always at least check for success of the SER_OPEN since users often select nonexistent comm ports when configuring software.

Visual BASIC Program Example

It's fair to say that Visual BASIC is a popular Windows language, so that's what we used to create a demo for the DLL. The details of declaring and calling DLLs from other languages are in their respective user manuals--we cannot provide tech support on this subject.

If you've never called a DLL from your programming language before, read the manual thoroughly, and try the idea out with some other DLL.

Here's a screenshot of the demo program:

Here is the entire code-window listing of the example program, which was written in VB6:

Private Declare Function SER_OPEN& Lib "SERSEN04.DLL" (ByVal commPort&, ByVal baudRate&)
Private Declare Function SER_CLOSE& Lib "SERSEN04.DLL" ()
Private Declare Sub SER_SEND Lib "SERSEN04.DLL" (theString$)
Private Declare Sub SER_RAWSEND Lib "SERSEN04.DLL" (theString$)
Private Declare Function SER_VERSINFO$ Lib "SERSEN04.DLL" ()


Private Sub Command1_Click()
' Code for the "Send" button.
  Call SER_OPEN(2, 9600)
  SER_SEND (Text1.Text)
  Call SER_CLOSE
End Sub

Private Sub Command2_Click()
' Code for the "Version" button.
  Text1.Text = SER_VERSINFO$()
End Sub

Download and Run the VB Example

Click here to download a small ZIP file containing the DLL and VB example programs. This is version 0.1, December 10, 1999.

  • UnZIP the file and place the DLL (SERSEN04.DLL) into C:\Windows\System
  • Place the VB files into a folder that's convenient to access from VB
  • Open the project with Visual BASIC, and pull up the Code window (Menu item View - Code)
  • Edit the instruction Call SER_OPEN(2, 9600) subsitituting your comm port number for "2"
  • Connect a serial display to the comm port, configure for 9600 baud, apply power
  • Run the program

SER_SEND and Special Characters

Before the SER_SEND function sends a string to the serial port, it searches for text between pairs of < > brackets and converts that text to ASCII codes. This makes it easier to construct strings containing control characters.

For example, in VB, to tack a carriage return onto the end of a string, you would write:

  • SER_SEND("Example string with carriage return" + CHR$(13))

SER_SEND provides several alternative ways to express the same thing:

  • SER_SEND("Example string with carriage return<13>") ' by ASCII code
  • SER_SEND("Example string with carriage return<CR>") ' by name
  • SER_SEND("Example string with carriage return<M>" ) ' by control code

All of these examples would send the demo phrase followed by ASCII 13, the carriage-return character. The advantage of the SER_SEND method is that it's more readable and possibly less prone to typos during programming than concatenating a bunch of CHR$() functions. Furthermore, you can combine multiple codes within one set of tags:

  • SER_SEND("<65,66,67,68,13>") ' Sends ABCD and carriage return.

(Note that 65 is the ASCII code for A, 66 is B... and so on.)

Since the documentation for our serial displays gives instructions in terms of their ASCII codes and/or control-characters, this feature should make your programming life easier. But wait, there's more!

SER_SEND also understands descriptive names for many of the instructions used by our products. (Most of our products' instructions overlap.) Here are some examples:

  • SER_SEND("<BPI_CLS>Cleared.") ' Clear screen (BPI- and BPK- series) then print.
  • SER_SEND("<CLEAR>Cleared") ' Clear screen (BPP, VFD, ILM, SGX, BGX) then print.

We've broken out the various named instructions into several separate pages by category and/or type of display:

Sending Variables with SER_SEND

The <> tags that SER_SEND() use to identify special characters is great for constants, but doesn't help with variables. These will still have to be sent the old-fashioned way; by concatenating a character string [CHR$()] function to a string. For example to draw a line from A,B to C,D (where A,B,C, and D are all variables) you might write VB code like this:

  • SER_SEND( "<LINE>"+CHR$(A+64)+CHR$(B+64)+CHR$(C+64)+CHR$(D+64) )

For those unfamiliar with the SGX and BGX displays, adding 64 to a value allows it to be sent as a single-byte shortcut, rather than a numeric string. This saves transmission time.

Final Notes

The DLL described here is not threaded, meaning that it halts your program's execution for the amount of time required to process and send a string. This time is depends on the baud rate and the length of the string (after processing any bracketed text, in the case of SER_SEND). Use the following approximate values to estimate time required:

  • 1200 bps: 8.3 milliseconds (ms) per byte (character)
  • 2400 bps: 4.2 ms/byte
  • 4800 bps: 2.1 ms/byte
  • 9600 bps: 1 ms/byte

Typical transmissions to serial displays are quite short, so the times required are very brief; you can rewrite every character of a 4x40 text LCD screen in under 2/10ths of a second. Just bear in mind that if your program makes unusually frequent updates of the display and/or uses a slow baud rate, there may be a noticeable slowdown in Windows' response. In this case, consider using a fancy, threaded/buffered serial communication control or library. See www.lvr.com for links to information on advanced serial-port programming.

That said, 99% of applications will do just fine with our easy-to-use DLL.

All trademarked names used in this document are the property of their respective holders.

Scott Edwards Electronics Inc.
1939 S. Frontage Rd. #F, Sierra Vista, AZ 85635
phone 520-459-4802; fax 520-459-0623
e-mail info@seetron.com