Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Talk to a serial device
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Divers
Thread ID:
00613431
Message ID:
00613729
Vues:
9
Hi Alonso;
>
>..How can I write a program (VFP of course) to exchange information with the device? I was wondering if there is an API call or something that makes the task less difficult... :)
>
>Another thing, it has to work on Windows 9x/NT/2K/XP.

We have the activex MSCOMM32 object that does this job perfectly, here is some sample that I created to other UT's fellow:

...The objects MSCOMM and Timer will be our tools for that:

In the Timer object set the property interval to 3000 !
In the Timer method you must write something like:
procedure timer
If  Thisform.mymscomm.InBufferCount>0
    =Thisform.mymscomm.Olecontrol1.oncomm()
Endif
endproc
This example receives some data from the COMx: port e send it to the keyboard (simulating the keyboard wand for some Barcodes readers)

In the method of the object nominated here as mymscomm that is our MSCOMM32 (That I supposed that you already put this in your form). Write on the Oncomm method something like:
procedure oncomm
If  This.CommEvent = 2  && there is acctivity there
        cbufferscanner=""
        wlen=0
        Do While this.InBufferCount > 0
            cbufferscanner=cbufferscanner+This.Input
            wlen=len(alltrim(cbufferscanner))
            If  AT(CHR(10),Thisformset.bufferscanner)>0  && it's a LF that meaning the end of my data
                Do while AT(CHR(10),cbufferscanner)>0
                   cbufferscanner=STUFF(cbufferscanner,AT(CHR(10),cbufferscanner),1,"")
                Enddo
                wlen=len(alltrim(cbufferscanner))
            Endif
            If  wlen>0
                WSCANNER=substr(cbufferscanner,1,wlen)
                cbufferscanner=stuff(cbufferscanner,1,wlen,"")
                Thisformset.LVEMSCANNER=.T.  && warnning for the rest of the application that exists acctivity from scanner
                Keyboard WSCANNER  && Keyboard entry simulation
            Endif
        Enddo
    Endif
Endif
Return
endproc
This will work perfectly in all Windows systems. And, you must setup some properties on mscomm32 to handle with your external device (data speed, communication port in use, stop bits, parity, etc.)


HTH, Please tell me if it works ok ?


Claudio
"Now to him who is able to do immeasurably more than all we ask or imagine, according to his power that is at work within us, Ephesians 3:20
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform