Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

Cannot upload data to serial device using x-on, x-off in Labview but works OK in Hyperterminal

Hello,
 
I'm trying to write a Labview 7.1 App that will upload a motorola .S28 file to a custom designed piece of hardware. The serial port on the hardware device requires the serial port settings be set to 9600, 8,N,1, none, for general operation and my Labview app is able to send and receive information from the hardware using the NI VISA 4.00 serial read and write routines, so I know that there are no fundamental communications errors.  The general communications also work when I set the com port to 9600, 8,N,1, x-on, x-off.
 
The problem I'm experiencing is that I can upload calibration files (which require x-on, x-off flow control) in Hyperterminal by:
1. configuring the Hyperterminal session for 9600, 8,N,1, x-on, x-off
2. selecting "Transfer--> Send Text File... when my device prompts me to upload the file.
This works 100% of the time in Hyperterminal, but I cannot accomplish the same upload in my Labview app.
 
The very first thing my LV app does is to pop up a dialog box to the user prompting him/her to select the desired com port (Visa Resource Name), Baud rate, Data bits, Parity, Stop bits, Flow Control, and allows the user to enable/disable the termination char and to set the termination char (always enabled and set to default 0xA).  The flow control is set to x-on, x-off. This is accomplished using the VISA Configure Serial Port vi. 
 
I have tried using both the VISA Write From File vi and also reading the file to a text variable then using the VISA (serial) Write vi but neither work. The VISA Write From File vi  return count correctly identifies the number of bytes in the file but the hardware never returns it's transfer complete status message (remember this works 100% of the time in Hyperterminal).  Does anyone out there have any advice as to how I can make this work?
 
Thanks,
Ian
:
 
0 Kudos
Message 1 of 8
(5,899 Views)
It's hard to say what Hyperterminal might be doing differently. It's possible that it is adding some termination character when the write is finished. Unless you've modified the VISA Configure Serial Port, you're not sending any termination character. All that the default function does is set the termination character for a read. What you might want to do is use a utility like portmon to see if there are differences at the end of the file transfer.
0 Kudos
Message 2 of 8
(5,897 Views)
Thanks for the good suggestion Dennis. I used a program called Free Serial Port Monitor http://www.serial-port-monitor.com/index.html to capture the differences between Hyperterminal and Labview. The file I'm uploadingis a Motorola .S28, s-record file which is essentially a text file however the key difference is how the carriage return line feed is handled at the end of each line. Hyperterminal by default strips the line feed (hex 0A) leaving the carriage return (hex 0D which is the enter key), whereas Labview does not, at least I haven't figured out how to yet.
 
What I had to do was to create a loop that opens the file and reads one character at a time. If the character is not a hex 0A then I transmit the character, when a hex 0A is encountered I simply throw it away and don't send. This of course adds the overhead of having to parse every file I want to upload for the hex 0A token. 
 
Does anyone know of a way to configure the VISA serial port routines to transmit only the 0D character and strip the 0A char without having to parse the file?
 
Thanks,
Ian
0 Kudos
Message 3 of 8
(5,862 Views)
This is going to be a two-part solution, meaning you will need to change the way you read your file and the way you transmit the data.

First, when you read from your file, set the Read VI to read in Line Mode. When you do this, the output of the read will be an array of strings rather than a single string. It will basically read the file until it hits the CR/LF combination, but should strip the terminating characters from each line.

Second, in order to replace the carriage return which was stripped, you can configure VISA to transmit a termination character after each write is performed. In addition to setting the termination character to CR on the Configure Serial Port VI, you will want to use a VISA Property Node to set the Serial::End Mode For Writes properter to use the termination character.

Now, you can simply use a For loop to index through your string array, transmitting each line. You will have eliminated all your manual parsing of the file, which should simplify your application and increase performance. I have included a picture of how this could be done in LabVIEW 8.x. The file I/O interface looks different than it did in 7.1, but the same functionality exists.



-Jason S.

Message Edited by JasonS on 09-26-2007 08:49 AM

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

Jason,

 

Would a similar method work for sending a binary file over a serial connection? If so, how would I parse it without the CR/LF? Should I cut it into 1024 bytes?

 

The "VISA Write From File" function is not working with my target UUT (unit under test) so I would like to use the "VISA Write" function to give me more control.

 

Thanks for your help!!

 

 

Best Regards,

 

Sam Broyles 

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

Sam,

 

A similar method should definitely work for binary files.  The Read from Binary File function allows you to specify the number of bytes or elements of type to read.  This is explained quite well in the LabVIEW Help for that function.

Cody A.
0 Kudos
Message 6 of 8
(4,927 Views)
But what is not mentioned in this hijacked thread is that he needs to transmit using the ymodem protocol. See http://forums.ni.com/t5/Instrument-Control-GPIB-Serial/VISA-Serial-Write-Binary-File-aborted/m-p/308...
0 Kudos
Message 7 of 8
(4,917 Views)

I apologize -- I did not intend to hijack this thread. My intention was to approach the problem from another angle. I was drawn to this thread because I was attempting to automate serial communication to replicate a manual procedure performed with Hyperterminal. Read/Write functions were easy to implement, but when it was time to upload a binary file, I hit a dead-end.

 

As I have researched more about the ymodem protocol, it's obvious that implementing this protocol with LabVIEW VISA functions would be a significant project on its own!

 

I am still evaluating my options. I will post the solution to the other thread.

http://forums.ni.com/t5/Instrument-Control-GPIB-Serial/VISA-Serial-Write-Binary-File-aborted/m-p/308...

 

 

Best Regards,

 

Sam Broyles

 

0 Kudos
Message 8 of 8
(4,892 Views)