01-24-2024 12:42 PM
I have successfully used PFI0 as a counter input on my USB-6002, with C# :-
task.CIChannels.CreateCountEdgesChannel("Dev1/ctr0", "Count Edges", CICountEdgesActiveEdge.Falling, 0, CICountEdgesCountDirection.Up);
I now need to use PFI1 as the input, instead of PFI0. I think I need to first use DaqSystem.Local.DisconnectTerminals() and DaqSystem.Local.ConnectTerminals() to disconnect PFI0 and connect PFI1 prior to starting the task, as follows:-
DaqSystem.Local.DisconnectTerminals("/Dev1/PFI0", "/Dev1/Ctr0Source");
DaqSystem.Local.ConnectTerminals("/Dev1/PFI1", "/Dev1/Ctr0Source");
However I get an exception upon task.Start() - "NationalInstruments.DAQmx.DaqException: 'Specified route cannot be satisfied, because it requires resources that are currently in use by another route."
Perhaps that is because PFI1 is already assigned to Port1? If so, I can't see how to disconnect that.
Any help would be greatly appreciated!
01-24-2024 03:08 PM
I don't know the C# syntax, but one usually doesn't need to use the system-level calls to Connect or Disconnect terminals. There should be a task-level setting available for selecting between PFI0 and PFI1 (supposing your low-cost USB device supports this choice).
In LabVIEW, I'd be using a channel property node to set the "source terminal" for the edge counting task. See if you can find a similar setting in the C# API.
(Note: because of the monkeying around you've been doing with Connect and Disconnect, I'd recommend you first go into MAX and reset the device to clear out any such system-wide signal routes and resource usage.)
-Kevin P
01-25-2024 08:31 AM
Hi Kevin, thank you for the response. Unfortunately I can't find the C# task-level way of doing this. Interestingly when I use the DaqSystem approach it does seem to connect PFI1 to Ctr0Source - I am sure of this because my subsequent task.Start() then complains that it wanted PFI0 allocated but found PFI1 already allocated. Maybe the CreatedCountEdgesChannel() needs something other than "Dev1/Ctr0" for its counter parameter to specify it's to come via PFI0, but I can't find any documentation to that effect.
I've spent an embarrassing 2 days on this, I think I will have to leave it and instead feed both of my inputs into PFI0 and use hardware to ensure only 1 is active at any one time.
01-25-2024 11:20 AM
Before giving up, check your device docs and MAX for some further help. Those will at least help you identify the default routings between PFI pins and internal counter i/o pins (source, gate, out, aux on some devices). Max also has "test panels" that'll let you try out edge counting with various combos of Ctr # and PFI #.
-Kevin P