02-09-2010 03:23 PM - edited 02-09-2010 03:28 PM
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 commands(such 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.
Solved! Go to Solution.
02-09-2010 03:33 PM
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.
02-09-2010 03:39 PM
02-09-2010 03:46 PM
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
02-09-2010 09:46 PM
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?
02-09-2010 10:02 PM
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?
02-09-2010 10:19 PM
02-09-2010 10:36 PM
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?
02-10-2010 11:51 AM
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.
02-10-2010 11:56 AM
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