private void SetDataSendingBit(bool condition) { int iReturnCode; //Return code String szDeviceName = "M1000"; //List data for 'DeviceName' int iNumberOfData = 1; //Data for 'DeviceSize' short[] arrDeviceValue; //Data for 'DeviceValue' //Assign the array for 'DeviceValue'. arrDeviceValue = new short[iNumberOfData]; if (condition == true) { arrDeviceValue[0] = 1; } else { arrDeviceValue[0] = 0; } try { //The WriteDeviceRandom2 method is executed. iReturnCode = plc.WriteDeviceRandom2(szDeviceName, iNumberOfData, ref arrDeviceValue[0]); } //Exception processing catch (Exception exception) { Debug.WriteLine(exception.Message); return; } }