MarshallSoft

Windows Standard

Serial Communications

for PowerBASIC

Programmer's Manual


(WSC_4PB)


Version 5.0

January 18, 2010.



This software is provided as-is.
There are no warranties, expressed or implied.



Copyright (C) 2010
All rights reserved



MarshallSoft Computing, Inc.
Post Office Box 4543
Huntsville AL 35815


Email : info@marshallsoft.com

Web : www.marshallsoft.com


MARSHALLSOFT is a registered trademark of MarshallSoft Computing.




TABLE OF CONTENTS


1 Introduction
1.1 Features
1.2 Documentation Set
1.3 Example Program
1.4 Installation
1.5 Uninstalling
1.6 Pricing
1.7 Updates
2 Library Overview
2.1 Dynamic Link Libraries
2.2 Keycode (License Key)
2.3 Win32 STDCALL and DECLSPEC
2.4 Using Threads
2.5 Limitations on COM Ports
2.6 Error Display
2.7 Waiting for New Serial Data
2.8 SioEvent Logic
2.9 Virtual Serial Ports
2.10 Adding WSC to a PowerBASIC program
2.11 PowerBASIC Declaration Files
3 Compiler Issues
3.1 PowerBASIC Console Compiler
3.2 PowerBASIC DLL Compiler
3.3 PowerBASIC Windows Compiler
3.4 Compiling WSC Source
3.5 Compiling Example Programs
4 Example Programs
4.1 WSCVER
4.2 SIMPLE
4.3 SIMPLE2
4.4 SELFTEST
4.5 FINDER
4.6 DIALER
4.7 THREAD
4.8 DEVICE
4.9 XMS and XMR
4.10 YMS and YMR
4.11 ECHOPORT
4.12 RS485
4.13 PORTS
4.14 EventW
4.15 W_HELLO
4.16 W_DEVICE
4.17 W_XMS and W_XMR
5 Revision History

1 Introduction

The Windows Standard Serial Communications Library for PowerBASIC (WSC4PB) is a toolkit that allows software developers to quickly develop serial communication applications in PowerBASIC.

The Windows Standard Serial Communications Library (WSC) is a component DLL library used to create serial communications programs that access data from a serial port using RS232 or multi-drop RS422 or RS485 ports. WSC also supports virtual serial ports using Bluetooth serial and USB to serial converters. The WSC component library uses the Windows API for all communication and can be used to easily write applications to control serial devices such as barcode scanners, modems, lab instruments, medical devices, USB serial devices, scales, GPS navigation, etc.

The Windows Serial Communications Library for PowerBASIC (WSC4PB) component library supports and has been tested with all versions of the PowerBASIC Console Compiler (PBCC), PowerBASIC DLL Compiler (PBDLL), and PowerBASIC Windows Compiler (PBWIN). WSC4PB includes numerous PowerBASIC example programs with source that demonstrate serial port communications functions.

The WSC SDK runs under 16-bit and 32-bit Windows (Windows 95, Windows 98, Windows ME, Windows 2000, Windows 2003, Windows NT, Windows XP, Windows Vista and Windows 7) as well as 64-bit Windows (Windows Vista 64 and Windows 7). A Win32 DLL is provided with WSC4PB. (Win16 and Win64 DLLs are available). The Windows Standard Communications Library SDK DLLs (WSC64.DLL, WSC32.DLL and WSC16.DLL can also be used from any development environment (Visual Basic, C++, Delphi, COBOL, Visual FoxPro, dBase, Xbase++, etc.) capable of calling the Windows API.

When comparing the Windows Standard Serial Communications Library against our competition, note that:

  1. WSC4PB is a standard Windows DLL (NOT an OCX or ActiveX control) and is much smaller than a comparable OCX or ActiveX control.
  2. A WIN32 DLL is included.
  3. WSC does NOT depend on ActiveX or Microsoft Foundation Class (MFC) libraries or similar "support" libraries.
  4. The WIN32 version of WSC is fully thread safe.
  5. The WSC functions can be called from applications not capable of using controls.

MarshallSoft also has versions of the Windows Standard Serial Communications Library for Visual C/C++ (WSC4C), Delphi (WSC4D), dBASE (WSC4DB), Visual FoxPro (WSC4FP), Visual Basic (WSC4VB), and Xbase++ (WSC4XB). All versions of WSC use the same DLLs (WSC16.DLL, WSC32.DLL or WSC64.DLL). However, the examples provided for each version are written in the specified computer programming environment.

The latest versions of the Windows Standard Serial Communications Library (WSC) can be downloaded from our web site at http://www.marshallsoft.com/serial-communication-library.htm


Our goal is to provide a robust serial communication library component that you and your customers can depend upon. A fully functional evaluation version is available. Contact us if you have any questions.


1.1 Features

Some of the many features of the Windows Serial Communications Library for PowerBASIC are:

Also see WSC versions for other supported languages:

Several PowerBASIC example programs with full source code are included. Refer to Section 4 for more details on each of the example programs.

     DEVICE   : Sends text string to serial device.
     DIALER   : Modem dialer.
     ECHOPORT : Multi-threaded console mode program echoes all input.
     FINDER   : Finds a modem connected to one of your serial ports.
     HELLO    : PowerBASIC Windows compiler (PBWIN) version of WSCVER.
     PORTS    : PowerBASIC DLL Compiler (PBDLL) example program finds ports.
     RS485    : RS485 example terminal program.
     SELFTEST : Performs COM port functionality testing.
     SIMPLE   : A simple terminal emulator.
     SIMPLE2  : Same as SIMPLE, but uses WSC32PTR.PBI.
     THREAD   : Same as SIMPLE, but implemented using a Win32 thread.
     WSCVER   : Display WSC version number.
     XMR      : Receives files via XMODEM protocol.
     XMS      : Sends files via XMODEM protocol.
     YMR      : Receives files via YMODEM protocol.
     YMS      : Sends files via YMODEM protocol.
     EventW   : Terminal program that uses SioEventWait to efficiently wait.
     W_Hello  : PBWin version of WSCVER.BAS (WSC Version)
     W_Device : PBWin version of DEVICE.BAS
     W_XMS    : PBwin version of XMS.BAS
     W_XMR    : PBWin version of XMR.BAS

WSC4PB contains 38 functions and modem control. All functions return a negative number if an error condition is detected. For more details, consult the WSC Reference Manual (WSC_REF.PDF or WSC_REF.HTM) and the RS232/422/485 Serial Communications User’s Manual (SERIAL.PDF or SERIAL.HTM). Both manuals can be accessed online at

http://www.marshallsoft.com/wsc4pb.htm


1.2 Documentation Set

The complete set of documentation consists of four manuals in two formats. This is the first manual (WSC_4PB) in the set.

The WSC_4PB Programmer's Manual is the programming language specific (PowerBASIC) manual and provides information needed to compile your programs in a PowerBASIC environment.

The WSC User’s Manual (WSC_USR) discusses language independent serial communications programming issues including modem control. Purchasing and license information is also provided.

The WSC Reference Manual (WSC_REF) contains details on each individual WSC function.

The Serial Communications User’s Manual (SERIAL) contains background information on serial port hardware.

Each manual comes in two formats:

The documentation is also provided on our web site at

http://www.marshallsoft.com/wsc4pb.htm

1.3 Example Program

The following example program segment displays the WSC registration string.

     $INCLUDE "WSC32.PBI"
     $INCLUDE "KEYCODE.PBI"

    FUNCTION PbMain() AS LONG
    Dim Code As Integer
    Dim Temp As Asciiz * 51
    Code = SioKeyCode(%WSC_KEY_CODE)
    IF Code < 0 THEN
      PRINT "SioKeyCode fails: Check value of %WSC_KEY_CODE"
      EXIT FUNCTION
    END IF
    ' display registration string
    Code = SioGetReg(Temp, 50)
    IF Code > 0 THEN
      PRINT Left$(Temp, Code)
    END IF
    END FUNCTION

Refer to section 4.0 for complete examples with source.


1.4 Installation

  1. Before installation of WSC4PB, a PowerBASIC Console Compiler (or PowerBASIC DLL Compiler) should already be installed on your system and tested.

  2. Unzip WSC4PB50.ZIP (evaluation version) or WSCxxxxx.ZIP (registered version where xxxxx is your Customer ID) using any Windows unzip program.

  3. Run the installation program, SETUP.EXE, which will install all WSC4PB files, including copying WSC32.DLL to your Windows directory.

Note that no DLL registration is required and the Windows registry is not modified.

1.5 Uninstalling

Uninstalling WSC4PB is very easy. WSC4PB does not modify the registry. First, delete the WSC4PB project directory created when installing WSC4PB. Second, delete WSC32.DLL from your Windows directory, typically C:\WINDOWS for Windows 95/98/Me/2003/XP/Vista/Win7 or C:\WINNT for Windows NT/2000.

Running the UNINSTAL.BAT batch file will also delete WSC32.DLL, MIO32.DLL, XYM32.DLL, and ASD32.DLL as described above.

1.6 Pricing

A developer license for WSC4PB can be registered for $115 (or $195 with ANSI C source code to the library DLL's). Purchasing details can be found in Section_1.3 "How to Purchase" in the WSC User’s Manual (WSC_USR.HTM). Also see INVOICE.TXT provided with the evaluation version or order directly on our web site at

    http://www.marshallsoft.com/order.htm

1.7 Updates

When a developer license is purchased, the developer will receive a new set of registered DLLs plus a license file (WSCxxxxx.LIC). The license file is needed to download updates to the registered DLL’. Updates can be downloaded for a period of one year from purchase from:


     http://www.marshallsoft.com/oem.htm

After one year, your license must be updated if you want to be able to download updates. Your license can be updated for :

If source code was previously purchased, updates to the source code can be purchased for $40 along with the DLL update.

Note that the registered DLL’s never expire.


2 Library Overview

The Windows Standard Serial Communications Library (WSC) has been tested on multiple computers running Windows 95/98/Me/XP/2003/Vista/Win7 and Windows NT/2000.

2.1 Dynamic Link Libraries

The WSC4PB serial communication library component (WSC32.DLL) is implemented as a Win32 dynamic link library (DLL). A DLL is characterized by the fact that it need not be loaded until required by an application program and that only one copy of the DLL is necessary regardless of the number of application programs that use it. Contrast this to the traditional static library that is bound to each and every application that uses it at link time.

An important advantage that DLLs have over other "popular" library formats such as VBX or OCX is that DLLs are callable by all Windows applications. Since DLLs are the building blocks of the Windows Operating System, they will not be replaced by a "newer technology".

2.2 Keycode (License Key)

The WSC32.DLL has a keycode encoded within it. Your keycode is a 9 or 10 digit decimal number and will be found in the file KEYCODE.PBI. The keycode for the evaluation version is 0. You will receive a new keycode and a set of new DLL's when registering. The KEYCODE is passed to SioKeyCode.

If you get an error message (value -108) when calling SioKeyCode, it means that the keycode in your application does not match the keycode in the DLL. After registering, it is best to remove the evaluation version of the WSC32.DLL from the Windows search path or delete it.

2.3 Win32 STDCALL and DECLSPEC

WSC32 is written in ANSI C and is compiled using the STDCALL and DECLSPEC keywords. This means that WSC4PB uses the same calling conventions and file naming conventions as the Win32 API. . In particular, function names are NOT decorated. There are neither leading underscores nor trailing "@size" strings added to function names.

Any Windows application program capable of calling the Windows API provided the proper declaration file is used may call the WSC32.DLL functions.

2.4 Using Threads

WSC4PB is thread safe, and can be used from any Windows application capable of using threads. Refer to the THREAD and ECHOPORT example programs, which demonstrate the use of threads. ECHOPORT also demonstrates the use of the WIN32 Sleep() function.

The necessary Win32 thread functions are declared in the PowerBASIC INCLUDE file "WIN32API.INC"

2.5 Limitations on COM Ports

The 32-bit version of WSC4PB (WSC32.DLL) can use any port from COM1 to COM256, provided that the port is known to Windows 95/98/NT/2000/2003/Vista/Me/XP/Win7 and there is physical hardware present.

2.6 Error Display

The error message text associated with WSC error codes can be displayed by calling SayError (refer to Errors32.bas). Each sample program contains examples of error processing.

2.7 Waiting for New Serial Data

All serial data is moved from the UART's buffer to the receive queue in memory (by the Windows serial port driver) under interrupt control. Similarly, all out going serial data is moved to the transmit queue in memory.

There are several methods that can be used to receive incoming serial data. SioMessage can be used in PBWIN programs since they have a message loop. SioGetc and SioGets can be called directly. Note that if there is no input data available, SioGetc returns WSC_NO_DATA while SioGets returns zero. Also see Section 2.8.

2.8 SioEvent Logic

SioEvent, SioEventChar, and SioEventWait will block until the specified event occurs. If a call to SioEvent, SioEventChar, or SioEventWait is placed in a thread, then the thread will block but the application calling the thread will not.

2.9 Virtual Serial Ports

A "virtual" serial port is COM port that appears to be a real RS232 serial port to the Windows API (and thus to WSC), but is in reality a COM port emulator.

The two most common virtual ports are those created for USB/serial port converters and Blue Tooth. WSC will work with USB to serial port converters and with Bluetooth serial.

More information about Virtual serial ports can be found in Section_2.12 of the WSC User’s Manual (WSC_USR). (http://www.marshallsoft.com/wsc_usr.htm#Section_2.12 )

2.10 Adding WSC to A PowerBASIC Program

In order to add WSC to a PowerBASIC program, add

     $INCLUDE "WSC32.PBI"
     $INCLUDE "KEYCODE.PBI"

after any other $INCLUDE statements. Then add

     Code = SioKeyCode(%WSC_KEY_CODE)
     If Code < 0 Then
       '... display error code to user here...
       EXIT FUNCTION
     END IF

as the fist executed WSC function.

2.11 PowerBASIC Declaration Files

WSC constants are defined and all WSC functions are declared in the file WSC32.PBI. WSC32.PBI is included in all of the example programs except for SIMPLE2.BAS.

Two of the WSC functions (SioPuts and SioGets) have alternate declarations in the file WSC32PTR.PBI. The alternate declarations allow greater flexibility in how strings are handled in your PowerBASIC program. For an illustration, see the example program SIMPLE2.BAS.


3 Compiler Issues

The WSC4PB library supports and has been tested with the PowerBASIC Console Compiler (PBCC), PowerBASIC DLL Compiler (PBDLL), and PowerBASIC Windows Compiler (PBWIN).

Please examine the WSC32.PBI file. Note that %COM1 has numerical value zero, not one. The user must assume the responsibility for passing the correct information when calling WSC4PB functions

3.1 PowerBASIC Console Compiler (PBCC)

Most of the example programs are written for the PowerBASIC Console Compiler (PBCC). Be sure to read the comments at the beginning of each example program. Also see section 4.0 "Example Programs" below.

3.2 PowerBASIC DLL Compiler (PBDLL)

WSC functions can be called from programs written for the PowerBASIC DLL Compiler (PBDLL). The same DLL (WSC32.DLL) is used for both PowerBASIC and Visual Basic. WSC functions are defined in WSC32.PBI for PowerBASIC and in WSC32.BAS for Visual Basic. The Visual Basic version can be downloaded from www.marshallsoft.com/wsc4vb.htm See the PORTS.BAS example program.

3.3 PowerBASIC Windows Compiler (PBWIN)

WSC functions can be called from programs written for the PowerBASIC Windows Compiler (PBWIN). There are no differences in how WSC functions are called in programs written in any of the Windows PowerBASIC compilers.

3.4 Compiling WSC Source

WSC32.DLL is written in standard ANSI C (WSC32.C), and has been compiled using Microsoft Visual C/C++ with the STDCALL and DECLSPEC compiler keywords. Source code for the WSC library can be purchased at the same time as a WSC developer license is purchased.

WSC32.C may also be compiled using Borland C/C++ or Watcom C/C++ compilers. If you recompile WSC32.C using Borland or Watcom compilers, the resulting WSC32.DLL can only be used by applications compiled with the same compiler, unless the STDCALL and DECLSPEC keywords are specified.

For more information on the C/C++ version of WSC, download the latest version of WSC4C from our web site at http://www.marshallsoft.com/wsc4c.htm

3.5 Compiling Example Programs

Compiling programs using the PowerBASIC Console Compiler is very easy. For example, to compile SIMPLE.BAS, type

     PBCC SIMPLE.BAS

at the command prompt. If your program requires access to any Windows API functions, you must include the path on the command line. For example, assuming that you have installed PBCC at C:\PBCC, to compile the ECHOPORT.BAS program, type (the "-MT" is for Multi-Tasking support)

     PBCC ECHOPORT.BAS -IC:\PBCC\WINAPI -MT

WSC4PB functions can also be called from PBDLL programs. See the PORTS.BAS example.

4 Example Programs

The example programs are designed to demonstrate the various capabilities of WSC4PB. The best way to become familiar with WSC4PB is to study and run the example programs.

4.1 WSCVER

WSCVER ("WSC Version") is a PBCC example program displays the WSC version number. This is the first program to compile and build since it versifies that WSC32.DLL is installed properly. Also see the HELLO.BAS (PBWIN) example program.

4.2 SIMPLE

SIMPLE is a very simple serial communications program using WSC4PB. Everything that is typed on the keyboard is sent to the serial port, and everything incoming from the serial port is displayed on the screen.

The easiest way to test SIMPLE is to connect to a modem. Typing 'AT' should result in an 'OK' being displayed.

A null-modem cable can also be used to connect two computers together with their serial ports. Run SIMPLE on both machines. Whatever is typed on one machine will be displayed on the other.

4.3 SIMPLE2

SIMPLE2 is the same program as SIMPLE, except that it uses WSC32PTR.PBI rather than WSC32.BPI, in which alternate definitions of SioPuts and SioGets are used.

4.4 SELFTEST

SELFTEST performs a serial port I/O functionality test. Either a pair of ports on the same computer (using a null modem cable) or a single port (using a loopback adapter) can be tested.

Refer to LOOPBACK.TXT for an explanation of how to make a loopback adapter (without tools!).

4.5 FINDER

The FINDER program searches for a connected modem. Your modem must be connected to one of COM1, COM2, COM3, or COM4, and must be turned on.

FINDER takes no arguments. After connecting your modem to one of your serial ports, type

               FINDER

4.6 DIALER

The DIALER programs dials up a specified host, such as a Bulletin Board System (BBS).

4.7 THREAD

The THREAD example program is similar to SIMPLE, except that it uses a Win32 thread. Note that the PowerBASIC thread function blocks awaiting serial input.

4.8 DEVICE

The DEVICE example program is designed to send a text string to a serial device. A carriage return is appended to the end of the string.

The DEVICE program can be used to send commands to serial devices which use ASCII commands, such as bar code readers, XY-plotters, etc.

Also see W_DEVICE below.

4.9 XMS and XMR

XMS (XMODEM Send) and XMR (XMODEM Receive) are programs that send and receive files using the XMODEM protocol.

Also see W_XMS and W_XMR below.

4.10 YMS and YMR

YMS (YMODEM Send) and YMR (YMODEM Receive) are programs that send and receive files using the YMODEM protocol.

4.11 ECHOPORT

The ECHOPORT program echoes characters incoming on COM1 and COM2 using threads. To use,

1. Connect COM1 or COM2 to another computer using a NULL modem cable.
2. Start SIMPLE on the other computer(s) at 38400 baud.
3. Start ECHOPORT. Anything transmitted from the other computer is echoed back.

4.12 RS485

The RS485 program is a simple terminal emulator using a RS485 port in which RTS is raised before transmitting and dropped afterwards.

4.13 PORTS

The PORTS example program demonstrates how to call DLL's created by the PowerBASIC DLL compiler from (32-bit) Microsoft Visual Basic. PORTS.BAS is compiled by

     PBDLL PORTS.BAS

You must also compile the Visual Basic program PORTS.FRM by loading PORTS.VBP in Visual Basic version 4.0 or above.

4.14 EventW

EventW is a PBCC terminal program. It works exactly like SIMPLE and SIMPLE2 except that SioEventWait is used to efficiently wait for new incoming data.


4.15 W_HELLO

W_HELLO is a PowerBASIC for Windows (PB/WIN) example program similar to WSCVER. It displays the WSC version number.

4.16 W_DEVICE

W_DEVICE is a PowerBASIC for Windows (PB/WIN) example program similar to DEVICE.

The W_DEVICE example program is designed to send a text string to a serial device. A carriage return is appended to the end of the string.

The W_DEVICE program can be used to send commands to serial devices which use ASCII commands, such as bar code readers, XY-plotters, etc.

4.17 W_XMS and W_XMR

W_XMS (XMODEM Send) and W_XMR (XMODEM Receive) are PowerBASIC for Windows (PB/WIN) programs that send and receive files using the XMODEM protocol.


5 Revision History


NOTE: Version 2.3 was the first PowerBASIC version.


Version 2.3: August 3, 1998.

Version 2.4: May 24, 1999

Version 3.0: September 8, 2000

Version 3.1: May 15, 2001.

Version 3.2: August 8, 2002.

Version 4.0: December 2, 2003.

Version 4.1: August 12, 2004

Version 4.2: March 28, 2006.

Version 4.3: October 2, 2007.

Version 4.4: February 5, 2009

Version 5.0: January 18, 2010