>I am looking for a reasonable fast way to read and write to a serial port from within VFP. The following is a quick basic example program. How can I do this in VFP?
>
Your best bet would be to use the MSCOMM32.OCX included with VFP; it provides an OLE interface to serial communications. There are detailed examples of how to use the MSCOMM control here on UT, as well as in the MSDN documentation. A close equivalent of what you show below might look like:
oComm = CREATEOBJ('MSCOMMLib.MSComm')
oComm.CommPort = 1
oComm.Settings = '9600,N,8,1'
oComm.InputLength = 0
oComm.PortOpen = .T.
DO WHILE LEN(oComm.Input) > 0
ENDDO
*assume you have #DEFINEs to replace your constant declarations
oComm.Output = CHR(SetZ + 1) + CHR(13) + CHR(10) && omit CR/LF if not needed
*etc, etc.
>CONST SetX = 16, SetY = 32, SetZ = 64 ' Define constants
>CONST XCW = 0, XCCW = 16, YCW = 0, YCCW = 32, ZCW = 0, ZCCW = 64
>
>CLS : OPEN "COM1:9600,N,8,1" FOR RANDOM AS #1 ' Init. Comm. Port
>DO UNTIL EOF(1) ' Do not start communications
> I = ASC(INPUT$(1, #1)) ' until the serial port
>LOOP ' input buffer is empty.
>
>PRINT #1, CHR$(SetZ + 1); ' X and Y = full step, Z = half step.
>PRINT #1, CHR$(2); ' No limit sense for any steppers.
>PRINT #1, CHR$(SetY + 3); ' Y = 2 phase excitation.
>PRINT #1, CHR$(4); ' Set a step rate
>PRINT #1, CHR$(160); ' clock of 160.
>PRINT #1, CHR$(SetX + 5); ' Set the speed divisor for
>PRINT #1, CHR$(5); ' stepper X to 5.
>PRINT #1, CHR$(SetY + 5); ' Set the speed divisor for
>PRINT #1, CHR$(10); ' stepper Y to 10.
>PRINT #1, CHR$(SetZ + 5); ' Set the speed divisor for
>PRINT #1, CHR$(15); ' stepper Z to 15.
>
>Thanks