Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

digital port I/O - Read and write at the same time

I am now using visual studio.net and start to implement the write and read functons simultaneously on the digital port I/O to control a motor to move using ni DAQcard. However, for my implementatoin, the motor can only be allowed to move in one direction. It seems that the reading process interferes the proper function of the write function. Without the reading part, the motor can run properly in two directions. I am so confused.

Lines 0:1 are corresponding to the read process, while lines 2:7 are controlling the motor to move. Pin 5 gives a clock pulse continuously and pin 6 controls the move direction, i.e., Clockwise and Anti-clockwise. Thanks for answering my question in advance.  Here is my code as below.

 

myTaskread = New Task()
myTaskread.DIChannels.CreateChannel("Dev1/port0/line0:7", "DigRead", _
ChannelLineGrouping.OneChannelForAllLines)
myDigitalReader = New DigitalSingleChannelReader(myTaskread.Stream)

digitalWriteTask = New Task()
digitalWriteTask.DOChannels.CreateChannel("Dev1/Port0/line0:7", "port0", _
ChannelLineGrouping.OneChannelForAllLines)

 

Dim dataArray(7) As Boolean
Dim writer As New DigitalSingleChannelWriter(digitalWriteTask.Stream)
Dim readData() As Boolean
Dim movecount As Integer = 0

If (angle_check < 0) Then
aSign = True

End If

Try


angle_move = Math.Round(angle_check / 0.72)

For step_move As Integer = 0 To Math.Abs(angle_move) - 1

For p As Integer = 5 To 5
dataArray(p) = False
Next
'dataArray(5) = True
If aSign = True Then  ' control CCW motion
dataArray(6) = True  
End If

writer.WriteSingleSampleMultiLine(True, dataArray) ' Write data
System.Threading.Thread.Sleep(CType(0.02 * 1000, Long)) 'delay

dataArray(5) = True ' Command Move pin
writer.WriteSingleSampleMultiLine(True, dataArray)

System.Threading.Thread.Sleep(CType(0.02 * 1000, Long))

readData = myDigitalReader.ReadSingleSampleMultiLine()
left_sen = readData(0)
right_sen = readData(1)

System.Threading.Thread.Sleep(CType(0.02 * 200, Long))

 

Next

 


Dim dataArray(7) As Boolean
Dim writer As New DigitalSingleChannelWriter(digitalWriteTask.Stream)

0 Kudos
Message 1 of 3
(3,606 Views)

Hello hyleung,

 

Nothing in your code jumps out at me as being particularly erroneous.  What device are you using to perform your bidirectional I/O?  Only certain devices are capable of this sort of operation, and many of them require you to configure your output and input groups in terms of "nibbles," which are groups of four bits.  Therefore, depending on your device, you may have to configure pins 0:3 and pins 4:7 in groups instead of 0:1 and 2:7.  If you can also describe the motor you are using, it will allow us to get a good handle on your entire hardware implementation.

 

I am also somewhat confused as to what you are actually asking.  It seems like you want to read and write so that you can run your motor in two directions, but currently can only move the motor in one direction doing both.  You are, however, able to move the motor properly without doing the read.  Could you please explain what you gain by performing the read?  Can you carry out your application using only a write?  Did you ever receive any errors during your coding that you could share?  What sort of data are you actually receiving from your read operation?  I can see that you're storing the results of the read in the left_sen and right_sen variables, what will these be used for?  Are there any troubleshooting steps you have already taken that I should be aware of?

 

Thank you in advance for the answers to these questions; any additional information you can provide will be useful.

 

Regards

Patrick
CLA
0 Kudos
Message 2 of 3
(3,583 Views)

Thank you for your reply. I have a good news to share with you. My code can now be worked properly. I build up two channels which are configured to use 0:1 and 2:7. I adopt a NI6100DAQ is data-acquiration card.


I modify the code like this, so the DI channels cannot be conflicted to each other, while other code keep unchanged.


myTaskread = New Task()
myTaskread.DIChannels.CreateChannel("Dev1/port0/line0:1", "DigRead", _
ChannelLineGrouping.OneChannelForAllLines)
myDigitalReader = New DigitalSingleChannelReader(myTaskread.Stream)
digitalWriteTask = New Task()
digitalWriteTask.DOChannels.CreateChannel("Dev1/Port0/line2:7", "port0", _
ChannelLineGrouping.OneChannelForAllLines)

 

Once gain, I thank you for your professional questions to let me make a clear clarifiaction. There are two sensors to sense the motor's physical positions, one for the clock-wise side and other for the anti-clockwise side. I employed them to check whether the motor has reached the desired physical position.


For your concern, I was getting no error when I implemented the above code, I found that the only problem was just that the motor cannot move at an anti-clockwise postion but always move in a clockwise postion. It can be explained that two channel built up while using the same port affects the read/write function at the same time.
Finally, I appreciate your help.

0 Kudos
Message 3 of 3
(3,554 Views)