LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Issues with serial byte reading

Solved!
Go to solution

Hello,

 

I currently have a PIC18F Microcontroller communicating serially with LABview using the basic serial read and write.vi. The PIC sends strings such as "V222!" (V being header character, and ! being the ending character). I then have a program to take each individual character read and concatenate them into a larger string for data extraction. The serial port has been configured for 38400 baud and to be only one byte long.

 

The PIC transmits this one byte at a time and the problem here is that LABview seems to be only reading V most of the time, and occasinally a 2. Since it does not seem to be ever reading the ending character, the data extraction sequence of my code never gets executed.

 

A few questions I have are:

 

  • I am curious to know if LABview is just storing the data and only showing the first character (which is then the one I read) and if it is, how can I clear the buffer after reading it in time for the next character to be received?
  • Is there a simple method to configure the VISA serial port to only read one byte at a time?

 

If anyone has any advice it would be greatly appreciated. I can also post pictures of the code I have if it would help.

 

Thanks,

 

Nick C

0 Kudos
Message 1 of 8
(5,360 Views)

Do you mean you set your serial port buffer to be only 1 byte?  Then you will certainly lose data.  If you only want to read one byte at a time, then wire a 1 into the VISA read function.  Don't mess with the size of the VISA buffer for the serial port.

 

If this doesn't answer your question, post your actual VI rather than just screenshots for further help.

Message 2 of 8
(5,348 Views)

Thanks for the input Ravens Fan,

 

Since I have only ever used serial with PIC18 micros to other PIC18 micros, I thought it would be in my best interest to have LABview read only one byte that is transmitted at a time and then try and string the data together.

 

I did a little more tinkering with my code and now have the serial port receiving the correct string from PIC. I am wondering why though since the PIC sends one byte at a time, I could not read one byte at a time from LABview? I had changed the receive buffer size of the serial port to 1 byte long to try and accomplish this. 

 

I think one of the problems was that PIC was sending the data to fast to labview and it lost the rest of the character string because it couldn't process the first character fast enough. 

 

With the serial working, I do have a few other questions remaining but I shall wait until I post my code later this evening when I have access to it. 

 

Regards,

 

Nick C 

 

0 Kudos
Message 3 of 8
(5,326 Views)
Solution
Accepted by topic author Cliff89

The PIC may send one byte at a time, but so do all other devices communicating over a serial port.  The definition of serial port implies one byte at a time.  Actually it is really one BIT at a time.  But serial port settings force the gathering of 7 or 8 bits to produce a byte.  The PIC sends one byte followed by another byte, etc.  The time between the byte sendings may be too small to read them contiguously in your Labview program. 

 

At very slow baud rates it may actually work.  At 300 baud (3mS per bit), it takes 33 mS to send one byte (start bit + 8 bits + stop bit).  So if your loop runs fast enough, you could capture each byte one at a time.  But there is the overhead of other code to store the byte, etc. 

 

At 38000 baud, it takes only 0.2 mS to send a byte.  Labview isn't fast enough to loop at that rate to capture all bytes individually. 

 

But why bother?  Just capture all bytes and process them as a complete message.

 

- tbob

Inventor of the WORM Global
Message 4 of 8
(5,319 Views)

I would recommend reading the serial port as follows:

 

  •  Read from the serial port in a continuous loop concatinating each read with the proceeding read.  You can monitor the string for the termination character "!" to know that you have received the whole string.
  • Before each read, ask the serial port for how many Bytes are available to be read at the port and then read only that many
    • Many times there will be 0 bytes available which is OK as you will just be concatenating an empty string into your results
    • Make sure to use a ms wait or some other method to keep the loop from running the processor up to 100%

GetNumberOfBytes.GIF
Message 5 of 8
(5,307 Views)

Back Again,

 

First of all I would just like to thank everyone very much for their help. You have helped me understand serial and LABview a little bit better. I do have the program running to my liking now.

 

@tbob

 

I did take your advice and am now receiving the full string and then processing it from there. Also, thanks for the explanation why it was not receiving everything, that helped a lot in understanding the problem.

 

@Faraclas

 

Thats exactly the program I had before, the loop would then exit after it received a "!". It turned out that the PIC was just sending the information to fast for LABview to read it that way. 

 

Regards,

 

Nick C 

0 Kudos
Message 6 of 8
(5,287 Views)
 i want to connect the pci6251 to pc.. i am not getting to which port should i connect the pci board.. could anybody help me 
0 Kudos
Message 7 of 8
(5,264 Views)

Hello Ravi-

 

     To connect a PCI card to the PC, you have to open the computer and place the card in one of the available PCI slots - should be parallel to your hard drive.  You will see the horizontal connector in the PC and the slot on the back where the connector comes out.  Just make sure the PCI card is pushed all the way into the horizontal connector and you should be good to go.

 

     Be sure to create new threads when there are new issues.  This will ensure that both you and the original poster will both get the support they deserve Smiley Happy

 

     I hope this helps!

Gary P.
Applications Engineer
National Instruments
0 Kudos
Message 8 of 8
(5,232 Views)