LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Help with serial port needed

This is a clearer version of a previous question I posted. I
apologize for any confusion.

[Newbie - never done port commuication before]

I have data coming in on a serial port (RS-232, DB9, COM1) and the
size of the file changes every time (and I cannot predict the size).
I currently seem to be capturing only a portion of the file, and I'm
not sure how to set the "# read bytes" on the VISA Serial Read
function or if this is even the right method because of this problem.

The situation is this: I hit "print" on an instrument panel, and it
sends the print job out thru the serial port. I'm trying to save the
file and then forward it over the 'net using the TCP functions, so I
need to have the serial port ready and waiting to receive data

whenever the instrument sends it.

I have the TCP side working. 🙂 The serial side has only the VISA
Serial Read function and I'm trying to create a new file and write all
the data to it (I guess this would be bytestream type?).

Any and all help would be appreciated. Thanks!

Kirk
0 Kudos
Message 1 of 10
(3,366 Views)
Kirk

does your instrument have a terminating character/sequence ?? if so just keep polling the com port until you receive the term char/seq or a timeout occurs, you will have to decide for yourself what that timeout should be.

Good Luck

Dan
0 Kudos
Message 2 of 10
(3,366 Views)
As I said in your other posting, you could use VISA Bytes at Serial Port (on the Instrument I/O>Serial palette) to determine how many bytes are available and feed that data to the VISA Read. Both of these would be in a while loop. You would terminate the while loop when there are zero bytes left to read or some termination string is read. The termination string might be some text that indicates the last line in the file (if one exists). I've attached a picture that shows a simple example of what I mean.
Message 3 of 10
(3,366 Views)
Thanks for the response. I don't know the answer to your question,
unfortunately. I DO know that the file being sent out is a PCL file
since it thinks the job is going directly to an HP laserjet printer.
I'll have to do some more research on this to find out about
termination characters.

Thanks again!

Kirk
0 Kudos
Message 4 of 10
(3,366 Views)
I noticed that you're using either Google or a newsreader. If you go to the LabVIEW forum at http://www.ni.com/devzone/dev_exchange/default.htm, then you can actually see an example. Only the NI forum allows for attachments.
0 Kudos
Message 5 of 10
(3,366 Views)
Dennis Knutson wrote:
> I noticed that you're using either Google or a newsreader. If you go
> to the LabVIEW forum at
> http://www.ni.com/devzone/dev_exchange/default.htm, then you can
> actually see an example. Only the NI forum allows for attachments.

If you prefer to use a news reader of some sort, you can connect
directly to newsgroups.ni.com and get comp.lang.labview from there.
While other news servers typically strip attachements or even drop
entire posts with attachments for obvious reasons, the NI news server
keeps them.

Rolf Kalbermatter
Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
0 Kudos
Message 6 of 10
(3,366 Views)
P.S. I neglected to mention that I have taken advantage of your suggestion to use the serial read function and can observe the bytes available at the serial port. I really appreciate everyone's help.

I'm also reviewing the image you posted as a guide for my loop to read the data. THANKS!

Kirk
0 Kudos
Message 7 of 10
(3,366 Views)
I tried to use your vi directly based on the screenshot, but did not have success b/c I still don't know the termination character. Instead, I thought I could just try to capture all the information and put it into an array somehow, then simply look for the termination character. Is this the wrong way to go about this? A screenshot of my diagram is attached.

Thanks!

Kirk
0 Kudos
Message 8 of 10
(3,366 Views)
There's a couple of problems that I see. If you want to just run this VI as a test to see the entire contents, then you really should use the concantenate string function as I did in the earlier attachment. If all you want is the very last thing read by the VISA Read, then you might be okay but I don't know how fast the instrument will be writing to the serial port. If you start this VI immediately and then issue the print screen command, you might read x number of bytes and then y number of bytes, and finally z number of bytes as they become available. Converting the string to an array will do nothing more than take the last string read and put that into element 0 of an array. You could just as easily turn on autoindexing of the string as
it exits the while loop and then you would have a multi-element array with the elements containing all the text. When you do your search for a termination character, you might also have to enable /codes or hex display by right clicking the string indicator, as I think it likely that the termination character might be something unprintable - i.e. a formfeed (x0C) . You might have some success doing a Google on PCL file format to see if what, if anything is in a file that indicates to the printer that the job is done.
0 Kudos
Message 9 of 10
(3,366 Views)
Wow, I really appreciate the time you've taken. I've made some great progress based on your help. I have what I believe to be the start/termination string, because it appears only twice (at the start right after the header, then at the end): (in hex) 2A74 3330 3052 0A

Right now I'm working on stopping the loop ONLY after the second appearance of the sequence, but another problem has arisen: there appears to be too-rapid polling of the serial port, because no data gets through the loop once I start it running. I've tried setting a delay on the loop but with no change in results.

If I take out the loop and manually start the vi I can step my way through the data transmission (obviously this won't work for lab use, but that is how
I was able to determine the escape sequence).

Thanks,

Kirk
0 Kudos
Message 10 of 10
(3,366 Views)