Article ID: 158008 - Last Review: July 13, 2004 - Revision: 3.1 How To Use MSCOMM32.OCX to Transfer Data on DBCS WindowsThis article was previously published under Q158008 On This PageSUMMARY
This article illustrates some techniques using the MSComm32.OCX control for
receiving and transmitting binary data on double-byte character set (DBCS)
Windows.
MORE INFORMATION
The Communications control, MSCOMM32.OCX, provides serial communications
for your application by allowing the transmission and reception of data
through a serial port where only a string of characters to the transmit
buffer is permitted. This feature limits you to transmitting only text-
based files.
The binary data must be converted one byte at a time to a character and then transmitted. When received, the data must be converted from a character back into binary data one byte at a time. See the REFERENCES section below for more information. On double-byte character set Windows, such as Korean, Japanese, and Chinese Windows, binary data will be corrupted if one of the binary values matches a DBCS lead character. The MSComm control will interpret this byte and the following byte as one double-byte character and return only one byte for the equivalent ASCII character. To resolve this problem, which is specific to DBCS Windows, you can implement certain encoding algorithms that can convert binary data into text data and vice versa. This article demonstrates how to convert one byte binary data into ASCII size of three characters to preserve the lead character. On the receiving end, these three ASCII characters are converted back into one-byte binary data. For example:
ASC('a') = 97 ' 97
would be transmitted as three characters:
'0''9''7'
NOTE: The sample code is reading the input file as binary. It is not necessary to convert each character to ASCII value. If you use a modem instead of RS-232 cable, you need to add some codes to establish the modem connection. For example:
WARNING: USE OF THE SAMPLE CODE PROVIDED IN THIS ARTICLE IS AT YOUR OWN RISK. Microsoft provides this sample code "as is" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose. Sample Code - Transmitter
Sample Code - Receiver
The event-driven technique generates an OnComm event when there are characters waiting in the input buffer. Also, the CommEvent property will contain a numeric 2. For the OnComm event to be triggered, you must set the Rthreshold property to a value other than its default of zero. The most common setting for the RThreshold property is 1, meaning that the OnComm event is triggered if a minimum of one character is waiting in the input buffer. In this article, the numeric 3 is being used as a value of RThreshold property because 3 characters at a time are being sent. REFERENCES
For additional information, please see the following article in the
Microsoft Knowledge Base:
194923
(http://support.microsoft.com/kb/194923/EN-US/
)
How To Trap Control Characters Using the MSComm Control
APPLIES TO
| Article Translations
|
Back to the top
