ni.com is currently undergoing scheduled maintenance.

Some services may be unavailable at this time. Please contact us for help or try again later.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Why can't I get the same size of data from using Bytes at Port in VISA property node.

Hi,

I need to get the same size of data from the device at once whenever I get.

I tried to use the Bytes at Port to see if the data is received.

But the number of data received was different.

I don't know what I make any mistake.

Thanks,
0 Kudos
Message 1 of 14
(3,938 Views)
Sorry, I forgot to attach the file.
0 Kudos
Message 2 of 14
(3,915 Views)
Sorry, I forgot to attach the file.
0 Kudos
Message 3 of 14
(3,914 Views)
I'm not entirely sure what you're trying to do. Bytes at serial port tells you how many bytes are waiting at the moment in the buffer that exists in the serial port. To read the data, you need to use the VISA read VI and tell it how many bytes to read from the port. Is the serial instrument sending data on its own? If so, the number of bytes in the port will keep getting bigger, because you're not reading from the port and the serial device is writing to it. Tell us more about what you're trying to do, what kind of instrument you have and what kind of string does it send.

___________________
Try to take over the world!
Message 4 of 14
(3,901 Views)
Serial device: is only available for transmission (22,590 byte)

I am writing an application that can receive all data from our specific device, display out to the graph or table and also save it.

While the device transmit 22,590 byte to buffer in the pc, the application should wait until the received data is full and then read the data using VI Read.vi at one time.

I'd like to detect a COMPORT with a RS-232 cable as soon as one byte is received.
(I think it's impossible to find it before receiving.)
So I made it can find some available COMPORT lists using VISA Find.vi, and tried to check which comport connected to RS-232 cable when the first byte was arrived.(using Bytes at Port property node)

But the problem is that the number of the received data in the buffer is different whenever I get it. It's likely to work well when using one while loop, or one Bytes at Port.
0 Kudos
Message 5 of 14
(3,899 Views)
To read 22,590 b, I think you should wire -1 into the timeout input of the config VI (-1 means "wait forever", I presume this will work the same in serial) and tell the read VI to read 22,509 b. This way, whenever the code gets to the read VI, the read VI won't return until it has read 22,590 b. If this doesn't work, you can always use Bytes at serial port until the number is big enough and then read the number of bytes you want.
About automatically finding the port - isn't the device always connected to the same port? If so, you only have to wire the appropiate VISA reference (for example, COM1, which is represented by default as ASRL::INSTR1). There is no need to search for the port (unless what you're interested in is knowing when it is connected, and for that case, I think the method I mentioned earlier should work.

___________________
Try to take over the world!
Message 6 of 14
(3,893 Views)
Thanks for your advice in advance.

I think it's not enough to tell you about more detail information about the configuration.

The 22,590 is the maximum number of byte which can be received from our specific product (for medical use).

And the end-user for using my application can be someone who work for a hospital. So they can be confused which port is right or can make a mistake to connect a cable to an appropriate port. In addition, when using an usb to serial adapter, as you know, COMPORT value probably change (depending on the driver).

I'd like to tell the end-user that which port is available and they connect to the appropriate port.

When I used one Byte at Port property node in one while loop to see if the full data is received, the data was always exactly received. But, after adding to the property node, while-loop and case structure to check the cable, loss of data has been occurred. (for example 22,948, 22,930, ...)
0 Kudos
Message 7 of 14
(3,873 Views)
I'm not sure whether there is a way to check which port has the device connected without writing code, since you need an explicit VISA reference to a specific port to use the VISA VIs (at least the ones I know), so you have to know the port. You could write code to cycle through the ports until one is found that doesn't have an error.
I only have experience with one serial to USB converter, and that one, once installed, keeps a specific port (in this case, COM 4) and doesn't change. Even if the device is connected and disconnected on a regular basis, you can force the user to have only one available port in the hardware. Then, you configure the program once and save the data.
It's possible that the second Bytes at port VI runs too soon and so you don't get all the bytes sent, because they didn't get there yet. Did you try doing what I suggested (using a -1 timeout and a VISA read)?

___________________
Try to take over the world!
Message 8 of 14
(3,856 Views)
Hi! tst.

The method you suggested is very simple and easy to read data.
But, I think it's only able to read. I have attempted to display error message to let the end-user know his or her mistake when the serial cable connected to the port which is different from the port set by user.

Our device has an one way communication now. It just send data to the buffer in the PC. So I can't use VISA Write to find which port has the device.
Instead of that, I check when the data is arrived in the buffer (at least more than one byte)while the available ports references (a few of ASRL::INSTR1~9) which wire into the VISA resource terminal of VISA config.vi change automatically in a while-loop. Once the data is arrived, the application compare the port reference set by user with the port received data. And if they are the same, keep receiving until it has full data and if not, stop running and display error message.

But the problem is that I can't receive the exactly number of byte(=29520 byte) when receiving in the buffer. To read data is the next work.

Thanks,
0 Kudos
Message 9 of 14
(3,843 Views)
OK. Let me see if I got this straight.
You have a device transmitting data, which is connected and disconnected on a regular basis (is it?). You want LV to recognize which port the device was connected to and then to read the device until its disconnected and go back to listening mode, right?
So - here's how: when you detect the device (using the bytes at port VI) start reading from it using a long timeout (not -1 but, for instance, 10000 or 20000) in a while loop. As soon as this comes back with a timeout error it probably means that the device was disconnected and you should exit the loop and go back to listening mode. If my understanding is wrong, I suggest you elaborate on your exact setup - how you want the system to behave, how will the people in the system behave and so on.

___________________
Try to take over the world!
Message 10 of 14
(3,837 Views)