I too found myself in the position of going on using CBuilder 6 and the free Turbopower serial port component for much longer than I expected. I had a couple of warnings about this cosy state of affairs. The first being that after getting XE I could not load the Turbopower component.
Serial I/O (RS232)
Under DOS, it was possible to directly access these ports. However, Windows 95 and above forbid direct hardware access. Therefore, this page exists to help get around windows.
Generic References
- I suggest starting with this good Tutorial.
- Here is the complete standard including the pin out, timing, and signal descriptions.
- Did you know that RS means Recommended Standard? This site also compares Simplex/Duplex and DTE/DCE. Free software shows how to write Windows 95 programs which access the serial port - comm32.zip/comm32.cpp (4kb)
- The Visual Basic help file explains how to use Comm.drv to access serial ports. (Search on serial.)
- Another tutorial and links to various rs232 related sites.
- Books and lots of very good links.
- While Windows does not normally allow you to directly access the hardware, WIN95IO.dll privides a simple work around. Unfortunately, the distribution package does not provide any examples, just 4 function prototypes. The following 2 examples may help.
- vbOut &H378, MyData%
temp% = vbInp &H378 - Many hints are available from comp.lang.basic.visual.misc.
- Hardware kits and book are available from Peter Anderson.
- The comp.arch.hobbyist FAQ contains many links on how to interface to the Serial Port, Parallel Printer, and Joystick, as well as links to information on IR Standards.
- Boondog Automation provides a number of related tutorials describing how to build your own hardware interfaces and how to write interface software. They also sell a parallel I/O, 8255-based ISA card - either as a kit or assembled.
- Information on various UARTs, includes links, pin-outs, and an overview.
- MarshallSoft provides a good FAQ explaining the UART with links to vendor specs. They also provide shareware libraries for a number of programming languages.
- This system.ini patch from Newsgroups: microsoft.public.win95.msdosapps may help you run DOS applications under Windows 95 et al.
- Portmon is a free GUI/device driver combination that monitors and displays all serial and parallel port activity on a system.
- Reynolds Electronics appears to be a basic PC hobby store. It has all sorts of Basic Stamp, PIC, and data aquisition info.
- B&B Electronics provides a variety of serial I/O devices (including a USB Data Acquisition Module - 8s/4d 12-bit ADC, 4 10-bit DAC, 8 digital I/Os, and software), books, and a pretty good free Technical Library.
- ePanorama.net provides a large number of links to all kinds of useful information - serial, parallel, IR, usb, firewire, keyboard, mouse, joystick.
- Isolated Full Duplex RS232C Interface provides schematics and a PC board for a self powered interface circuit the optically isolates the TxD and RxD lines from the PC serial port.
Visual Basic 6.0
Visual Basic Programmers Guide to Serial Communications by Richard Grier. Richard's page provides free ActiveX serial components for those that don't have MSComm32.ocx.
VB 6.0 provides VBTerm, a sample terminal emulation application under ..samplesVB98MSCOMM.
You can open a port as a file. This example, from comp.lang.basic.visual.misc, opens the printer
MS Access 97 SR-2
MS Access 97 SR-2 - Fails
On my system, the following code causes Access to hang.
I tested several variations with the same result - Without Len = 3
- With temp as a variant
- Both 'com1' and 'com1:'
- Both Input and Binary
MS Access 97 SR-2 - Works
- Set the threshold to one (1)
- When the first character is read, set a timer and add the character to the barcode
- As each additional character is read, re-start the timer
- When the timer expires, call the function of your choice and pass the completed barcode. (The example below just writes it to a component.)
- Finally, stop the timer and clear the string Barcode
- In the help, the case statement has many options. To simplify this example, I removed all but the one that reads the data.
- The only available timer is attached to the form. Therefore, it is hard to encapsulate this in a library.
- MS Access 97 SR-2 will not display the MSComm help when you click on a command and press F1 ... unless you FIRST locate and open 'C:WIN98HELPCOMCTL2.HLP'. (Your path may be different.)
- This code requires that MSCOMM32.ocx is installed on every machine that uses this feature. Simply copying the file is NOT sufficient. There are no instructions on how to do it correctly. Copying it installs the TypeLib resistry key, but not the several CLSID's or the License.
- I had everything working perfect. When I tried to demonstrate the code to my boss, NONE of the case constants were defined ... Well they were 2 hours before! (And they work fine now.)
Delphi
C++ Builder
_bios_serialcom
![Greenleaf Serial Port Ocx Greenleaf Serial Port Ocx](http://wpuploads.appadvice.com/wp-content/uploads/2015/12/Dustwun1-642x324.png)
![Greenleaf Serial Port Ocx Greenleaf Serial Port Ocx](/uploads/1/2/6/2/126295101/221937848.jpg)
At any rate, I will NOT provide copies of bios.h to anyone.
Virtual Integrated Design provides various RS-232 circuits and free software examples.
Accessing the RS232 Port in DOS using BIOS.H functions provides a summary of the allowed options/contants. There is also a program showing how to use bioscom to access ports.
Microsoft provides a Simple Example Using _bios_serialcom(). The article states that this interface tends to loose data. In order to improve the reliability, the comport needs to call an interrupt routine which moves the data to a buffer. This was easy under DOS, but generally not allowed under Windows.
Windows API
Use CreateFile to open a handle to a communications resource, such as com1 or lpt1.
Test the returned handle to verify that the port is not locked by another process.
Use GetCommState to determine the current settings, SetCommState to change the settings.
You can use BuildCommDCB to pass common parameters (baud, parity, etc.) to the DCB as a string. But you'll still need SetCommState to actually change the settings.
See the DCB help for the supported constants.
Some additional commands - TransmitCommChar, PurgeComm, FlushFileBuffers
Microsoft Platform SDK - Communication Overview, Communication Functions
The only property which is remembered between disconnects is the Baud Rate. Parity, StopBits and the like are reset each time the connection is opened. Unfortunately, both SetCommState and SetCommConfig are extremely slow. As a result, it is not practical to disconnect the comport between uses.