Toggle Switch Component - On Screen Dip Switch - Modbus


Recommended Posts

Want to create an on screen a dip switch array (16 bits) that is similar to my printed circuit board assembly (PCBA) dip switch array. The reason for this is so that the user can commision his lighting system from DAQfactory instead of having to use the PCBA dip switches.

Not sure how to proceed but here is my first line of thought:

1. Created on a page 16 toggle switches in an array that looks similar to my PCBA dip switches.

2. Created 16 channels: Device type = Test and each have a unique channel number. I/O type is String. Reason creating these channels is simply do not know another way to get the toggle switch value into a variable that I can work with.

3. When I use the toggle switch the channels are set to 0 or 1. This allows the user to have a dip switch type on screen user interface.

4. Need to combine these 16 values into a variable so that I can send them to my Modbus slave PCBA. Know how to do this in C but not sure how to do this in DAQfactory script. I assume create a sequence and

OR them together into a single variable but not sure how to manipulate the data in DAQfactory script.

5. Send to my Modbus slave PCBA the 16 bits (dip switch setting from the DAQfactory screen) using Set Register S16 (6).

Thanks for your assistance.

Link to comment
Share on other sites

Actually, its easier to use a variable and the From.bit function. Then you can use either 16 switches or buttons to toggle, or just use the check box component and select the Array? option. I've attached a sample.

1) in an auto start sequence, create your variable. Initialize it as an array of bits where the bits are in one row and 16 columns. Use fill() to create an array with 16 rows, then use transpose() to convert it to 16 columns. There are other ways to do it, and you can actually combine the two functions into one line if you want

2) if you want to use a check box, check select the Array? option, set 16 wide, and the Set Channel is simply your variable

3) if you want to use a bunch of switches or other component, you'll have to assign the variable to each, subsetting for the appropriate bit. Since the bits are in columns, it will be [0][x] where x is the bit number.

4) to convert to a word, use the from.bit() function on your variable.

The attached sample requires 5.87a.

bits.ctl

Link to comment
Share on other sites

That is perfect!

What is the prefered way to send this data? I have a button that the user will press to upload the new dip switch data to my Modbus Slave PCBA and was thinking of using Set Register S16 (6). Give the new dip switch value to the Set Register S16 (6) is where I get a bit confused . . . Do I create a sequence where the dip switch variable is assigned to the channel [0] that i created for Set Register S16 (6)?

Link to comment
Share on other sites

Hi, figured it out:

Here is a sequenc . . .

Channel_Dip_Switch = From.Bit(Dip_Switch_Bits)

Where Channel_Dip_Switch is the channel Set Regist S16(6) and Dip_Switch_Bits is the array of 16 bits that represent 16 positions of an on screen dip switch. This now sends the value when this sequence is called.

Thanks,

Link to comment
Share on other sites

Archived

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