Command GetNumCharsWaiting() in Subroutine

I have a subroutine that opens a TCP pipe to an Ethernet device. The process for the subroutine is:

  1. Open a TCP pipe to the ethernet device
  2. Send a command string to the device.
  3. Check for a waiting return value using GetNumCharsWaiting()
  4. Get the string using the ReceiveNChars() command. Using the number of characters returned above as an argument to the ReceiveNChars() command.

When I step into the subroutine in debug mode it returns the correct number of characters. When I step over the subroutine it returns a 0 as the number of characters waiting.

What is going on? Have I found a bug?

Is the subroutine parameter holding the number of characters a literal or a variable? If you want to see the value from the subroutine it needs to be setup as a variable.

The number of characters is a variable within the subroutine; it is not passed out of the subroutine. The subroutine uses this value to receive a string with ReceiveNChars() that is passed out of the subroutine; the parameter passed out of the subroutine is a variable string.

So I assume you are calling GetNumCharsWaiting in the subroutine? In debug, once you step out of the subroutine, you can no longer see any of the variables inside it.

No, that’s not what I’m seeing. When I step into the subroutine GetNumCharsWaiting returns a proper value. When I step over the subroutine GetNumCharsWaiting will return a 0 value, an incorrect value, for the number of characters waiting. In both cases, GetNumCharsWaiting is called from inside the subroutine.

How are you viewing the value returned by GetNumCharsWaiting?

I added a temporary return value to the subroutine.

Is this temporary value parameter setup as an integer variable?

The temporary value was set up as an integer variable.

Does your subroutine loop back if there are no characters waiting and wait for them to arrive?

I suspect when stepping over, there are no characters waiting because they haven’t arrived yet on the network.

My subroutine does not loop back. Can you give me an example?

image

This flow will wait for some characters to show up or timeout.

1 Like

This thread is a really solid one that has helped a lot of people get up and running.
Review both the thread posts and Mary’s link.