03-24-2017 04:17 PM
I am sending serial data to labview from a PIC32 specifically the PIC32MX340F512H. I am trying to graph the position of the potentiometer. I have values that are input ranging from 0-1023. When I try graphing it, the graph plots 1 byte each time which is giving me an unwanted graph. For example, for the number 1023 it will plot 1, then 0, then 2, and then 3. How do I fix this problem?
Note: I am a beginner with LABVIEW and have minimal experience.
Solved! Go to Solution.
03-24-2017 04:24 PM - edited 03-24-2017 04:27 PM
What does your incoming data look like?
You are reading 4 bytes at a time. Are you sending ASCII characters "0" "1" ... "9"? Are you they padded with zeroes? ("1024" is for bytes, but "12" is only 2)
What does your device's code look like? Are you sending a termination character? (For a 4 digit number string, you should be reading at least 5 bytes so that you can the 4 characters and the termination character. If you probe the error wire or put an indicator on it, is it telling you anything?
What is going on with your shift registers? You have a shift register you are sending data to at the right side of the loop, but you aren't using the left side shift register, just using the plain tunnel. Either get rid of the ordinary tunnel or get rid of the shift register.
03-24-2017 04:35 PM
I am sending ASCII characters but they are read as strings which I converted to numbers from 0-1023 by labview.
The device code is attached. I am not sending any termination character. I am not sure which error wire you're referring to.
Yes my program got a little messed up I made this program from multiple tutorials on youtube. I was going to send that to the visa close object box.
03-24-2017 05:20 PM
I'm not familiar with the sprintf function, so I had to to google it and found this.
https://www.tutorialspoint.com/c_standard_library/c_function_sprintf.htm
The most interesting part of that said "
If successful, the total number of characters written is returned excluding the null-character appended at the end of the string, otherwise a negative number is returned in case of failure."
So it sounds like it is sending a termination character, but that character is a null-character which is decimal 0 or hex 00.
Your Serial Configure in LabVIEW doesn't have the termination connectors wired in, so it uses the default values of enable and the linefeed character (decimal 10, hex 0A).
I think you are having issues with the read not terminating until you get the 4 bytes you read because it didn't get a linefeed character. But you get a null character in there and that is disrupting the conversion from the valid ASCII characters you do get when things get out of sync.
Don't learn programming by watching Youtube videos. You are better off googling for written programming references. I know there are better examples out there for out to send data through a microcontroller serial port.
The NI forums have a user group for Arduino. LabVIEW Interface for Arduino (LIFA) I know your device is not an Arduino, but the code that can be programmed on that looks similar to your controller.
Find a version that sends a better defined termination character. Or if you can be sure it sends the null character as a termination character, you can wire a 0 to the termination character input of the VISA Configure. And you should read more than 4 bytes. At least 5, if not more, just so you can be sure that you get the full 1024 and the termination character when you do the VISA Read.
03-24-2017 05:41 PM
Here's an idea. Try putting a \n in the format string in C so it looks like "%d\n". Then when you send the buffer, try to send it with strlen(buff)-1 because I think you need to cutoff the null character at the end of the string, but it would now follow the linefeed character that LabVIEW wants.
03-24-2017 11:18 PM
Thank you for the help. I didn't know about the termination character that was being sent. Labview wasn't picking up the 0 at the end of sprintf which is probably cause my UART was set to send everything except that. I just decided to send the '\n' after each value in my PIC code and now it reads it perfectly. I also added the concatenated string to append the values together.
What I don't understand is what does the Visa property node do? When I added this it would not show any values.
03-24-2017 11:22 PM
Which VISA property node? I don't see any in the code you've posted so far. And there are lots of different VISA property nodes you could have added.
03-25-2017 01:18 PM
I saw numerous people use the instr visa property node with the number of bytes serial property going to the byte count of the read visa block.
03-25-2017 03:40 PM
Okay. The Bytes at Port property node you'll see used in the NI Serial Basic Read and Write example. It is not a good example. I find that Bytes at Port should not be used in perhaps 95% of programs using serial communication. When you have a defined termination character, or a well defined communication protocol, don't use it.
The most common mistake is people will write a command, immediately check bytes at port, and read that many bytes. Without a sufficient delay between the write and bytes at port check, they have not give the device enough time to read the command, act on it, and send back a response. They'll get 0 bytes at port and proceed to read 0 bytes, which means they get nothing.