You are currently offline, waiting for your internet to reconnect

How to send to the serial port by using Mscomm32.ocx

This article was previously published under Q139526
This article describes the settings necessary to send data to the serialport by using Mscomm32.ocx. Mscomm32.ocx ships with Microsoft Visual FoxPro ProfessionalEdition. It can be used on computers that are running Microsoft Windows 95 and later versions of Windows.
The most frequently used properties to send data to the serial port usingthe mscomm control are as follows:


The CommPort property specifies the communications port number. A numericproperty that corresponds to the Comm port. By default, this property isset to 1 corresponding to com1. Valid values are 1, 2, 3, or 4 depending onthe serial ports installed on the computer and their configuration.


The Settings property configures the baud rate, parity, data bits, and stopbits for the serial port. The Settings property is a character string that contains individual comma-separated values. By default, the Settings property is as follows:
This property corresponds to 9600 baud, no parity, 8 data bits, and 1 stop bit.

The following baud rate values are valid: 110, 300, 600, 1200, 2400, 4800, 9600 (default), 14400, 19200, 28800, 38400, 56000, 57600, 115200, 128000, 256000.


The PortOpen property specifies a logical value that controls whether ornot the serial port is open and active. Once the previous properties areset to begin using the serial port, you can set this property to true.


The Output property is assigned the string of characters to be sent to theserial port. To output the string "Hello World" to the serial port afterthe previous properties are set, use the following command:
   myform.mycomm.output = "Hello World"				
Other properties that may be also be needed depending on the applicationare as follows:


The CommEvent property contains a value that represents the most recentcommunications event or errors.


The Sthreshold property specifies the minimum number of characters in theoutput buffer that are sent.


The OutBufferCount control returns the number of characters waiting in thetransmit buffer. This should always be zero if the Sthreshold property iszero. Setting the OutBufferCount property to zero will clear the transmitbuffer.


The OutBufferSize property specifies the size of the transmit buffer. Bydefault, this buffer is 512 bytes. The larger the transmit buffer, the lessmemory available to other applications. Slow baud rates and large textstrings written to the serial port may mean you need to make this valuelarger.

Following is a sample that shows how to set up the comm control and dialthe phone number 555-1234 by using the standard Hayes Modem commands.
   PUBLIC ComForm   ComForm = CREATEOBJECT('Form')   ComForm.AddObject("Testcom","Olecontrol","MSCOMMLib.MSComm")   ComForm.Testcom.CommPort = 2 && Use Comm2, The second Serial Port.   ComForm.Testcom.Settings = "14400,N,8,1"  && 14.4 Kbaud, No Parity,                                             && 8 data Bits, 1 Stop Bit   ComForm.Testcom.PortOpen = .T.   ComForm.Testcom.Output = "ATDT555-1234" + chr(13) && Dialing the number   * The chr(13) is needed to complete the modem command sequence   ComForm.Testcom.PortOpen = .F.   ***** End Code *****
Note If you use this in an application and then distribute the application by using the Visual FoxPro Setup Wizard, you may see the following error when you run the application:
Program Error OLE error code 0x80040112: Appropriate license for this class not found.
If this error occurs, see the following article in the Microsoft Knowledge Base:
192693 License error with ActiveX control added at run-time

Article ID: 139526 - Last Review: 04/01/2008 17:16:06 - Revision: 4.2

  • Microsoft Visual FoxPro 3.0 Standard Edition
  • Microsoft Visual FoxPro 5.0 Standard Edition
  • Microsoft Visual FoxPro 6.0 Professional Edition
  • Microsoft Visual FoxPro 7.0 Professional Edition
  • Microsoft Visual FoxPro 8.0 Professional Edition
  • Microsoft Visual FoxPro 9.0 Professional Edition
  • kbcode kbhowto KB139526
" src="" '="">