12-21-2022 12:44 PM
Hello,
I am trying to turn on a relay which is connected to a pump and can switch it on and off via LabView. The board installed on my computer (PCIe-DIO96H) allows me to control the relay with LabView. I am trying to utilize the samples of "ULx Write Dig Chan" and "ULx Write Dig Port" provided by LabView software package, but I have not been successful yet. I am not clear on the difference between "Port", "Channel", "Line", and "sample" so I guess that's the reason that I have difficulties choosing the right option for "ULX Write.VI".
Once I run the above code, I get this error message:
Measurements: Write cannot be performed, because the number of channels in the data does not match the number of channels in the task.
When writing, supply data for all channels in the task. Alternatively, modify the task to contain the same number of channels as the data written.
Number of Channels in Task: 1
Number of Channels in Data: 96
I was wondering how I could change the "Number of Channels in Task" to match with "Number of Channels in Data".
Could anyone please help me understand the difference between the mentioned terms and modify the sample codes to achieve the mentioned purpose?
Best Regsrds,
Amirhossein
12-22-2022 12:48 AM
@Amir1992 wrote: DMV Now
Hello,
I am trying to turn on a relay which is connected to a pump and can switch it on and off via LabView. The board installed on my computer (PCIe-DIO96H) allows me to control the relay with LabView. I am trying to utilize the samples of "ULx Write Dig Chan" and "ULx Write Dig Port" provided by LabView software package, but I have not been successful yet. I am not clear on the difference between "Port", "Channel", "Line", and "sample" so I guess that's the reason that I have difficulties choosing the right option for "ULX Write.VI".
Once I run the above code, I get this error message:
Measurements: Write cannot be performed, because the number of channels in the data does not match the number of channels in the task.
When writing, supply data for all channels in the task. Alternatively, modify the task to contain the same number of channels as the data written.
Number of Channels in Task: 1
Number of Channels in Data: 96
I was wondering how I could change the "Number of Channels in Task" to match with "Number of Channels in Data".
Could anyone please help me understand the difference between the mentioned terms and modify the sample codes to achieve the mentioned purpose?
Best Regsrds,
Amirhossein
write a new digital output value, you should use non-latched (immediate) digital I/O. When a DAQ device accepts or transfers data after a digital.
12-22-2022 01:53 AM - edited 12-22-2022 01:55 AM
Hi Amir,
@Amir1992 wrote:
I am not clear on the difference between "Port", "Channel", "Line", and "sample" so I guess that's the reason that I have difficulties choosing the right option for "ULX Write.VI".
Once I run the above code, I get this error message:
Number of Channels in Task: 1
Number of Channels in Data: 96
Why does your "data" array contain 96 elements when you want to switch a single relay?
Does ULx come with a manual?
12-22-2022 10:39 AM
Hi,
Thank you very much for your answer and clarification on the mentioned terms.
Actually, I need to turn on and off 96 relays by sending digital output signals. I corrected my code as in the first picture attached below, but I still have difficulty controlling each relay, which is associated with a channel (if I am not mistaken), separately. I mean that when I turn on the first channel related to the first relay, the first relay turns on, but when I turn on the second to the fourth channel, the first relay turns on again. It seems that the channels are grouped such that I cannot turn on each relay separately. When I click on the line menu in the second image attached below, I can see 96 different lines (channels), but at least the first four lines control the same relay and do not control different relays.
Could you please help me modify the above code so I will be able to turn on and off each of the relays individually?
Kind regards,
Amir
12-22-2022 10:47 AM
I forgot to mention that I used "multiple channels" option as well (as shown in the first picture attached below), but once I run the code I receive the error message as shown in the second picture attached below and no relay turns on.
Kind Regards,
Amir
12-23-2022 06:19 AM
Hi Amir,
@Amir1992 wrote:
Actually, I need to turn on and off 96 relays by sending digital output signals.
Then your task should contain all those 96 lines. And your data array needs to contain 96 elements to drive those 96 lines!
@Amir1992 wrote:
Could you please help me modify the above code so I will be able to turn on and off each of the relays individually?
You didn't attach any code so I cannot modify anthing…
Btw. you are using a ULx-device: I don't have such a device and so I don't have/want install the ULx driver!
Does the ULx driver come with example VIs? Is there an example specifically for your device? Is there an example explaining how to drive multiple DO lines?
12-23-2022 03:57 PM
Try this (see attached VI).
If you have to turn ON and OFF one relay, you don't need an array.
Also can you be more specific about the cycle? How long you want it ON and OFF. I have done a project about turn ON and OFF multiple relays for further questions, feel free to reach out.
~If this is what you want, don't forget to accept as solution as a gesture of gratitude ~
12-24-2022 10:59 AM
Amir,
You seem to be using an "unusual" piece of hardware, a 96-pin DIO device compatible with LabVIEW but not made by NI. I have some experience with DIO, typically multi-function DAQ devices that have a small number of DIO pins, often individually addressable as Booleans, and have also worked with DIO "chips" that had 8 or 16 DIO lines that were addressed (typically) as 8-bit bytes.
I assume you have access to a User Manual for the MCC device you are using, which probably discusses the proper way to address a 96-bit DIO device. From some things I've been able to find on the Web, it appears that your device might be configured as 4 "ports" of 24 digital "lines" (4 x 24 = 96).
Since I don't know how your MCC device is designed to operate (you attached neither a Manual nor any of MCC's "Example VIs" for doing multi-channel DIO), I'll describe code I created for handling an 8-bit "register", where each bit does a different function.
First, the unit of I/O for the device is the Port, an unsigned byte (a U8), while the unit of interest to me, the user, is a Line, or one bit. For example, the Port might have bit 0 be On/Off, bits 1 and 2 being a "mode-selector", and bits 3 to 7 being unused.
When I start, I assume I know nothing about the state of the device (though it might have a PowerUp state where all the bits are 0 -- does your device do that?). So the "safe" thing for me to do is to write 0 to the Port (which sets all the bits to 0, or "off"). I also create, in memory, a "Register", a U8 that reflects the current value in the Port, so I also initialize it to 0.
Now I want to turn on Bit 0, but without affecting the other bits. If the device allows me to address individual lines, then I simply turn on Line 0. But if it allows only Port I/O, what can I do? Well, I can go to my "Register" value, which has all 8 bits currently in the Port, and "turn on bit 0", then write the updated 8-bit Register to the Port. How about turning off a bit? Same thing, but now I need to clear the bit.
Fortunately, setting and clearing are easy operations in LabVIEW. Assume you have a U8 called "Register". To "Set" bit n (n = 0..7), you need to represent a U8 with bit n set, the rest all 0. For this, there's a Shift by Power of 2 function in the Numeric Palette -- shift 1 by n, the bit number, and you have your U8. Now set the bit by doing a logical OR with the current Register value. [What happens if the bit is already set? Is that what you want to happen?]
Clearing a bit goes the same way, but a little different. First, shift the single bit "1" to the position you want to clear. Negate it, turning your chosen bit position to a 0, but setting (to 1) all the other bits. Now AND that with the Register value, which keeps all the "other" bits intact, and clears your chosen bit by adding it with 0.
If your 96-line DIO device allows you to address the lines as 4 Ports of 24 bits, you'll create 4 U32 "Registers" and proceed as above, with the bit number going from 0 to 23.
What you didn't tell us, but would definitely impact how you implement controlling your 96 switches, is how you plan the User Interface. Are you going to have 96 Boolean On/Off switches? Are you going to have a Boolean Indicator saying whether the switch is On or Off, and a corresponding Boolean Control that says "Change State"? The more we know about what you plan to do, the better we can advise you on how to do it.
Bob Schor
01-03-2023 05:37 PM
Hello,
Thank you very much for your response. I intend to explain the specific issue I am dealing with now. I used your and other responses in this chat (I appreciate all of them) and improved my code.
The problem I have is that 96 different lines are detected by labview, but I cannot control any of them except the first one. I should note that I have already installed the first four relays (out of 96), but I can control only the first one. Please see the attached picture and the file.
when I open the drop-down menu in the front window in the attached file, I can see 96 lines and each line is related to one relay. I have access to the first four relays at the moment (Dev0/1stPortA/Do0, Dev0/1stPortA/Do1, Dev0/1stPortA/Do2, and Dev0/1stPortA/Do3). Once I choose "Dev0/1stPortA/Do0", I can turn it on and off by putting 0 and 1 in the data box in the front window, but once I choose the other three lines, I cannot control them. It seems that it detects only the first relay. It should be noted that I'm using a quad relay which consists of four relays and I can see if I can control them by seeing the four lights on the quad relay turning on and off. The board is configured by "Instacall" and I can control each relay using "DAQWare DIO" software. Eventually, I need to control 96 pumps using the device I have installed, but at the moment I am trying to figure out how I should work with it by installing only the first quad relay (the first four relays).
Would you please assist me with the above-mentioned issue? Is there a way I can control each line (relay) separately via labview?
Kind regards,
Amirhossein
01-03-2023 09:21 PM
It looks like you might be using some (obsolete? no-longer-manufactured?) hardware from MCC. I tried to "guess" the model number of your device, so I might be able to learn more about the code you are trying to run, but was unsuccessful.
You are using LabVIEW 2022, the newest version of LabVIEW, which should support NI devices for the last 4-5 years. I would recommend purchasing modern (circa 2022) NI hardware, loading the appropriate Drivers and DAQmx, read the manual to learn/understand how to do multi-channel DIO, and write your LabVIEW code.
Note that it is possible that the old hardware will work with the (unknown) ULx software. It would definitely help us (to help you) if you could provide manuals for the hardware and the ULx software.
Bob Schor