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

Can we really use fgets() to read COMM port?

Status
Not open for further replies.

wcglorioso

Programmer
Jul 23, 2003
30
PH
Here is the description of the FGETS( ) Function

Returns a series of bytes from a file or a communication port opened with a low-level file function until it encounters a carriage return.

I am a little into serial communications programming. I know I have to configure the host to match the serial device.

I try to avoid using OCX (the Mscomm32.ocx) as much as possible. I want to stick to the VFP provided tools.

How do we specify the parameters such as baud rate, parity, data bit length, etc. in order for the host to comminicate properly with the serial device?

I know I have to wait for a carriage return to be sent before I could get a character but that could be coordinated with the device I think.

I am into a lot of RAD so I have no time to figure this out through experimentation.

I hope for anyone who can enlighten me on this.
 
AirCon,

I don't know much about this, but I feel sure that Wcglorioso will need more than AT commands. AT commands are no good for setting baud rate, parity, etc. You need to make those settings before you can start to send AT commands.

Also, AT commands assume that there is a modem attached to the serial port. He might be using some other device.

Mike


Mike Lewis
Edinburgh, Scotland
 
<<< I try to avoid using OCX (the Mscomm32.ocx)
<<< as much as possible. I want to stick to
<<< the VFP provided tools.

wcglorioso,

MSCOMM32.OCX is a VFP provided tool and has shipped with almost every version of VFP. You can also include it, at no charge, with your applications.

I would use it in the example you provided above. The only hassle you'll have to deal with is installing or registering it on target machines.

Here's an example of how to use it (assuming you dropped it on a form with name &quot;oleCommControl&quot;):

WITH THISFORM
.oleCommControl.InputMode = 1 && Binary
.oleCommControl.CommPort = 2 && COM2
.oleCommControl.Settings = &quot;9600,N,8,1&quot;
.oleCommControl.RThreshold = 1
.oleCommControl.InBufferSize = 8192
.oleCommControl.PortOpen = .T.
ENDWITH

Once the port is open the OnComm event of the control will fire when data arrives and you can do with it what you need. The RThreshold property above (set to 1) tells the control to fire the OnComm event when 1 character is in the buffer. You can set this higher if you're expecting a larger string of data.

Andy
 
Hi,

I wrote an app using the MSCOMM32.OCX. Using the online help, I was able to get communication between to machines going very quickly. I found the OCX to work very well. Since my application uses the standard com ports (ones that use the &quot;standard&quot; addresses and interrupts), I am not sure if it will work with newer serial devices.

The OCX is supplied with VFP, so I guess that would make it a &quot;VFP provided tool&quot;.

HTH
msc
 
Mike,

He might be using some other device

Yes, I didn't think of that.

But if he is using Modem, then there is no other way to setup baud rate using VFP Low Level File. The only way I know is just to set an automatic line speed

I don't think it will work with API Call because it return different types of handle.

Another way is to use API function entirely, then we can setup the comm port anyway we want.

-- AirCon --
 
Mike,

Personally, I would go with Mscomm32.ocx
Yep, totally agree. It's the easiest way :)

Regards

-- AirCon --
 
On top of that, low level VFP stuff like FOPEN(), FREAD() and so on, does not play well with the OS when it comes to comm ports. It will work fine for file I/O but for hardware, it won't. You can't really access the hardware directly through VFP without going through the OS first. If you even get it to work, it will be flakey at best.


-Dave S.-
[cheers]
Even more Fox stuff at:
 
So there is no way of circumventing the use of an OCX or COM technology then.
The description of the function is then misleading.
It mentioned COMM port but it really could not be utilized.
Be sticking to my initial solution after all.
Thanks for putting worth into my question guys.
 
wcglorioso,

So there is no way of circumventing the use of an OCX or COM technology then

One thing you might be able to do is to run a DOS session, using the COPY command to send characters to and from the COMM port. That'll meet your goal of bypassing COM technology.

However, I think it would be simpler to use COM, the whole point of which is to hide the &quot;messy&quot; details of low-level techniques.

Mike


Mike Lewis
Edinburgh, Scotland
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top