LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

controlled reading from serial port

Solved!
Go to solution
I'm trying to establish a connection to an external device through the serial port. This is done in a while-loop which sends an association request tries to get a response if a response is not recieved a new rewuest is sent, etc. At the moment this procedure does not work. I am considering two explanations for this. The first is that the loop does not wait long enough for a response to come and simply keeps pumping out requests, the other is that there is something wrong with the reading algorithm, that doesn't let it properly take in information from the serial port.
Download All
0 Kudos
Message 1 of 16
(4,017 Views)

Hi,

 

First: Are you sure that you serial communication work? Did you try HyperTerminal on Serial port?

 

Second: How long is delay on device between receiving  command and sending response to host PC? Are you waiting to this response? 🙂

0 Kudos
Message 2 of 16
(4,007 Views)

Not hyperterminal, but other programs, and I am pretty sure it works.

 

Delay on device? Are you asking about the hardware or the program? The program has no delay functions.

0 Kudos
Message 3 of 16
(3,994 Views)

I made a new version of the read case. The old version was a while loop, the new version is a while loop which will go on until it encounters an EOF character. In this case it is

0xC1 or 'Á'. I thought the old version would break before getting any message. This doesnt get any signal either. I have probed it, and it doesn't get a string from which to take the length.

0 Kudos
Message 4 of 16
(3,971 Views)
Solution
Accepted by topic author Tzench
Have you even considered that the 'association request' that you are sending is not correct. More often than not, the reason you aren't getting anything to read is because you are not writing correctly. You have not posted anything related to this function and posting an image is not the best way to get help in this case. For certain types of writes, it's important to know whether your string control/constant is set for normal display, '\' Codes Display, or hex display.
0 Kudos
Message 5 of 16
(3,959 Views)

When you send command to external device ... device must processing this command and after transmit response. And there is same delay.

 

 When you are reading from port, first try how many bytes are ready on port for reading.

0 Kudos
Message 6 of 16
(3,956 Views)
Dennis: Does this setting affect what is actually sent out of that VI? Anyway here is the Association Request. It might look a bit weird at first, just concatenating a bunch of constants, but according to the protocol I'm using, this could theoreticaly look different in different situations, and I'm trying to be prepared for that.
0 Kudos
Message 7 of 16
(3,928 Views)
JCC: How would you suggest using the 'bytes at port' instrument? wait until it gets one byte and then wait until it gets an EOF?
0 Kudos
Message 8 of 16
(3,922 Views)

How look like you response package? Are there same BOF and EOF bytes on begin and end? Because after is better do something like:

 

- Open Com port (set speed, ..., set size of IO buffers)

-  Flush IO buffers

No when you have loop with transmitting and receiving do something like:

- Flush IO buffers (befor you send commend)

- Send your command to device

- Read response. But you are looking for BOF and you are reading everything to EOF

- and now you have complete response package - and no you could parse this response.

 

If value of EOF could be include inside between BOF and EOF is better when you disable Termination Character

0 Kudos
Message 9 of 16
(3,912 Views)

I don't really think it is a problem, but how do you flush the I/O-buffer? Is it done automatically when you open a VISA-session?

 

The BOF-character is 0xC0 and the EOF-charcter is 0xC1. These characters are guaranteed not to occur within a frame through a system of escape characters.

 

I've made some sniffs of this communication before, and sometimes you can see a couple of zeroes between the end of a frame and the beginning of another. I suppose this does not represent an actual transmission of zeroes but rather the "sampling" of a silent serial port.

0 Kudos
Message 10 of 16
(3,907 Views)