LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to achieve the same serial funtion in Labview as Qbasic

Solved!
Go to solution

I want to achieve the same serial port function in labview as what the Qbasic does. Is there certain differece in sending format via serial port between Labivew and Qbasic? Thank you for your help. 

 

I can use Qbasic program to send commandssuch as “WR”,”WS” responded via soldered 9 pin(PC) to 25 pin(Machine ) cable. The program as follows

 

10 CLS
20 OPEN "COM1:9600,N,8" FOR RANDOM AS #1
30 INPUT "INPUT COMMAND"; D$
40 PRINT #1, D$
50 IF EOF(1) THEN 50
60 INPUT #1, A$
70 IF A$ = CHR$(4) THEN A$ = "ACK"
80 PRINT A$
90 GOTO 30
 

 

But I cannot achieve the same function in Labview 8.2. I have already installed the VISA Driver. But when I try to send commands, the machine has no responded. Sometimes the labview can receive some random letters, such as “?”. The program as follows.

TO5000-labview.JPG

帖子被guosiming@sjtu.edu.cn在 02-09-2010 03:28 PM
时编辑过了
0 Kudos
Message 1 of 10
(4,731 Views)

guosiming@sjtu.edu.cn wrote:

I want to achieve the same serial port function in labview as what the Qbasic does. Is there certain differece in sending format via serial port between Labivew and Qbasic? Thank you for your help.


Not really. Serial communication is not a function of the programming language.

 

Your VI worked just fine on my computer with a loopback connected to my computer's serial port. Do you have the right cable for the instrument that you're trying to talk to? Have you tried communicating using a terminal emulation program, like HyperTerminal, if you're on Windows. You should always verify this first. 

0 Kudos
Message 2 of 10
(4,721 Views)
Solution
Accepted by guosiming@sjtu.edu.cn
It's been awhile since I used serial ports with Qbasic.  But I believe the Print #1 command will put a carriage return or line feed character at the end of the data being sent.  You may want to try to add a \r   or \r\n at the end of your message (with the "new message" string set to show \ codes).
Message 3 of 10
(4,716 Views)

Most likely QBasic adds a carriage return and/or line feed automatically when issueing the PRINT command. LabVIEW does not do that automatically so you will have to do that explicitedly in your program.

 

Also the "lines at serial port" is not really a good function to use if your device sends a carriage return to terminate each message. The Initiliaze Serial Port VI configures the serial port already to terminate on received carriage return, so it would be a lot better to simply wire a large enough number to the number of bytes to read that is guaranteed to be bigger than the largest returned message.

 

VISA read will return when:

 

1) an error has occured

2) the number of requested bytes have been received

3) the configured termination character has been received

4) the timeout has occurred

Rolf Kalbermatter
My Blog
0 Kudos
Message 4 of 10
(4,708 Views)

Thank you for your help.

Yes,I have test the cable,the qbasic program and the labview program. I can use the cable and qbasic programe to control my machine very well. And I can use labview to send and receive from one pc to another.

I think the qbasic command PRINT #1 maybe modify the  command I send a little bit, for example, add some additional letter before or after the command. But I don't know what it is.

I try to send somthing from on one pc using my QBASIC programe to another pc using my Labview programe. The QBasic program stop at "40 PRINT #1, D$", and tell me "device timeout". So what could cause this result? 

0 Kudos
Message 5 of 10
(4,672 Views)

Thank you for your answer.

 

I think what you said is right.  The qbasic command PRINT #1 maybe modify the  sending data a little bit, for example, add some additional letter before or after the command. But I don't know what it is.

 

One of the command is "RI", it works OK when using my Qbasic programe. When I send "RI" to machine via Labview, the labview receive an interrogation mark "?" when I send "RI" twice. When I send "RI\r" or "RI\r\n" each time, the the labview receive an interrogation mark "?" .

 

I try to send somthing from on one pc using my QBASIC programe to another pc using my Labview programe. The QBasic program stop at "40 PRINT #1, D$", and tell me "device timeout". So what could cause this result? How can I konw what the Qbasci really send to serial port?

0 Kudos
Message 6 of 10
(4,670 Views)
Thank you very much. Following your introcution, I solve this problem succesfully.
0 Kudos
Message 7 of 10
(4,663 Views)

Another possibility is that is sends just a line feed character which would be \n (when viewed in \ codes mode).

 

I have no idea why your qbasic program would stop at line 40 and say device timeout.  If anything, it would stop at line 60 if it is waiting for data to come into the serial port that never comes because you didn't write your LabVIEW program in a way to send back any data like your device would do.

 

If you really want to see all the details that your qbasic program is doing, use portmon.

 

What is the device you are trying to communicate with?  Does it have a manual?

0 Kudos
Message 8 of 10
(4,656 Views)

Ravens Fan wrote:
It's been awhile since I used serial ports with Qbasic. 

I think the last time I used Qbasic was for playing Nibbles.


___________________
Try to take over the world!
0 Kudos
Message 9 of 10
(4,625 Views)

tst wrote:

Ravens Fan wrote:
It's been awhile since I used serial ports with Qbasic. 

I think the last time I used Qbasic was for playing Nibbles.


 

For me it was my model train layout.

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 10 of 10
(4,622 Views)