LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to implement BASIC codes on Serial Port by Labview ?

Dear Gentlemen,

Thanks for reading this at first.

I need to use Labview to connect two instruments to my MACINTOSH. Both the
instruments offer standard 9-pin RS232C interface. ( So, the first question
is how to convert 9-pin setting to 8-pin? )

An example code of BASIC comes with one instrument is as follows:

10 PEN "COM1:600,N,7,2,RS,CS,DS,CD" AS #2
20 A$="D"
30 PRINT #2,A$
40 IN$=INPUT$(14,#2)
50 PRINT IN$
60 COLSE #2
70 END

Could you offer me some information about Line10,20 and 40?
What's the meaning of "RS", "CS", "DS", "CD"? Especially,
what's the meani
ng of Printing "D" to COM1 port? How can these be implemented
in Labview?

The other has an example code, too:
10 J=1
20 OPEN "COM1:9600,N,8,1,RS,CD,CS,DS"AS #2
30 A$=INPUT$(8,#2)
40 IN LEN(A$)=8, GOTO 50, ELSE GOTO 80
50 N!=VAL(LEFT$(A$,7))
60 PRINT J,N!
70 J=J=1
80 GOTO 30
90 END

What's the meaning of INPUT(8,#2)? Is it going to read 8 bytes from COM1?
Is N! a variable of Character String? What
is the meaning of LEFT(A$,7)?

Thank you so much!!!

Looking forward to your kind replies!!!

Yours, Rain
0 Kudos
Message 1 of 4
(3,710 Views)
Rain Lei wrote:

> Dear Gentlemen,
>
> Thanks for reading this at first.
>
> I need to use Labview to connect two instruments to my MACINTOSH. Both the
> instruments offer standard 9-pin RS232C interface. ( So, the first question
> is how to convert 9-pin setting to 8-pin? )

Someone with MAC experience will have to help here. There are really only a few
line
required for RS232. Check to see if you can find a converter at your local PC /
Hardware sttore.

>
>
> An example code of BASIC comes with one instrument is as follows:
>
> 10 PEN "COM1:600,N,7,2,RS,CS,DS,CD" AS #2

My knowldge of BASIC is years old but here goes. This line (10)
sets up the serial port (COM1 is the 1st serial port) to 600 baud, no parity, 7
data bits, 2 stop bits.
The RS (ready to send), CS (clear to send), DS (not sure about this one), and CD
(carrier detect, or signal present)
are control lines that determine when to Tx, Rx data. The #2 tells what data
type (integer, float etc) to use.
Check the BASIC manual to find out. Setting these command bits puts them into
some state (I'm guessing high)

>
> 20 A$="D"

This looks like the command that you send to the equipment

>
> 30 PRINT #2,A$

This sends the "D" to the gear

>
> 40 IN$=INPUT$(14,#2)

This reads back 14 bytes of data.

>
> 50 PRINT IN$
> 60 COLSE #2
> 70 END
>
> Could you offer me some information about Line10,20 and 40?
> What's the meaning of "RS", "CS", "DS", "CD"? Especially,
> what's the meaning of Printing "D" to COM1 port? How can these be implemented
> in Labview?
>
> The other has an example code, too:
> 10 J=1
> 20 OPEN "COM1:9600,N,8,1,RS,CD,CS,DS"AS #2
> 30 A$=INPUT$(8,#2)
> 40 IN LEN(A$)=8, GOTO 50, ELSE GOTO 80
> 50 N!=VAL(LEFT$(A$,7))
> 60 PRINT J,N!
> 70 J=J=1
> 80 GOTO 30
> 90 END
>
> What's the meaning of INPUT(8,#2)? Is it going to read 8 bytes from COM1?
> Is N! a variable of Character String? What
> is the meaning of LEFT(A$,7)?
>

The LEFT command takes the leftmost 7 bytes of the A$ and makes them an Integer
(I think)
This is meant to strip the last character (probably a Carriage return).

You realize of course that you can only talk to one piece of gear on one COM
port.
There is no addressing or arbitration on a serial port. If you try to hook up
two pieces
to the same serial port you will get a lot of nonsense.

This can all be done easily in labview. Use the VISA functions.
Kevin Kent
0 Kudos
Message 2 of 4
(3,710 Views)
From: Rain Lei

Here's some more detail on the BASIC code.

>An example code of BASIC comes with one instrument is as follows:

>10 PEN "COM1:600,N,7,2,RS,CS,DS,CD" AS #2

PEN should be OPEN. This command assigns an I/O path to the com port 1
and
assigns it a number #2. This number is used in subsequent reads and
writes.
It should be closed after use with the command CLOSE #2.
This line sets it up for 600 baud (should that be 9600?), N (= No
parity?),
7 data bits, 2 stop bits. Sorry, but I'm not familiar with this
particular brand
of BASIC so I don't know what RS,CS DS and CD mean.

>20 A$="D"

This command assigns the character D to the string variable A$

>30 PRINT #2,A$

This command sends the string variable A$ to the instrument via I/O path
#2 (ie COM1).
You have to look up what the instrument does when it receives the
command D. This will be
in the manual or user guide that came with the instrument.
Whatever the command is, it commands the instrument to send a response.
You can tell
that because the next line is

>40 IN$=INPUT$(14,#2)

which reads 14 characters from the instrument on filestream 2 (COM1) and
stores
it in the string variable IN$

>50 PRINT IN$

Displays the string variable IN$ on the screen

>60 COLSE #2

Should be CLOSE #2. Closes filestream number 2, making it available for
other uses.

>70 END

>Could you offer me some information about Line10,20 and 40?
>What's the meaning of "RS", "CS", "DS", "CD"? Especially,
>what's the meaning of Printing "D" to COM1 port? How can these be
implemented
>in Labview?

>The other has an example code, too:
>10 J=1
>20 OPEN "COM1:9600,N,8,1,RS,CD,CS,DS"AS #2

The program sets up a continuous loop starting at line number 30. The
command
on line number 80 makes it loop.
The counter variable J has been initialized to 1 before entry.

>30 A$=INPUT$(8,#2)

Read 8 characters from the instrument and store them in string variable
A$

>40 IN LEN(A$)=8, GOTO 50, ELSE GOTO 80

IN should be IF. This line ensures that only strings of exactly 8
characters
are processed. LEN() is a function that counts the number of characters
in a
string. LEN(A$) is the number of characters in A$.
If the length of A$ is exactly 8 characters, the program continues at
line 50.
If not, the program jumps to line 80 which is the end of the loop, so
the
program jumps back to line 30, for another time through the loop.

>50 N!=VAL(LEFT$(A$,7))

The function VAL() converts a string to a number. This line takes the
leftmost
7 characters of the string variable A$, and converts it into a number.
This number is then stored in the variable N!. The ! at the end of the
variable
name means it is an integer, not a floating point number.

>60 PRINT J,N!

This displays the count number J and the instrument output N! on the
screen

>70 J=J=1

Should be J=J+1. This increments the counter variable J by 1. This
variable
is being used to count the number of 8-character messages from the
instrument.

>80 GOTO 30

Makes the program perform a loop by sending it back to line number 30.
In some brands of BASIC this is the only way to write a loop.

>90 END

Hope it helps

Tom Sheridan
0 Kudos
Message 3 of 4
(3,710 Views)
Tom Sheridan wrote:

> From: Rain Lei
>
> Here's some more detail on the BASIC code.
>
> >An example code of BASIC comes with one instrument is as follows:
>
> >10 PEN "COM1:600,N,7,2,RS,CS,DS,CD" AS #2
>

Man I was WAY off on some of this, but I aint done no basic in 5 yrs either
!!
0 Kudos
Message 4 of 4
(3,710 Views)