Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Stumped on a Serial Port Control Problem
Message
From
20/12/2002 13:28:27
 
 
To
20/12/2002 11:19:04
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00734920
Message ID:
00734968
Views:
18
Hi Jack,

You are polling for input - I doubt you will ever be successful at that data rate with this approach. Try this instead:

Add a form property called strinput vs your variable.
Put your code inside the Oncomm event of your comm control like this:
WITH THISFORM
IF THIS.commevent = 2
  .strinput = .strinput + .mscomm1.INPUT
  IF AT("READY",.strinput)<>0
    .strinput = STRTRAN(.strinput,'READY','')
    IF LEN(.strinput)>0
      ALINES(vntsplit,STRTRAN(.strinput,CHR(9),CHR(13)+CHR(10)))
      IF cs22(.strinput)=VAL(vntsplit(ALEN(vntsplit,1)))
        lngdataindex=ALEN(vntdatabuffer)+1
        DIMENSION vntdatabuffer(lngdataindex)
        vntdatabuffer(lngdataindex)=.strinput
        .mscomm1.outbuffercount = 0
        .mscomm1.OUTPUT = "READY"
        .strinput=""
      ELSE
        MESSAGEBOX("Checksum failed. Aborting Import")
        .mscomm1.outbuffercount = 0
        .mscomm1.OUTPUT = "STOP"
       ENDIF
    ELSE
      .mscomm1.outbuffercount = 0
      .mscomm1.OUTPUT = "READY"
      .strinput=""
    ENDIF
  ELSE AT("STOP",.strinput)<>0
    .strinput = STRTRAN(.strinput,'STOP','')
    IF LEN(.strinput)>0
      lngdataindex=ALEN(vntdatabuffer)+1
      DIMENSION vntdatabuffer(lngdataindex)
      vntdatabuffer(lngdataindex)=.strinput
    ENDIF
  ENDIF
ENDIF
ENDWITH
I think all my dots are in place :-)

See MSKB #Q140525 for a discussion of both approaches. Set the RThreshold property to 1 for the above to work.

>I have been playing with the transfer of data between a credit card processing terminal and an app I am building in VFP 6. I am using MSCOMM32 to control the serial port coming from the terminal and running into a timing problem.
>
>The program requests the data from the terminal, places the data into an array. When you step through the code, the data transfer obviously works correctly. But when you run the code, the data transfer starts but fails. As a quick fix, I placed the following into the code:
>
>do while blnAbort=.f.
> for delay=1 to 5000000
>next delay
>
>While this fixed the problem for the most part, on faster computers, it tends to still occasionally fail. (Entire routine is listed below.)
>
Previous
Reply
Map
View

Click here to load this message in the networking platform