Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MSComm32 to log a comm port 1

Status
Not open for further replies.

mcoupal

Technical User
Jul 9, 2001
61
US
I have been trying to use the MSComm32.OCX to log input that is being sent to Com2 by another program. My goal is to store each line of data sent to the port as a record in a table.

1. I set the port settings and open the port open .init of the form and leave the port open.

2. I have a timer running every five seconds which appends the OLE Comm object's .INPUT to a table's MEMO field. I close and reopen the Com port to flush the buffer.

3. I then copy the memo field to a .TXT file using the COPY MEMO command. Into a separate table I append ('TYPE SDF') from the .TXT file. This helps prevent chopping off the 'lines' of data sent (approx. 80 characters).

It seems that my .Input buffer is always empty or I only grab pieces of data. A line of text is sent to the port approximately once every four seconds. I have played with the Rthreshold property of the OLE Comm object and the InputLen property (I tried both 0 and 1).

Any suggestions on methodology? Or are there samples of this same type of program?

Thanks!
 
Some sample code for accessing serial data in VFP using MSCOMM32 can be found in the following:
- HOWTO: Receive from the Serial Port by Using MScomm32.ocx.
Also useful may be
- HOWTO: Send to the Serial Port by Using Mscomm32.ocx.
And of course,
- HOWTO: Transmit and Receive Binary Data using MSCOMM32.

Rick
 
Try using a delay between sending the string to the port and reading the serial port buffer.

I had the same problem using a serial port device. The MSComm32 control worked fine when I polled my Modem Port status as a test, but when I switched the CommPort setting back to my serial port device, I would receive pieces of data or nothing. Inserting the delay seemed to fix everything.

Hope this helps,

Jacob
 
We have a phone system that outputs records through a serial port for each call made. I wrote a little program in FoxPro to receive the data and put each call into a record. I used a timer set to read the port every 2 seconds, add records until there are no more CR+LFs left in the input string, and store the remaining string in a form property. Each iteration of the timer event would add whatever it found in comm.input to what was in the form property.

The alternative (which I would probably use were I to rewrite it from scratch) would be to use the OnComm event of the MSComm32 object to tell you that there is data instead of a Timer to check if there is.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top