コード例 #1
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;
        }
コード例 #2
0
ファイル: Form1.cs プロジェクト: jekyll2014/ccTalk-net-1
        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;
        }
コード例 #3
0
ファイル: Form1.cs プロジェクト: jekyll2014/ccTalk-net-1
        private void SendCommandButtonClick(object sender, EventArgs e)
        {
            // Attention! There we are creating new device object. But it could share connection with _coinAcceptor.
            ICctalkConnection con;
            Boolean isMyConnection;

            if (_coinAcceptor.Connection.IsOpen())
            {
                con = _coinAcceptor.Connection;
                isMyConnection = false;
            }
            else
            {
                con = new ConnectionRs232
                {
                    PortName = GetCom(),
                    RemoveEcho = true      // if we are connected to USB-COM echo is present otherwise set to false
                };
                con.Open();
                isMyConnection = true;
            }
            try
            {
                var c = new GenericCctalkDevice
                            {
                                Connection = con,
                                Address = 0
                            };

                if (radioButton1.Checked)
                {
                    var buf = c.CmdReadEventBuffer();

                    var sb = new StringBuilder();
                    sb.Append("Accepted: ");
                    sb.AppendFormat("Cntr={0} Data:", buf.Counter);
                    for (int i = 0; i < buf.Events.Length; i++)
                    {
                        var ev = buf.Events[i];
                        sb.AppendFormat("({0:X2} {1:X2}) ", ev.CoinCode, ev.ErrorOrRouteCode);
                    }

                    listBox1.Items.Add(sb.ToString());
                    listBox1.SelectedIndex = listBox1.Items.Count - 1;

                }
                else if (radioButton2.Checked)
                {
                    var serial = c.CmdGetSerial();
                    listBox1.Items.Add(String.Format("SN: {0}", serial));
                    listBox1.SelectedIndex = listBox1.Items.Count - 1;

                }
                else if (radioButton3.Checked)
                {
                    c.CmdReset();
                }
            }
            finally
            {
                if (isMyConnection)
                    con.Close();
            }
        }
コード例 #4
0
ファイル: Form1.cs プロジェクト: jekyll2014/ccTalk-net-1
        private void CreateBillValidator()
        {
            var con = new ConnectionRs232
                        {
                            PortName = GetCom(),
                            RemoveEcho = true // if we are connected to USB-COM echo is present otherwise set to false
                        };

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

                notes = BillValidator.DefaultConfig;
                configWord.Text = BillValidator.ConfigWord(BillValidator.DefaultConfig);
            }

            _billValidator = new BillValidator(Convert.ToByte(deviceNumber.Value), con, notes, null);

            _billValidator.NotesAccepted += BillValidatorNotesAccepted;
            _billValidator.ErrorMessageAccepted += BillValidatorErrorMessageAccepted;

            _billValidator.Init();

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

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