Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Need to read string from serial port for bar code app
Message
From
22/05/2002 17:18:20
 
 
To
03/05/2002 08:55:23
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00651375
Message ID:
00660190
Views:
22
Hi Again Jim, Patrick,

Sorry I didn't reply to you sooner on your last post to me regarding this, but I got busy on other things. Anyway, I finally got around to actually testing this thing with an RF gun. The client had the RF gun, so I was coding without actually being able to test it. Well, once I got to test there were some things that didn't behave at all like I expected! Maybe you can shed some light on this for me?

I ended up implementing it by just dropping the ActiveX control on a form. I didn't use vfpcom/bindevents. Here is what the code looks like in my oncomm event:

*** ActiveX Control Event ***

***section one - this works
thisform.fpc_ScanData=this.input
if chr(13) $ thisform.fpc_Scandata
thisform.fpc_ScanData=substr(thisform.fpc_scandata, 1, len(thisform.fpc_scandata)-1)
else
*wait wind 'there was no chr(13)'
endif
this.parent.txtbarcodedata.value=thisform.fpc_ScanData
this.parent.txtbarcodedata.refresh()
oBCinput.ProcessBCInputData(thisform.fpc_ScanData)
go bottom in messagequeue
go bottom in curtasksstarted
go bottom in taskscompleted
this.parent.txtbarcodedata.value=''
thisform.refresh()
***end section one

*** section two - this did not work
if .f.
local lcNextChar
lcNextChar = this.input

if lcNextChar=chr(13)
this.parent.txtbarcodedata.value=thisform.fpc_ScanData
this.parent.txtbarcodedata.refresh()
oBCinput.ProcessBCInputData(thisform.fpc_ScanData)
go bottom in messagequeue
go bottom in curtasksstarted
go bottom in taskscompleted
thisform.refresh()
else
thisform.fpc_ScanData=thisform.fpc_ScanData+lcNextChar
endif

endif
****************
Please note the following about the code above:

1)The code I originally wrote is in 'section two' (now commented out with if .f.). This code didn't work. Before I tested, I was under the impression that the oncomm event would fire each time a character was added to the input buffer, and that therefore I could build the string one character at a time, until I received a chr(13). But it turned out that the oncomm event only fired once, and stored my whole string to the input buffer.

Note that I don't have the doevents statement anywhere in here. Do I need it?

2) So, I recoded it as per 'section one', where I store this.input only once. But please note that I also have the following code:
if chr(13) $ thisform.fpc_Scandata
thisform.fpc_ScanData=substr(thisform.fpc_scandata, 1, len(thisform.fpc_scandata)-1)
else
*wait wind 'there was no chr(13)'
endif

I put in this code to account for a behaviour that doesn't make sense to me. When the form is active (the cursor is in the txtbarcodedata text box, which is a read only textbox), i.e., the form has the focus, a chr(13) is stored to the input string. But, oddly, if the form is minimized, and/or the vfp application itself is minimized, the chr(13) doesn't get stored to the input string.

One of the main reasons I wanted to go this route, was so that I could have an application that didn't rely on the cursor being in a textbox.

I don't understand why the state of the form should have any relationship whatsoever to what is stored to the input buffer.

I must be missing something here!


TIA





>David,
>
>Now that you've decided to use a form, create a form property to hold the input buffer, and a form method to process that input. Now, your ONCOMM event (2) can be reduced to something like:
>
>THISFORM.MyBuffer = THISFORM.MyBuffer + THIS.input
>THISFORM.ProcessData()
>
>In ProcessData():
>
>IF yourendoflinechar$THISFORM.MyBuffer
>  * Got a complete line - Do something
>  * Save it, send it, turn on a light, etc.
>  THISFORM.MyBuffer = ""
>ENDIF
>
>
>and you are done. If there is a chance of multiple scans in the buffer, you might test for multiple End of Line chars and just extract the most recent, leaving the rest intact or processing them all, or ? It's up to you.
>
>>OK. I think I've got the concepts down now. I can see why you have put it together the way you have, and why vfpcom is need.
>>
>>BTW, in this case I will probably instantiate it from a form. But I will probably need the control without a form down the road for some other uses.
>>
>>Thanks again!
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform