LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

VISA Serial Write is not writing

Solved!
Go to solution

I'm doing a very simple serial read-write VI with an Arduino just to figure out how to do some error handling for a more complicated project. I have a very minimal Arduino code that just instructs the Arduino to return the byte it received unless that byte is a '1', in which case it does nothing (this is to test if my code can catch and correct a read timeout). I know this Arduino code is working; I've verified it using the the serial moniter and another, previously written VI.

 

The VI I have here should be the easiest thing possible to get working; it just sends a single byte, reads the response, then if there's an error code it executes a case structure. I have determined, through some testing on the Arduino, that the VISA serial write function is not writing anything to the Arduino. I always end up with a VISA read timeout because the Arduino is not receiving any message.

 

I'm totally baffled here, I have much more complicated VI's sending the same types of messages to the same Arduino (with the exact same Serial configuration) and reading back actual data, I cannot for the life of me figure out why this one isn't doing anything. Is there something going on here that I don't know?

 

 

Download All
0 Kudos
Message 1 of 18
(2,431 Views)

Your question is missing the Arduino part.

 

LabVIEW you are sending a 2.  (What makes you think it is not being sent?)

The Arduino has some code that isn't shown.

 

You say it is working, but how do WE know it is?

 

Are you sure your LabVIEW communication settings match the Arduino's?

0 Kudos
Message 2 of 18
(2,415 Views)

Are you sure you are not getting some other error?  Are you trying to run this VI while also using the Arduino serial monitor or some other code?  Are you sure your Baud Rate is correct?  How about the other settings?

 

As already stated, we need to see the Arduino code as well in order to help debug this.  Is the Arduino using the println or the print in order to send back the read byte.  If using print, then you will definitely get timeouts because you told the VISA Read to read up to 100 bytes, ending with the termination character.  But if the Arduino is not sending the termination character, the VISA Read will time out.  Instead, you need to tell the VISA Read to read 1 byte.

 

You also really need to clean up your diagram, including using actual Error Clusters instead of unbundling the parts.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Download All
0 Kudos
Message 3 of 18
(2,406 Views)

Sorry for not including Arduino code earlier:

 

char inChar = '6';

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
}

void loop() {
  if (Serial.available()) {
    inChar = Serial.read();

    if (inChar == '1') {
      Serial.println("test?");
    }
    else {
      Serial.println(inChar);
    } 
  }
}

 

This is very slightly different than what I described before, the only difference being that now a '1' being received will cause the Arduino to print "test?".

 

The settings for the VISA connection are identical to another more complicated VI I wrote previously which connects to this same Arduino. That VI usually reads data off a sensor attached to the Arduino, and works correctly. If I load the above program to the Arduino and use this other VI, it works as expected (some other errors occur because it recieves the word "test?" when it's expecting a string with a float value, but other than this the program works, and most relevantly the write and read functions work).

 

Here is my evidence that the Arduino code works, and that the write function is the problem:

1) Using the Arduino serial monitor, I can send Serial messages to the Arduino and it responds as expected

2) Using another VI with this same Arduino running this same code I receive the expected output

3) I tried a modified version of this Arduino code that would continuously print the first message it received. After running the problematic VI I checked the Arduino using the Arduino Serial monitor and found that it had received no message

4) I have been successfully using another VI with this same Arduino, using the same Serial settings, to read data off of other devices

 

I've attached the other VI in case it's helpful.

0 Kudos
Message 4 of 18
(2,385 Views)

I am certain I am receiving a timeout error, I'm looking at the actual error code. I am just learning how to use error clusters today, this VI is just a very simple way to explore them and figure out how they work.

 

The Arduino is using println, I am using the termination character to indicate the end of the message. As I mentioned I've used virtually the same write/read code in another VI and it's working (incidentally it was another question that you helped answer that saved me from the bytesAvailable mess, so it'd all be a lot worse without that! Thanks!), I've attached that VI to another reply.

 

As a side note, do you have any specific advice on how to clean up my Labview code? I'm very knew and I definitely know I'm not writing things in a very efficient or clean way, so I'd appreciate any style tips or general corrections. Specifically do you have a link to anything describing what you meant with the error clusters? I did some googling on them earlier to work out what I have in my VI but I don't know what functions you are using in this cleaned up example, nor what the proper way to use them was. I've been unbundling them because I wanted to figure out what the actual messages were and because they feel easier to work for a newbie as more recognizable data types. Thanks for the help!

0 Kudos
Message 5 of 18
(2,378 Views)

Are you trying to run the serial monitor the same time you are running your VI?  I don't think that would work as the PC would be conflicting on serial ports.

 

Can you put in a visual indicator such as turning on an LED when it has Serial.Available?  Wait 500 milliseconds.  Then in the Else section of Serial.Available, turn off the LED.   Then you should see the LED blink when it receive a character.

 

If you say other VI's work with the same Arduino and this one doesn't, you need to figure out what is the difference between the ones that work and this one.

 

You should delete your serial controls.  You have a lot of coercion dots because you used doubles.  Most of those should probably be constants anyway.

Delete the control, write click on the input and pick Create Constant.  Edit the value to what is needed.  Now you'll have the correct datatype.

0 Kudos
Message 6 of 18
(2,372 Views)

@Tarnarmour wrote:

As a side note, do you have any specific advice on how to clean up my Labview code? I'm very knew and I definitely know I'm not writing things in a very efficient or clean way, so I'd appreciate any style tips or general corrections. Specifically do you have a link to anything describing what you meant with the error clusters? I did some googling on them earlier to work out what I have in my VI but I don't know what functions you are using in this cleaned up example, nor what the proper way to use them was. I've been unbundling them because I wanted to figure out what the actual messages were and because they feel easier to work for a newbie as more recognizable data types. Thanks for the help!


It's a little old (2007), but this book is an excellent read: The LabVIEW Style Book by Peter Bloome.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 7 of 18
(2,368 Views)

I am not running the monitor at the same time, when I've referred to checking the monitor what I mean is that I run the VI to completion, then open the serial monitor and query the Arduino (as I mentioned, I had a modified code that would cause the Arduino to constantly print whatever the last thing it read was, to see if it was the Write function that was the issue).

 

The VI with the doubles was a much earlier VI I wrote when I was trying to figure out how to use Serial reading. I had them all as inputs because I wanted to be able to experiment with how the Serial comms worked, and at the time I wasn't as aware of the datatype conflicts. I know it's in bad style, but my point is that that VI is the working one; the much cleaner, neater VI (which as far as I can tell is identical in every respect except for using constants and ints when initializing the Serial connection) is the one that is not working. I'm not really looking to improve the old one, I don't use it for anything.

 

I tried your LED indicator idea (I forgot I had an LED lying around! Getting rusty when it comes to circuit debugging) and it confirms that there is no message being received during the VI running. If I use the Serial monitor to write something to it, the LED lights properly.

0 Kudos
Message 8 of 18
(2,351 Views)

@crossrulz wrote:

@Tarnarmour wrote:

As a side note, do you have any specific advice on how to clean up my Labview code? I'm very knew and I definitely know I'm not writing things in a very efficient or clean way, so I'd appreciate any style tips or general corrections. Specifically do you have a link to anything describing what you meant with the error clusters? I did some googling on them earlier to work out what I have in my VI but I don't know what functions you are using in this cleaned up example, nor what the proper way to use them was. I've been unbundling them because I wanted to figure out what the actual messages were and because they feel easier to work for a newbie as more recognizable data types. Thanks for the help!


It's a little old (2007), but this book is an excellent read: The LabVIEW Style Book by Peter Bloome.


I read it front to back.  Bob Schor said he read it front to back 3x.  It was my bible before I developed my own style (based quite a bit on the book).

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 9 of 18
(2,344 Views)

It sounds like a good resource but to be honest I really don't want to drop $100 on it, I'm not sure how long I'll be using LabVIEW in this current job but I will not be able to justify purchasing this with company money, and I don't really want to use it for personal use (I really prefer traditional non-visual coding languages, though I fully admit this may mostly be due to lack of experience and poor style habits). Do you know if there's anything similar (if less thorough) available online? Or even just some threads here going over some basic rules that you think are particularly good?

0 Kudos
Message 10 of 18
(2,337 Views)