Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Reading and Writing to a Serial Port
Message
De
07/02/1999 09:50:21
 
 
À
07/02/1999 08:19:53
Information générale
Forum:
Visual FoxPro
Catégorie:
Fonctions Windows API
Divers
Thread ID:
00184838
Message ID:
00184845
Vues:
29
>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
EMail: EdR@edrauh.com
"See, the sun is going down..."
"No, the horizon is moving up!"
- Firesign Theater


NT and Win2K FAQ .. cWashington WSH/ADSI/WMI site
MS WSH site ........... WSH FAQ Site
Wrox Press .............. Win32 Scripting Journal
eSolutions Services, LLC

The Surgeon General has determined that prolonged exposure to the Windows Script Host may be addictive to laboratory mice and codemonkeys
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform