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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Setting up RS232 Comms Port

Status
Not open for further replies.

David Higgs

Programmer
May 6, 2012
392
GB
In my application I would like VFP to communicate with a Transceiver via the RS232 Comms Port. The information exchange is occasional and very short bursts. Basically a "FA;" command is sent to the transceiver which produces a reply of "FA14250000"; this is typical of what I am trying to achieve.

I have used a small third party comms utility to check that the comms port is working ok, now I need to set up VFP comms but not too sure where to start. I understand MSCOMM32.OCX has been used but I have no idea on how to set this up or incorporate it with VFP.

Any help would be most appreciated.

Regards,
David
 
Ok, progress so far.

I now have a form with MSCOMM32.OCX set up called "mycom" and have a Command Button with the following code in the Click Event.

Code:
thisform.Mycom.output = "FA;"	&&	Send request to FT-2000 Transceiver to read "Frequency"

ft2000_freq = thisform.mycom.Input

		freq = SUBSTR(ft2000_freq,3,8)
		freq = Transform(freq,"@R 99.999.999")
		
IF LEFT(freq,1) = "0"			&&	Remove leading Zero
		freq = SUBSTR(ft2000_freq,4,7)
		freq = Transform(freq,"@R 9.999.999")
ENDIF

thisform.label1.Caption = (freq)	&&	Display Frequency on Form
The above code is communicating (both ways) with the Transceiver, however it takes two clicks of the button to actually read and display the Frequency. I guess I need to look at a "Receive Buffer"?


Regards,
David
 
You can't expect Input directly coming in.
Please reread it shows when to read Input.

You can somewhat use this comm control as is, but to make use of the events you have to put code in there, so you better create a class based on oleconrol and pick the communications control.

This is asnchronous, you only set output and input will cause oncomm events. You receive input there, not in the code you output.

Bye, Olaf.
 
Hello Olaf,

Thank you for your reply.

I've read and re-read the document but couldn't help feeling that it was a bit of an overkill for my application. As I said, basically send / receive is working, it was just a case looking at the receive buffer too soon.

I've decided to insert a "10ms timer" to give the Transceiver time to respond to the request.

Code:
DECLARE Sleep IN Win32API INTEGER nMilliseconds
Sleep(10)
Source of the code
Probably not the most efficient way of doing things but it appears to do what I want.


Regards,
David
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top