LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Interfacing Labview and Basic Stamp 2

Has anyone worked on a project that involves the BS2 and Labview??
I got the below code from one of the manuals for BS2 and can see the output of the ADC0831 (8 bit analog to digital converter) on the DEBUG screen of the Stamp Editor.
****************************************************************

'{$STAMP BS2} 'STAMP directive (specifies a BS2)
' -----[ Initialization ]--------------------------------------------------
CS CON 2
CLK CON 1
RD1 CON 0 ' Read Signals via Specified Pins
TD16 CON 16 ' Transmit data serially
baud CON 16624 ' N9600 for BS2
sig VAR Byte ' Bytes to store the signals
DEBUG CLS ' Start display.
looping:

' -----[ Declarations ]----------------------------------------------------
adcBits VAR Byte
v VAR Byte
r VAR Byte
v2 VAR Byte
v3 VAR Byte

' -----[ Main Routine ]----------------------------------------------------
GOSUB RDSIG1 ' Read the signal
GOSUB Calc_Volts ' Calculate the signal in voltage form
GOSUB Display ' Display the results
SEROUT TD16, baud, [RD1]
GOTO looping

' -----[ Subroutines ]-----------------------------------------------------
RDSIG1:
HIGH CS
LOW CS
LOW CLK
PULSOUT CLK, 210
SHIFTIN RD1,CLK,MSBPOST,[adcBits\8]
RETURN

Calc_Volts:
v = 5 * adcBits / 255
r = 5 * adcBits // 255
v2 = 100 * r / 255
v3 = 100 * r // 255
v3 = 10 * v3 / 255
IF (v3 < 5) THEN skip_a_line
v2 = v2 + 1
skip_a_line:
IF (v2<100) THEN skip_out
v = v + 1
v2 = 0
skip_out:
RETURN

Display:
DEBUG HOME
DEBUG "8-bit binary value: ", BIN8 adcBits
DEBUG CR, CR, "Decimal value: ", DEC3 adcBits
DEBUG CR, CR, "DVM Reading: "
DEBUG DEC1 v, ".", DEC2 v2, " Volts"
RETURN
PAUSE 1000
RETURN

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


When I try to send this data via serial cable RS232 to analyse and display the results in Labview, I am not able to read the data coming out of it.
I am getting an error message during VISA READ and timeout expired before the completion of operation.
Can anybody advice what I might be doing wrong???
I have attached my Labview file along with. It is simply supposed to receive 8 bits, convert them to decimal value and do some math on it to get the required display.

There are 4 connections between BS2 and RS232 namely SOUT, SIN, ATN, VSS on one end while the other end goes into the COM port.
0 Kudos
Message 1 of 2
(3,291 Views)
In your code you set two timeout values, one in the "Serial Config" and the other in "VISA Property Node", it is not necessary to have two.

You also have a sequence structure inside the whileloop, there is no need to have this structure. Try to follow the serial examples shipped with LabVIEW and build your program from an example. It will make your code more efficient.

I don't understand why you have a "wait" in the loop that has a value of 1000 times of your sampling rate. If your sampling rate is 100/sec, you will have a 100 second delay between two reads?

Try to reconstruct your code and see if it will fix the error.
0 Kudos
Message 2 of 2
(3,260 Views)