LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Serial Communication with micro controller

I had almost the exact same problem. You need to put a delay between the write and read vi's.Imight be able to send you a copy of the vi. National helped me out with this one.
0 Kudos
Message 21 of 31
(933 Views)
I couldn't find the example so I just wrote a new one. Here it is and let me know if you have any problems.
0 Kudos
Message 22 of 31
(930 Views)
Let's try that again and with the attachment.

I couldn't find the example so I just wrote a new one. Here it is and let me know if you have any problems.
0 Kudos
Message 23 of 31
(929 Views)
Thanks for the example. It works, however I have to run the program twice to get the accurate output. Any reason why?

Peter
0 Kudos
Message 24 of 31
(925 Views)
Hello,

So it sounds like your serial port is working on your host side, just not on the microcontroller side. You may want to check the documentation to see that your microcontroller sends back ascii characters... perhaps you are receiving data in a binary format, instead of ascii. For example, when you query for the version, perhaps you are sent back the byte representation of, say, 1.5 instead of the 3 ascii characters for 1.5. Since the interface to the serial API is string, you would see the character interpretation of the binary data representing 1.5 and not the 3 characters. In fact, you may be able to check this if your version is indeed non-integer, since the binary returned value would like be returned in IEEE floating point form. Try type casting the data to type float (you may want to try both dbl or sgl in LabVIEW; you'll find the type cast in the Advanced -> Data Manipulation palette).

Hope you have success!

Best Regards,

JLS
Best,
JLS
Sixclear
0 Kudos
Message 25 of 31
(936 Views)
attached example uses compatible VIs for serial comm...

btw, if our use \code.... try adding either \n or \r but not both \n\r together.

good luck

Cheers!
ian.f
Ian F
Since LabVIEW 5.1... 7.1.1... 2009, 2010, 2014
依恩与LabVIEW
LVVILIB.blogspot.com
0 Kudos
Message 26 of 31
(920 Views)
Hi,

I am unable to load your vi. I am missing "func serial Read with timeout" subvi.
0 Kudos
Message 27 of 31
(908 Views)
One of many ways to comm with Serial Port is by using function VIs from within the serial.llb found here

..\Program Files\National Instruments\LabVIEW 7.0\vi.lib\instr\serial.llb


[Serial Port Init]
- Configure and Init the Serial Port with this VI (baud-rate etc)

[Serial Port Read/Write]
- Send/ Fetch

[Bytes at Serial port]
- Bytes count at Serial Port
- Use this VI to check no. of bytes available at the Port

[Close Serial Driver]
- Close the Serial Port when VI exits.

Note:
To be able to enter \r or \n at the end of command string (in String control), simply right-click on the String input control, select '\'Codes Display. Therefore try version\r or version\n but not both \n\r.

hope this info helps you in one way or another!

Cheers!
ian.f koo

http://forums.ni.com/ni/board/message?board.id=170&message.id=109251
Ian F
Since LabVIEW 5.1... 7.1.1... 2009, 2010, 2014
依恩与LabVIEW
LVVILIB.blogspot.com
0 Kudos
Message 28 of 31
(733 Views)
try this out ya!
Ian F
Since LabVIEW 5.1... 7.1.1... 2009, 2010, 2014
依恩与LabVIEW
LVVILIB.blogspot.com
0 Kudos
Message 29 of 31
(836 Views)


@Dennis Knutson wrote:
But you didn't get this error when you got the garbage characters and some partial data? How are specifying the number of bytes to read? If you specify too many bytes to read, you'll get the error. Are you sending the command and then using VISA Bytes at Serial Port to determine how many bytes are available? Do you have VISA Configure Serial Port set to terminate read when a termination character is received? If you do and the term character is not sent, you'll also get this error. Can you attach the VI that you've written with all control values set to the values you're using?


Dennis,
Some time back you were helping someone with a problem communicating with a micro controller. You said if you tried to read too few bytes the vi times out. I'm using the Serial Read Write that ships with LV 7.1. One of our test is to verify that we do not have communications between one serial port to another. The operator keeps the cable off the UUT on the receive but has it on the send port and runs the vi. He verifies no data is received on the Read side of the port of interest. How can I handle this vi error to turn it into a pass/fail criteria for LV7.1? It looks like a Windows error message. I just want to display PASS or FAIL to the operator. I don't want to display the error message.

Thanks,
Clint
0 Kudos
Message 30 of 31
(820 Views)