-->
Download WSC4VB
WSC4VB Programmer's Manual
WSC User's Manual
WSC Reference Manual
The purpose of this article is to demonstrate how you can perform serial port communication in the VBA (Visual Basic Applications – script.
This topic describes how to use
My.Computer.Ports
to receive strings from the computer's serial ports in Visual Basic.To receive strings from the serial port
- Initialize the return string.
- Determine which serial port should provide the strings. This example assumes it is
COM1
. - Use the
My.Computer.Ports.OpenSerialPort
method to obtain a reference to the port. For more information, see OpenSerialPort.TheTry...Catch...Finally
block allows the application to close the serial port even if it generates an exception. All code that manipulates the serial port should appear within this block. - Create a
Do
loop for reading lines of text until no more lines are available. - Use the ReadLine() method to read the next available line of text from the serial port.
- Use an
If
statement to determine if the ReadLine() method returnsNothing
(which means no more text is available). If it does returnNothing
, exit theDo
loop. - Add an
Else
block to theIf
statement to handle the case if the string is actually read. The block appends the string from the serial port to the return string. - Return the string.
Example
This code example is also available as an IntelliSense code snippet. In the code snippet picker, it is located in Connectivity and Networking. For more information, see Code Snippets.
Compiling the Code
This example assumes the computer is using
COM1
.Robust Programming
This example assumes the computer is using
COM1
. For more flexibility, the code should allow the user to select the desired serial port from a list of available ports. For more information, see How to: Show Available Serial Ports.This example uses a
Try...Catch...Finally
block to make sure that the application closes the port and to catch any timeout exceptions. For more information, see Try...Catch...Finally Statement.See also
Windows Standard Serial Communications Library for Visual Basic
The Marshallsoft serial communications component library for Visual Basic(WSC4VB) is a serial port library basedon the Windows serial comm API. WSC4VB uses the core Windows API to communicate with any device connectedto a serial port from within a Visual Basic or VB.NET application.
A simple interface allows accessing data from a serial port using RS232 or multi-drop RS422 / RS485 serialports. WSC also supports virtual ports such as those created by Bluetooth and USB/serial converters. WSCprovides the capability to quickly write Visual Basic applications to control serial devices such as barcode scanners,modems, lab instruments, medical devices, USB serial devices, scales, GPS navigation, etc.
The component library includes 52 functions plus serial line status & control, modem control,ASCII/XMODEM/YMODEM protocols, and a good selection of VB and VB.NET exampleprograms. The library can be used with any version of Visual Basic (including Visual Studio .Net) orVisual Basic for Applications (VBA).
Features of WSC4VB include:
- Includes 64-bit (WSC64.DLL) and 32-bit (WSC32.DLL) versions.
- Free technical support and updates for one year.
- Royalty free distribution with your compiled application.
- Evaluation versions are fully functional. No unlock code is required.
- Includes 49 functions plus modem control.
- Can control any serial device (scale, barcode reader, etc.) connected to a serial port.
- Can be used from GUI mode or console mode programs.
- Can control multiple ports simultaneously.
- Can be used with virtual serial ports using Bluetooth serial or a USB to serial converter.
- Supports RS232, and multidrop RS422, and RS485 ports.
- Includes hardware and software flow control.
- Supports character peek (SioEventChar).
- Supports transmit and receive timeouts.
- Can send Windows messages on completion of events (incoming character, etc.)
- Supports any baud rate (32-bit and 64-bit versions).
- Ability to specify the parity, word size, and number of stop bits.
- Comes with ANSI emulation and ASCII, XMODEM and YMODEM.
- Supports binary and text data transfer.
- Is port re-entrant.
- State driven Xmodem and Ymodem on multiple ports simultaneously.
- Is fully thread safe.
- Supports Windows XP through Windows 10.
- Works with all versions of Microsoft Visual Studio through VS 2015.
- Works with all versions of Microsoft Visual Basic and VB.NET.
- Can be used with VBA (Visual Basic for Applications) such as Excel, Microsoft Office and Access.
- Does not depend on support libraries. Makes calls to core Windows API functions only.
- Can be used with any program in any language (C/C++,.NET, Delphi, VB, VB.NET, Foxpro, etc.) that can call the Windows API.
- License covers all programming languages. Purchase a developer license for WSC4VB and use the DLLs with any other development environment (C++, Visual FoxPro, etc).
- Implemented as a standard Windows DLL, which will work with all versions of Windows.
- Will run on machines with or without .NET installed
- Can be purchased with or without ANSI C source code to the WSC DLLs.
- Documentation online as well as in printable format.
WSC4VB can be used in the development of Win32 and Win64applications running under Windows XP through Windows 10.The evaluation version of WSC4VB is fully functional.
Current version of the Windows Std Serial Comm Lib for VB is 7.0 (September 9, 2019).Registration is $119 for email delivery ($199 with C language source code).
Order
Order Page
Links
HOMEDownload WSC4VB
WSC4VB Programmer's Manual
WSC User's Manual
WSC Reference Manual