11-05-2009 04:46 AM
Hi,
I have used the LabView VISA functions before and know that you can use the bytes at serial port function to check for the number of bytes at the serial port and then wire that in to the input (number of bytes) of the VISA read function.
This time I am using the cRIO-9073 chassis and I have the RS232 9870 module. Is there any way that I can determine how many bytes there are at the serial port?
I am using the serial loopback example but in the example the user has to set the number of the bytes manually, I need the program to look at the number of bytes at the serial port and read those.
regards,
Harshil
11-06-2009 10:43 AM
Dear hkhiroya
This does seem simple enough.... using 2 VISA read functions, set the first VISA read resource name to the serial port you are reading from. Using the second VISA read function wire the return count from the first VI to the byte count of the second VI. This will read the byte count from the serial port and then send this data to the read function of the second. Use a numeric indictor along the same line to see what the byte count is.
Please be aware this function might return less than the number of bytes requested if the function reaches the end of the buffer, reaches a termination character, or if a timeout occurs.Please let me know if this is of use.
11-06-2009 04:34 PM
Harshil,
You will not be able to use VISA commands with the 9870 module and cRIO. A common way to implement this module is to continuously read the port from FPGA and let it time out if there is no data. Pass all the U8 you recieve into a DMA FIFO(target to host). Then, you can use the FIFO read function to pull the number of bytes available in the FIFO and know how many bytes are 'available'
11-10-2009 09:19 AM
Dear hkhiroya
My mistake, after looking into this a bit more I agree with Robbob's post. Use the FIFO read function to pull the bytes and see how many are available. Please let me know how you get on. Many thanks.
11-12-2009 04:26 AM
Hi,
Thanks for the help.
The problem I have is I cannot use FIFO as I am using the chassis on hybrid mode, thus I do not have enough channels on the target.
I am using the 9000x interrupt example from the (Serial loopback example), I have got it semi working. The problem I have is, the bytes at serial port indicates that it has 5 bytes but the read vi only reads 4 bytes!! It misses the first byte. E.g I am sending ''hello'' and receiving ''ello''.
Why is it doing this?
I have attached screenshots of the FPGA and the CRIO vi.
Regards
Harshil
11-12-2009 09:29 AM - edited 11-12-2009 09:32 AM
11-12-2009 10:42 AM
Harshil,
Hybrid mode uses 2 DMA FIFOs, so unless you are using the other channel for something else in your program you should still have one available.
While I am not sure what exactly is causing the only 4 bytes read, there are some obvious mistakes that I see that should be fixed.
First, your open/reset/run are inside the while loop. I assume you dont want to continuously reset your FPGA, so I would move these outside the while loop. Same with the close FPGA reference, move this outside as well.
The issue I see is that you wait on IRQ and also acknowledge the IRQ in parallel. Think about your data flow for a second and trace how these events will happen...you will find that you will lose information here. All of this needs to happen in serial, depending on how you want your app to run. I believe the example is supposed to call an IRQ for every byte read(I may be wrong, its been a while) and then the host reads a single byte each iteration.
11-13-2009 08:04 AM - edited 11-13-2009 08:08 AM
Hi Harshil
I have been looking into this some more and I know why you are only pulling 4 bytes of data. First of all I would follow the guidelines to tidy up your code outside the while loop stated previously as you indeed do not always want to read from the FPGA.
First you need to set the UARTs receive FIFO size from 4 to 8 and to read 8 bytes at a time in a loop. The 16550 series UARTs incorporated a 16-byte FIFO with a programmable interrupt trigger of 1, 4, 8, or 14 bytes. You have your trigger set on a 4 byte trigger I believe and therefore it does not read on from this. You can set the FIFO size in software on most
modern UARTs. The following should get you there on an XP machine
(similar on others):
1. Open the Device Manager.
2. Expand the Ports (COM & LPT) tab.
3. Right click and select properties.
4. Click the Port Settings tab.
5. Click the Advanced... button.
Here
you can change the receive buffer (FIFO) size to 8. Then you can read 8 bytes at a time in a loop and you will have the latest 4 bytes of data
all the time. If necessary, you can keep an accumulator value in SW to
monitor the total number of bytes received over multiple reads/loop
interations.
I have also included some added information on serial communication to explain anything you do not understand
http://digital.ni.com/public.nsf/allkb/E0D95CB9249FB8CF86256C68007B1F81?OpenDocument
And to explain the UART 8 byte buffer size more please see:
http://zone.ni.com/devzone/cda/tut/p/id/4052#toc1 (REF:Serial Communications Hardware Concepts and Hardware Overrun Errors)
11-13-2009 09:53 AM - edited 11-13-2009 09:53 AM
David,
Please recall that Harshil is using a CompactRIO Chassis with a 9870 module.
These types of settings are not available in any way through Windows XP settings. The only settings the user has access to for the 9870 are through the project module properties dialogue, and those will be for baud rate, parity, stop bits, etc.
The problem here is most likely improper data flow, with a wait on inturrupt and acknowledge inturrupt being called in parallel.
Hashil, do you always get 'ello' from 'hello' or is the behavior intermittent? Also, please let us know how everything works out after moving the open reference, etc, outside of the while loop and moving the IRQ acknowledge into the proper places.
11-16-2009 04:02 AM - edited 11-16-2009 04:03 AM
Hi Guys,
Thanks for your help.
Here is an update to what I have done and the problems I am currently facing.
I have got rid of the while loop for now and so the vi would only execute once. Also I have changed the way I read bytes at port in the FPGA vi. Instead of having it in the while loop and the read case structure I have created a separate while loop that only looks at bytes at port in the FPGA vi, therefore I do not need to acknowledge the IRQ (please see screenshot attached).
This works fine. However I now have two problems,
1. The read function only reads 61 bytes. If I write anything above 61 bytes I only receive the first 61 bytes. Anything below 61 bytes and I get the whole mesaage back. (please see attached screenshot). Why is it doing this? Is my read limit 61 bytes?
2. The vi (criovi) executes well sometimes, however sometimes I would set it to run and it stay there not finishing. I have to manually stop it. Why is this?
Your help is much appreciated.
Regards
Harshil