Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

Serial write & read problem in labview Test Application

Hi Good Day,

 

I created a LabVIEW program that when I wirte a command, it will response to a characters in 1 second span of delay and that response will be read to confirm that it is programmmed. the problem is that I cannot read nor write if I both Write & Read Visa VI are connected each other. But If I ONLY write, It writes. If I use the HyperTerminal with Baud Rate 38400, Data Bits 8, Stop & Parity 0, The command function well & respond easily. I put the Write Visa with String to write _IAPH:43,"",""\r\n and after Write VISA, the Read VISA is inside a While Loop with 50ms time. the Read Buffer String Indicator is the output of the Read VISA.

 

Hope for your help. Thanks!

0 Kudos
Message 1 of 8
(5,092 Views)

Here is my sample VI for the test application. The String to write should be _IAPH:43,"JBS251A121800001","D00001"\r\n on the Write Visa and will respond after 1 second. The response will be like this:

 

JBS251S121800001

D00001

OK

 

the _IAPH43:,"",""\r\n is a command only to confirm that the string is programmed and the response is the same as above.

 

The problem is that it will not read the that responses nor write also.

 

Hope you can help me. Thank you very much

 

Mugs

0 Kudos
Message 2 of 8
(5,090 Views)

Well, you started out with a state machine. That's a very good start.

 

You have several issue with your code.

  • The serial port configuration should be in the "Initialize" state. Do not configure the serial port in each iteration. You can use a shift register to pass the VISA resource reference around the loop.
  • You are not actually appending a CRLF as part of your write. You are actually performing a classic mistake, having to do with what the "\" character means. When used like this: "\r" it means an escape sequence. It does not mean that you actually enter the two characters separately. The way you have it now, the constant that you add is adding four characters: "\", "r", "\", and "\n". That's not what you want. Right-click on the string constant and select '\' Codes Display. You will see the mistake.
  • You are not waiting 1 second after the write. Having a Wait function in parallel to a Write operation does not mean the wait will occur after the write. LabVIEW does not execute code top to bottom. Use the Time Delay function to wire in a wait in sequence to your Write.
  • You have sequence structures where none are necessary.
0 Kudos
Message 3 of 8
(5,083 Views)

Well, you started out with a state machine. That's a very good start.

 

You have several issue with your code.

  • The serial port configuration should be in the "Initialize" state. Do not configure the serial port in each iteration. You can use a shift register to pass the VISA resource reference around the loop.
  • You are not actually appending a CRLF as part of your write. You are actually performing a classic mistake, having to do with what the "\" character means. When used like this: "\r" it means an escape sequence. It does not mean that you actually enter the two characters separately. The way you have it now, the constant that you add is adding four characters: "\", "r", "\", and "\n". That's not what you want. Right-click on the string constant and select '\' Codes Display. You will see the mistake.
  • You are not waiting 1 second after the write. Having a Wait function in parallel to a Write operation does not mean the wait will occur after the write. LabVIEW does not execute code top to bottom. Use the Time Delay function to wire in a wait in sequence to your Write.
  • You have sequence structures where none are necessary.

 

 

 

Sir, Thank you for your response & I appreicate it because I am a newbie from LabVIEW application. Hope you understand. Maybe we can focus only on the write-read visa. forget the other case structures because that is for future development.

 

I already tried to put a Shift registers around the loop and the results are still the same. In the Initialise to Telnet the flow are OK because that GPS not connected is for detection from the Unit.The code for detection is _IAPH:48,0,1 from the firmware & that is why it reads in the Telnet Case eventhough the whileloop on GPS has 50ms time Delay and the the whileloop is waiting for more than 10secs. The \r\n is a code used for terminating the command as our software team procedure says in using other application (like LabVIEW) aside from HyperTerminal and TeraTerm without touching the Keypad and also used for other commands. Without these code, the firmware will not respond once It didnt see these code. The idea of the the command is to write the Serial Number & Unit ID of the Unit and the firmware will respond that the Serial Numbers & Unit ID are programmed and OK.

 

The 1 second delay is a countermeasure that We might expect just to read the response from the firmware & dedicated only for that command. Yet the problem It cannot write & read while IF I only write it, with the code \r\n, It writes....and when I check to the HyperTerminal the Serial Numbers & Unit ID is written.

 

The other sequence structure are for future preparation so no problem with that. Hope for your kind help & I would appreciate it.

 

Best Regards,

 

Mugs

0 Kudos
Message 4 of 8
(5,080 Views)

Reread the answer about the \r\n termination characters. You are NOT sending them correctly and if you do not acknowledge that, you will never get your communication to work. Every write is incorrect.

0 Kudos
Message 5 of 8
(5,077 Views)

@Dennis: Sir I will give you a sample of a \r\n write commands that commands to type a Keypad on a phone. Pleasee see attachment. These write commands are working perfectly fine and used of production already. In all of the commands execution, all have immediate responses in a matter of milliseconds & all command execution will depend only on \r\n.

0 Kudos
Message 6 of 8
(5,070 Views)

You're just not listening.

 

I'm going to go somewhere else now.

0 Kudos
Message 7 of 8
(5,068 Views)

I agree. If you don't like the answer that you are doing something wrong, then stop asking questions here. Since you did not feel it necessary to post actual code, do the comparison yourself of the display type.

0 Kudos
Message 8 of 8
(5,057 Views)