Ejemplo n.º 1
0
        private void CreateCoinAcceptor()
        {
            var con = new ConnectionRs232
                        {
                            PortName = GetCom(),
                            RemoveEcho = true
                        };

            Dictionary<byte, CoinTypeInfo> coins;
            if (!CoinAcceptor.TryParseConfigWord(configWord.Text, out coins))
            {
                MessageBox.Show("Wrong config word, using defaults");

                coins = CoinAcceptor.DefaultConfig;
                configWord.Text = CoinAcceptor.ConfigWord(CoinAcceptor.DefaultConfig);
            }

            _coinAcceptor = new CoinAcceptor(Convert.ToByte(deviceNumber.Value), con, coins, null);

            _coinAcceptor.CoinAccepted += CoinAcceptorCoinAccepted;
            _coinAcceptor.ErrorMessageAccepted += CoinAcceptorErrorMessageAccepted;

            _coinAcceptor.Init();

            groupBox1.Enabled = true;
            panel1.Enabled = true;

            initCoinButton.Enabled = false;
            resetButton.Enabled = true;
            configWord.Enabled = false;
        }
Ejemplo n.º 2
0
        private bool ConnectToCoinAcceptor()
        {
            Dictionary<byte, CoinTypeInfo> coins;
            coins = CoinAcceptor.DefaultConfig;

            byte deviceNumber = 2; //device number defaults to 2 - coin acceptor

            //can be changed to ones liking by using SetCoins(coinsDefaultText, out coins)
            //default from .dll is:
            //1=0,05=5 cent; 2=0,1=10 cent; 3=0,2=20 cent; 4=0,5=50 cent; 5=1=1 euro; 6=2=2 euro;
            string coinsDefaultText = CoinAcceptor.ConfigWord(CoinAcceptor.DefaultConfig);

            txtLog.Text += "Using the following connection string for coins:" + Environment.NewLine + coinsDefaultText + newline;

            try
            {
                string port = "COM" + txtPortNumber.Text;
                var connection = new ConnectionRs232
                                     {
                                         PortName = port,
                                         RemoveEcho = true
                                     };

                txtLog.Text += "Trying to connect to port:" + port + " - ";

                _coinAcceptor = new CoinAcceptor(deviceNumber, connection, coins, null);

                _coinAcceptor.CoinAccepted += _coinAcceptor_CoinAccepted;
                _coinAcceptor.ErrorMessageAccepted += _coinAcceptor_ErrorMessageAccepted;

                _coinAcceptor.Init(true);

                if (_coinAcceptor.IsInitialized)
                {
                    txtLog.Text += "Successfully initialized the CoinAcceptor!" + newline;
                    return true;
                }

                txtLog.Text += "Failed initializing the CoinAcceptor!" + newline;
                DisposeCoinAcceptor();
                connection.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }

            return false;
        }
Ejemplo n.º 3
0
        private void CreateCoinAcceptor()
        {
            // Create a factory object and configure it.
            var devFactory = new DeviceFactory();
            devFactory.ComPort = GetCom();
            devFactory.RemoveEcho = false;
            devFactory.ConfigWord = configWord.Text;
            // Create the device controller.
            _coinAcceptor = (CoinAcceptor)devFactory.CreateDevice(CctalkDeviceTypes.CoinAcceptor);

            _coinAcceptor.MoneyAccepted += CoinAcceptorCoinAccepted;
            _coinAcceptor.ErrorMessage += CoinAcceptorErrorMessageAccepted;

            _coinAcceptor.Init();

            groupBox1.Enabled = true;
            panel1.Enabled = true;

            initCoinButton.Enabled = false;
            resetButton.Enabled = true;
            configWord.Enabled = false;
        }