Jump to content
  • 0

Long DIO control delay with script for UART and DIO


Jonboy

Question

I am trying create a test bed to send UART data across a cable using two RS485 Half Duplex transceivers.  These transceivers have control pins that will enable/disable the Driver and Receiver for the desired mode of operation.  In order to control the enable pins of the transceiver, I was trying to use a JavaScript to set a DIO pin high when the UART will send data, and then change it back to low so that is can receive data sent to it.  My setup uses two AD2 devices connected together and when I send UART data from one device, the other device will receive this data, look for the Line Feed character as the final character, then enable the DIO3 pin which is connected to the enable pins of the transceiver.  Once this pin is set, the UART will send the data, and then the DIO3 pin should be changed back to Low to disable the driver and enable the receiver again.  The first device should receive the data back from the second device as an echo where it could compare it with the transmitted data and check it for errors.

This script works well except for one very big issue.  There is a very long delay in changing the DIO3 pin back low following the UART send command.  I can time this by hand with a stop watch and it can take up to 3 seconds for the DIO3 pin to change to Low again.  The data is received by the second node, the DIO3 pin is pulled high very quickly, the data is sent back to the first node quickly, and then I have to wait many seconds for the DIO3 pin to change low again before I can have the first node send another message.

I have also connected the two AD2 devices directly together and I noticed that the two UARTs can transmit and receive messages as fast as the script will allow them but if this is faster than the DIO pin state change that I require for my RS485 transceivers, the DIO3 pin stays high and sometimes never goes low even when the scripts have finished executing and it doesn't appear to gate execution of additional lines of code.

Is this a bug that can be fixed, and is there a work around that will allow me to change the DIO3 pin within 10's of mS following a UART send command? Is this a Waveforms GUI related issue that I could avoid by creating a Python script using the SDK?

RS485_UART_PingPong_Script_Master.dwf3work RS485_UART_PingPong_Script_Slave.dwf3work RS485_UART_PingPong_Script_Slave.js

Link to comment
Share on other sites

5 answers to this question

Recommended Posts

Hi @Jonboy

The settings in the interface or from the script (.text = or .value = ) are not executed immediately but after a few ms timeout. This for UI responsiveness and to avoid congestion.

The Script is running in the same thread as the UI, without wait() function calls the UI is kept blocked and timeouts are late. Specially in loops, make sure to have wait() calls so the UI can function.

From the Script you can force the timeout execution with the Instrument.config()

StaticIO.Channel0.DIO3.value = 1;
StaticIO.config()
...
StaticIO.Channel0.DIO3.value = 0;
StaticIO.config()


 

Link to comment
Share on other sites

Hi @attila

Thank you!  After adding a small wait() inside loop, I now see the DIO pin changing state quickly.  Out of curiosity and generally speaking, is there a minimum amount of wait time required, or recommended for the UI?  I assume this might be somewhat arbitrary. And what is the minimum time the wait() will accept or what is the resolution of this parameter?  I can play with this value but I would like to run with as little time delay as possible but I am curious what is achievable.  Thanks again.

Link to comment
Share on other sites

Hi @Jonboy

For the fastest DIO change use the StaticIO.config() This will apply the earlier DIO settings immediately.

You can use wait(0) or wait(). This will only execute the cached tasks and return.
The wait(0.111) will execute and return after about 111ms, or earlier with false when the Stop/Cancel button was pressed.
The resolution is 1ms and the precision is about 10ms.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...