Page 1 of 1

Preserve outputs states between executables.

Posted: Tue Apr 20, 2021 3:07 am
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.

Re: Preserve outputs states between executables.

Posted: Tue Apr 20, 2021 8:07 am
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