Digital I/O

cancel
Showing results for 
Search instead for 
Did you mean: 

Reading and Writing to a port

Solved!
Go to solution

Hi,

 

I had been trying to read and write to a port using the .Net 3.5 example codes that are supplied with the controller. Examples\DotNet 3.5\Digital\Generate Values\Write Dig Channel and Read Dig Channel. Regardless of what value I write I always get positive output read and all the bits are high on thge channel. To reporoduce the issue simply run both programs at the sametime Write Dig Channel and Read Dig Channel. Set the port to  Dev1/Port0/line0:7 in both tests and write a value that is negative to one or all the channels. When you read the values, the values are all positive. I have tested using the example code in VB and I am getting the same results. Please note that the controller is working correctly when I run the measurement and automation test. I have looked at the Forums and I found the post at:

http://forums.ni.com/t5/Measurement-Studio-for-VC/Basic-questions-about-PCI-DIO-96/m-p/242296 The article name is Basic questions about PCI-DIO-96 and it states that the values written should persist. Any ideas on what I can be doing wrong?

 

Thanks, Magued

0 Kudos
Message 1 of 11
(4,692 Views)

Magued,

 

I ran a simple test here on my end using test panels and confirmed your findings, which is to be expected. The way that the device works is that it will constantly be driven high on startup and will stay high unless driven low. What Is the Power-Up State of My Digital Input/Output (DIO) Board?. This provides some additional information on the power up states of DIO boards.

 

For example, lets say D0 line 0 is connected by wire to DI line 1. DI 1 will start out high, and then you set DO 0 to low, DI 1 will then be driven low and will stay low as long as the DO is connected, when it is no longer connected the digital line will go to its default. When you create the task again with the same lines, your signal is going back to its default state and line 0 is no longer set low, but is reset to its default. When you read line 0 again, you see a high value.

 

A better test to run would be to set the write channel to line 0 and the read channel to line 1, and have  wire connect between the two. Then when you run the write task and then run the read task, the read task should read the previous state from DO 0 as long as the devices are connected. I hope that this helps, but if you need additional clarifications, don't hesitate to ask. Thanks! 

 

 

 

Frank,
National Instruments
Software Group Manager
0 Kudos
Message 2 of 11
(4,654 Views)

Hi Frank,

 

Thanks for your reply. We have a huge real time application that is built using the traditional NI-DAQ. In the application we set outputs to 0 or 1, then read the status of the output bit and display its actual value. If we need to hard wire the inputs to monitor our outputs then it will cut the number of our assignment pins into half and this will require hardware changes that are complex. 

The traditional NI-DAQ supported this functionality, the 8522 devices support reading the status of output bits and ports. The question does the new DI-NAQmx supports this functionality? And if it not supported then why? Is there a workaround?

I am attaching a screen shot that shows the Test panel using the traditional system. Note that you can read the status of the output port and it doesn’t reset to the default value.  

 

Thanks, Magued

0 Kudos
Message 3 of 11
(4,636 Views)

Magued,

 

The PCI-DIO-96 uses an older chip than what most of our current DIO hardware uses. This chip did allow for you to do both reads and writes on the same line, but this functionality is only possible with Traditional DAQ. DAQmx was designed to abstract much of the low level functionality, which elminated the ability to control the registers that are necessary for this sort of task. Our modern DIO cards are not capable of this functionality, and so reading and writing on the same port is not a typical procedure. Typically you specify a single line as either a read or a write line and not both as Frank explained. However, since the PCI-DIO-96 allows you to do this with Traditional DAQ, check out this KB for more information. This is not an intended use case and is thus not really supported. I would recommend using the DAQmx driver with external connections for reading and writing.

National Instruments
0 Kudos
Message 4 of 11
(4,626 Views)

Hi Beil,

 

We are talking about thousands of line of code that has to be changed and we would like a resolution. 

Is there a software solution or any work around? Any code we can add to accomplish what we had in the legacy system?

 

You also have the new NI PCI-6509. Would that chip be able to do the required functionality? Please note that even if the PCI-6509 would support the functionality we still want this issue resolved for the PCI-DIO-96.

 

Thanks, Magued

0 Kudos
Message 5 of 11
(4,596 Views)

Hi Beil,

 

Thanks for the reply to the support case. I am posting your resolution here in case someone else have the same issue:

----------------->

After speaking with our R&D department with the DIO-96 you read from the line you are outputing on very simply in DAQmx. If you have your task configured for output, then you just need to read on that channel. This is done easiest on the same task. Thus it is not as easy if you have two separate applications. This does not work for input tasks and it must be static DIO. Alternatively you can change the tristate property depending on whether you are doing input or output. Setting the tristate value to true allows for input and false for output.

<-----------------------

 

In code add the following to the  WriteDigChan example and it should work:

 

 

Dim myDigitalReader As New DigitalSingleChannelReader(digitalWriteTask.Stream)

readData = myDigitalReader.ReadSingleSampleMultiLine()

 

Magued

 

 

 

 

0 Kudos
Message 6 of 11
(4,578 Views)

Thanks Magued for posting my correction.

I want to follow up with a bit more information. The method I explained will allow you to verify what you are driving the line to. If you would like to read a digital signal from an external device on that same line, you will need a slightly different setup. You will need to dynamically configure the tristate of the line at run time. The tristate will need to switch on and off in order to switch from output to input. This is because we don't want two devices to be driving the line at the same time. This could cause many complications, and could potentially damage your device (See the caution here).

National Instruments
0 Kudos
Message 7 of 11
(4,570 Views)

Hi Beil,

 

The provided solution will work for our application.  Still I would like to know the resolution for reading from an external device on that port and how to configure the tristate of the line at runtime.

 

Thanks, Magued

0 Kudos
Message 8 of 11
(4,552 Views)

For DAQmx there is a property node that you can use to change the state of the device at runtime. You should also be able to do the same in Traditional DAQ using property nodes (DO.Tristate). As far as the resolution of a digital signal, I am a bit confused by what you mean as resolution typically is related to analog signals. Some clarification of what you mean would be helpful for us to continue to assist you.

Frank,
National Instruments
Software Group Manager
0 Kudos
Message 9 of 11
(4,522 Views)
Solution
Accepted by topic author Magued

Here is a LabVIEW and a VB example that demonstrate using tristate to switch between output and input. The Output setting will allow you to drive the liine and read back what you wrote. The read setting will allow you to read an external digital signal. Please excuse the fact that these are both rough and unofficial examples.

National Instruments
Download All
0 Kudos
Message 10 of 11
(4,485 Views)