Preserve outputs states between executables.

Supporting Visual Studio on Windows
Post Reply
john7
Fresh meat
Posts: 3
Joined: Tue Apr 20, 2021 2:58 am
Contact:

Preserve outputs states between executables.

Post by john7 »

I setup a card

Code: Select all


DigitalInput[] digital_inputs = new DigitalInput[INPUTS_COUNT] ;
        DigitalOutput[] digital_outputs = new DigitalOutput[OUTPUTS_COUNT];
        
private void InputsInit(int inputs, int type)
        {
            int i;

            try
            {
                for (i = 0; i < inputs; i++)
                {
                    digital_inputs[i] = new DigitalInput
                    {
                        DeviceSerialNumber = type,
                        Channel = i
                    };

                    digital_inputs[i].StateChange += DigitalInput_StateChange;
                }

                for (i = 0; i < inputs; i++)
                {
                    digital_inputs[i].Open(WAIT_ATTACH_MS);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                device_connected = false;
            }
        }

        private void OutputsInit(int outputs, int type)
        {
            int i;

            try
            {
                for (i = 0; i < outputs; i++)
                {
                    digital_outputs[i] = new DigitalOutput
                    {
                        DeviceSerialNumber = type,
                        Channel = i
                    };
                }

                for (i = 0; i < outputs; i++)
                {
                    digital_outputs[i].Open(WAIT_ATTACH_MS);
                }

                device_connected = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                device_connected = false;
            }
        }

        private void CardInit(int card_type)
        {
            if (card_type == CARD_TYPE_0_0_4)
            {
                io_count = 4;
                dev_ser_number = 520535;

                OutputsInit(io_count, dev_ser_number);
            }
            else if (card_type == CARD_TYPE_0_16_16)
            {
                io_count = 16;
                dev_ser_number = 546353;

                InputsInit(io_count, dev_ser_number);
                OutputsInit(io_count, dev_ser_number);
            }
        }
Then I set some outputs

Code: Select all

private void CheckedChanged(object sender, EventArgs e)
{
    CheckBox outputChk = (CheckBox)sender;

    int outputIndex = int.Parse((string)outputChk.Tag);

     if (outputIndex < io_count)
         digital_outputs[outputIndex].State = outputChk.Checked;
}
But when I close my application the outputs go off. How can I make the objects

Code: Select all

DigitalInput[] digital_inputs = new DigitalInput[INPUTS_COUNT] ;
        DigitalOutput[] digital_outputs = new DigitalOutput[OUTPUTS_COUNT];
global between the projects in one solution?
I want to switch on some outputs in one exe and switch it off in another.
User avatar
mparadis
Site Admin
Posts: 660
Joined: Fri Oct 28, 2011 12:17 pm
Contact:

Re: Preserve outputs states between executables.

Post by mparadis »

One of your programs needs to be kept running in order to keep the outputs on. The typical solution to this kind of problem is to use the Network Server and connect remotely with all of your programs, so they can access the outputs at the same time.

See these threads:

Digital Output Persistence
State persistence of DigitalOutput
Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests