コード例 #1
0
 /// <summary>
 /// Obsługa zdarzenia naciśnięcia przycisku połączenia z driver'em USB.
 /// </summary>
 void ConnectItem_Click(object sender, RoutedEventArgs e)
 {
     /* Jeżeli połączony - to rozłącz */
     if (_USBConnected)
     {
         USBComm.usbDisconnect();
         _USBConnected     = false;
         _miConnect.Header = Properties.Messages.menuDisconnect;
     }
     /* Jeżeli nie podłączony - to nawiąż połączenie */
     else
     {
         USBComm.TDeviceState devState = USBComm.usbGetDeviceState();
         if (devState.state == (int)stateCodes.STATE_DISCONNECTED)
         {
             int ret = USBComm.usbConnect();
             if (ret == (int)errorCodes.ERR_NONE)
             {
                 Console.WriteLine("Connected");
                 _USBConnected     = true;
                 _miConnect.Header = Properties.Messages.menuConnect;
             }
             else
             {
                 Console.WriteLine("Connection failed with return code: " + ret);
             }
         }
     }
 }
コード例 #2
0
 /// <summary>
 /// Obsługa zdarzenia zamknięcia okna aplikacji.
 /// </summary>
 void MainWindow_closed(object sender, EventArgs e)
 {
     _timer.Stop();
     USBComm.TDeviceState devState = USBComm.usbGetDeviceState();
     if (devState.state == (int)stateCodes.STATE_CONNECTED)
     {
         USBComm.usbDisconnect();
     }
 }
コード例 #3
0
        void Timer_Tick(object sender, EventArgs e)
        {
            USBComm.TDeviceState devState = USBComm.usbGetDeviceState();
            if (devState.state == (int)stateCodes.STATE_DISCONNECTED)
            {
                int ret = USBComm.usbConnect();
                if (ret == (int)errorCodes.ERR_NONE)
                {
                    Console.WriteLine("Connected");
                }
                else
                {
                    Console.WriteLine("Connection failed with return code: " + ret);
                    //USBComm.usbDisconnect();
                }
            }
            else
            {
                if (devState.state == (int)stateCodes.STATE_CONNECTED)
                {
                    //USBComm.usbDisconnect();
                    //int r=USBComm.usbConnect();

                    SolidColorBrush redBrush  = new SolidColorBrush(Colors.Red);
                    SolidColorBrush grayBrush = new SolidColorBrush(Colors.Gray);

                    int[] DIdata = new int[16];
                    int[] DOdata = new int[16];

                    short[] AOdata = new short[8];
                    short[] AIdata = new short[8];

                    USBComm.usbGetAllDI(DIdata);
                    USBComm.usbGetAllDO(DOdata);
                    USBComm.usbGetAllAO(AOdata);
                    USBComm.usbGetAllAI(AIdata);

                    _bLoadData = true;

                    for (int i = 0; i < 16; i++)
                    {
                        _arrDIs[i].Fill = (DIdata[i] == 1 ? redBrush : grayBrush);
                        _arrDOs[i].Fill = (DOdata[i] == 1 ? redBrush : grayBrush);
                    }
                    for (int i = 0; i < 4; i++)
                    {
                        _arrAIs[i].Text    = String.Format("{0:0.00}", ((Double)(10 * AIdata[i]) / 4095));
                        _arrAOs[i].Text    = String.Format("{0:0.00}", (((Double)(10 * AOdata[i])) / 4095));
                        _arrS_AOs[i].Value = AOdata[i];
                        // _arrS_AOs[i].Value = AOdata[i];
                    }
                    this.UpdateLayout();
                    _bLoadData = false;
                }
            }
        }
コード例 #4
0
        private void b_DO_click(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            Ellipse el    = (Ellipse)sender;
            int     n     = Int32.Parse(el.Name.Remove(0, 4));
            int     value = (((SolidColorBrush)(_arrDOs[n - 1].Fill)).Color.Equals(_redBrush.Color) ? 0 : 1);

            USBComm.TDeviceState devState = USBComm.usbGetDeviceState();
            if (devState.state == (int)stateCodes.STATE_CONNECTED)
            {
                USBComm.usbSetDO(n - 1, value);
            }
        }
コード例 #5
0
        private void EncoderSlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs <double> e)
        {
            Slider sl    = (Slider)sender;
            short  value = (Int16)e.NewValue; // pobranie nowo ustawionej wartość,
            char   dir   = _bRightDirection ? (char)0 : (char)1;

            USBComm.TDeviceState devState = USBComm.usbGetDeviceState(); // Pobieramy stan
            _tbEncoder.Text = ((Int32)value).ToString();
            if (devState.state == (int)stateCodes.STATE_CONNECTED)
            {
                USBComm.usbSetEncoder(value, dir);
            }
        }
コード例 #6
0
 private void AO_valueChanged(object sender, System.Windows.RoutedPropertyChangedEventArgs <double> e)
 {
     if (!_bLoadData)
     {
         Slider sl    = (Slider)sender;
         int    n     = Int32.Parse(sl.Name.Remove(0, 4));
         short  value = (Int16)e.NewValue;                            // pobranie nowo ustawionej wartość, Slider-y mają działają od 0 do 1024
         USBComm.TDeviceState devState = USBComm.usbGetDeviceState(); // Pobieramy stan
         if (devState.state == (int)stateCodes.STATE_CONNECTED)
         {
             USBComm.usbSetAO(n - 1, value); //Jeżeli jestśmy połączeni to ustaw to wyjście
         }
     }
 }
コード例 #7
0
 /// <summary>
 /// Obsługa zdarzenia dla timera.
 /// </summary>
 void Timer_Tick(object sender, EventArgs e)
 {
     USBComm.TDeviceState devState = USBComm.usbGetDeviceState();
     if (devState.state == (int)stateCodes.STATE_CONNECTED)
     {
         _stConnectionBlinking.Begin(this, true);
         _miConnect.Header = Properties.Messages.menuDisconnect;
     }
     else
     {
         _miConnect.Header = Properties.Messages.menuConnect;
         _elConnected.Fill = _grayBrush;
         //if (cst.ToString().Equals("Active"))
         _stConnectionBlinking.Stop(this);
     }
 }
コード例 #8
0
 private void AO_textChanged(object sender, System.Windows.Controls.TextChangedEventArgs e)
 {
     if (!_bLoadData)
     {
         TextBox tb = (TextBox)sender;
         int     n  = Int32.Parse(tb.Name.Remove(0, 2));
         try
         {
             double volt  = double.Parse(tb.Text);
             short  value = (Int16)(volt * 4095 / 10);                    // pobranie nowo ustawionej wartość, musi być to jakieś Double
             USBComm.TDeviceState devState = USBComm.usbGetDeviceState(); // Pobieramy stan
             if (devState.state == (int)stateCodes.STATE_CONNECTED)
             {
                 USBComm.usbSetAO(n - 1, value);
             }
             //Jeżeli jesteśmy połączeni to ustaw to wyjście
         }
         catch
         {
         }
     }
 }
コード例 #9
0
        private void EnkoderEnable_checkBox_Checked(object sender, RoutedEventArgs e)
        {
            CheckBox chb = (CheckBox)sender;

            _bEncoderEnable = chb.IsChecked == true ? true : false;
            USBComm.TDeviceState devState = USBComm.usbGetDeviceState();
            if (_bEncoderEnable)
            {
                short value = Int16.Parse(_tbEncoder.Text);
                char  dir   = _bRightDirection ? (char)0 : (char)1;
                if (devState.state == (int)stateCodes.STATE_CONNECTED)
                {
                    USBComm.usbSetEncoder(value, dir);
                }
            }
            else
            {
                if (devState.state == (int)stateCodes.STATE_CONNECTED)
                {
                    USBComm.usbDisEncoder();
                }
            }
        }
コード例 #10
0
        /// <summary>
        /// Obsługa zdarzenia zmiany elementu w widoku TreeView.
        /// </summary>
        void TreeView_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs <object> e)
        {
            TreeView     tv  = (TreeView)sender;
            TreeViewItem tvi = (TreeViewItem)e.NewValue;

            if (tvi.Header.Equals(Properties.Messages.msgReactor))
            {
                onReactorExpand();
            }
            if (tvi.Header.Equals(Properties.Messages.msgSygnalizacja))
            {
                onSygnalizacjaExpand();
            }
            if (tvi.Header.Equals(Properties.Messages.msgSygnalizacjaII))
            {
                onSygnalizacjaIIExpand();
            }
            if (tvi.Header.Equals(Properties.Messages.msgSygnalizacjaIII))
            {
                onSygnalizacjaIIIExpand();
            }
            if (tvi.Header.Equals(Properties.Messages.msgACMotor))
            {
                onACMotorExpand();
            }
            if (tvi.Header.Equals(Properties.Messages.msgDemo))
            {
                _tcMain.SelectedIndex = 0;
                DeactivateOutputs();
            }
            if (tvi.Header.Equals(Properties.Messages.msgSimulation))
            {
                _tcMain.SelectedIndex = 1;
                ActivateSimulationOutputs();
                /* łączenie z urządzeniem */
                if (!_USBConnected)
                {
                    USBComm.TDeviceState devState = USBComm.usbGetDeviceState();
                    if (devState.state == (int)stateCodes.STATE_DISCONNECTED)
                    {
                        int ret = USBComm.usbConnect();
                        if (ret == (int)errorCodes.ERR_NONE)
                        {
                            Console.WriteLine("Connected");
                            _USBConnected     = true;
                            _miConnect.Header = Properties.Messages.menuConnect;
                        }
                        else
                        {
                            Console.WriteLine("Connection failed with return code: " + ret);
                        }
                    }
                }
            }
            if (tvi.Header.Equals(Properties.Messages.msgTest))
            {
                _tcMain.SelectedIndex = 2;
                ActivateTestOutputs();
                /* łączenie z urządzeniem */
                if (!_USBConnected)
                {
                    USBComm.TDeviceState devState = USBComm.usbGetDeviceState();
                    if (devState.state == (int)stateCodes.STATE_DISCONNECTED)
                    {
                        int ret = USBComm.usbConnect();
                        if (ret == (int)errorCodes.ERR_NONE)
                        {
                            Console.WriteLine("Connected");
                            _USBConnected     = true;
                            _miConnect.Header = Properties.Messages.menuConnect;
                        }
                        else
                        {
                            Console.WriteLine("Connection failed with return code: " + ret);
                        }
                    }
                }
            }
            if (tvi.Header.Equals(Properties.Messages.msgSettings))
            {
                if (_bACMotorActive)
                {
                    PLCEmulator.ACMotor.ACMotorSettings settingsWnd = new PLCEmulator.ACMotor.ACMotorSettings();
                    settingsWnd.ShowDialog();
                }
                if (_bReactorActive)
                {
                    PLCEmulator.Reactor.ReactorSettings settingsWnd = new PLCEmulator.Reactor.ReactorSettings();
                    if (settingsWnd.ShowDialog() == true)
                    {
                        _bReactorActive = false;
                    }
                    onReactorExpand();
                }
            }
            if (tvi.Header.Equals(Properties.Messages.msgObjasnienia))
            {
                if (_bSygnalizacjaActive)
                {
                    PLCEmulator.Sygnalizacja.SygnalizacjaSettings settingsWnd = new PLCEmulator.Sygnalizacja.SygnalizacjaSettings();
                    if (settingsWnd.ShowDialog() == true)
                    {
                        _bSygnalizacjaActive = false;
                    }
                    onSygnalizacjaExpand();
                }
                if (_bSygnalizacjaIIActive)
                {
                    PLCEmulator.SygnalizacjaII.SygnalizacjaIISettings settingsWnd = new PLCEmulator.SygnalizacjaII.SygnalizacjaIISettings();
                    if (settingsWnd.ShowDialog() == true)
                    {
                        _bSygnalizacjaIIActive = false;
                    }
                    onSygnalizacjaIIExpand();
                }
                if (_bSygnalizacjaIIIActive)
                {
                    PLCEmulator.SygnalizacjaIII.SygnalizacjaIIISettings settingsWnd = new PLCEmulator.SygnalizacjaIII.SygnalizacjaIIISettings();
                    if (settingsWnd.ShowDialog() == true)
                    {
                        _bSygnalizacjaIIIActive = false;
                    }
                    onSygnalizacjaIIIExpand();
                }
            }
            SetHelp();
        }