Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Stumped on a Serial Port Control Problem
Message
From
20/12/2002 11:19:04
 
 
To
All
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Title:
Stumped on a Serial Port Control Problem
Miscellaneous
Thread ID:
00734920
Message ID:
00734920
Views:
44
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.)

I still feel like I am missing a step that would eliminate the need for the delay but am running into a mental brick wall.

One additional note. All of the serial control parameters in the terminal are FIXED. The unit transmits data at 19200 baud and cannot be changed. My opinion is that they are running it too fast but I am told that there is no way they will allow a user to change the serial port transmission parameters.

I was hoping that someone here might have experience at coding serial port controls in VFP and could tell me what I am doing wrong or what I am missing.

Thank you in advance for your help.

Jack Wilson



**********************************************

strInput=""
lngDataIndex=0
dimension vntDataBuffer(1)
blnAbort=.f.
thisform.MSComm1.PortOpen = .t.
thisform.MSComm1.OutBufferCount = 0
thisform.MSComm1.Output = "ATIMPORT"

*****************************

do while blnAbort=.f.
for delay=1 to 5000000
next delay

*****************************


strInput = strInput+thisform.MSComm1.Input
if at("READY",strInput)<>0
strInput = strtran(strInput,'READY','')
thisform.timer1.interval=0
t2=.f.
thisform.timer1.interval=30000
if len(strInput)>0

* set step on

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
thisform.MSComm1.OutBufferCount = 0
thisform.MSComm1.Output = "READY"
strInput=""
else
messagebox("Checksum failed. Aborting Import")
thisform.MSComm1.OutBufferCount = 0
thisform.MSComm1.Output = "STOP"
blnAbort=.t.
endif
else
thisform.MSComm1.OutBufferCount = 0
thisform.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
blnAbort=.t.
endif
endif
enddo
thisform.MSComm1.PortOpen = .f.
Next
Reply
Map
View

Click here to load this message in the networking platform