Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How To Read A Weight Scale (Cardinal) Through COM1 port
Message
From
18/02/2008 16:10:19
James Blackburn
Qualty Design Systems, Inc.
Kuna, Idaho, United States
 
 
To
18/02/2008 11:14:33
Raza Malik
Universal Accounting Software
Edgewater, New Jersey, United States
General information
Forum:
Visual FoxPro
Category:
COM/DCOM and OLE Automation
Environment versions
Visual FoxPro:
VFP 7 SP1
Miscellaneous
Thread ID:
01293466
Message ID:
01293599
Views:
39
In addition to what Don said, you need some type of wait state to give the data to time fill the buffer. There is an oncom event that is supposed to fire when the buffer receives data but I had very limited success with that. I ended up using a timer and polling the com port every 500 ms and then checking for the length of the buffer. Here is some code that might help. This assumes that the indicator is sending a continuous stream of data.
WITH this.oleweight
	IF TYPE("NVL(_screen.oapp,'')") = "O"
		LOCAL lnnum, lnSecs, lnNumber, lnDataLen, x
		LOCAL lacodes[1]
		lnDataLen = _screen.oapp.osite.WS_datalength
		lnStartPos = _screen.oapp.osite.ws_lentodata
		IF .inBufferCount >= (lnDataLen*2)
			this.lScaleIndicatorError = .f. 
			this.tlastreadtime = DATETIME()
			lcnum = .input
                        * this is used for debug in production.  
			IF FILE("logscale.txt")
				STRTOFILE(lcnum,"scallog.txt",1)
			ENDIF 
			this.clastscalestring = lcNum
			* gets the last valid weight.
			IF RAT(CHR(13),lcnum,1) > 0
				lcnum = SUBSTR(lcnum,RAT(CHR(13),lcnum,1)-lnDataLen,lnDataLen)
			ENDIF 	

			IF LEN(lcNum) < 10
				RETURN 
			ENDIF 

			lcnum = SUBSTR(lcnum,lnStartPos,7)

                        * more debug code for production.
			IF FILE("logscale.txt")
				STRTOFILE(lcnum+CRLF,"ScaleNum.txt",1)
			ENDIF 

			lnNumber = INT(VAL(retnum(lcnum)))
                        *display a negative number
			IF ATC("-",lcnum) > 0
				lnNumber = lnNumber * -1 
			ENDIF 
                        
                        * this is used to freeze the weight on the computer screen while the user is
                        * filing in ticket info 
			IF NOT thisform.lFrezzWeight
				this.txtweight.Value = lnNumber 
				this.txtweight.Refresh()
			ELSE
				IF lnNumber < 400 AND NOT this.lreprint 
					this.cleanup()
				ENDIF 	
			ENDIF
		ELSE 
			IF EMPTY(this.tlastreadtime)
				this.tlastreadtime = DATETIME()
			ENDIF 
			IF DATETIME()- this.tlastreadtime > 10 
				this.lScaleIndicatorError = .t. 
			ENDIF 	
		ENDIF 
		
		IF NOT ISNULL(this.tstarttime)
                        * times out application if weight is not completed in a specific time frame. 
			IF DATETIME() - this.tstarttime > 60*this.ntimeout 
				thisform.processticket(.f.)
			ENDIF 
		ENDIF 	

	ELSE 
		.interval = 0		
	ENDIF 
ENDWITH 
>Hello Experts...
>
>I have weight scale attached to a COM1 port. Truck goes over the scale and it sends multiple readings to a VFP application via COM1 port. I can see the data comming through Hyper Terminal but I always get 0 through VFP application. I use the following code to capture the weight through COM1 port:
>
>
>	SET OLEOBJECT ON
>	oComm = CREATEOBJECT('MSCOMMLib.MSComm')
>	oComm.CommPort = 1
>	oComm.Settings = "1200,N,8,1"
>	oComm.InputLen = 0
>	oComm.PortOpen = .T.
>
>	II = oComm.input
>
>	=MESSAGEBIOX(II)
>
>	oComm.PortOpen = .F.
>
>	RETURN
>
>
>
>Can someone tell me what I am doing wrong ?
>
>Please...
>
>Thank You.
>
>Raza Malik
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform