Exemple #1
0
        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;
        }
Exemple #2
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;
        }
        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);
        }
        private void btnCoinOpenPort_Click(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrEmpty(cmbCoinPorts.Text))
            {
                Core.Log.Out("请选择串口");
                return;
            }

            var con = new ConnectionRs232
            {
                PortName   = cmbCoinPorts.Text,
                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);
            //}

            coins         = CoinAcceptor.DefaultConfig;
            _coinAcceptor = new CoinAcceptor(02, con, coins, null);

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

            _coinAcceptor.Init();

            if (_coinAcceptor.IsInitialized)
            {
                wpCoinIn.IsEnabled = true;
            }
        }
Exemple #5
0
        public static string Init(string cardcom, string cashIncom, string coinIncom, string cashOutcom, string coin1Outcom, string coin5Outcom)
        {
            if (bInit)
            {
                return("");
            }

            var sb   = new StringBuilder();
            var msg  = "";
            var open = false;

            IsOpenCassetteAndRead = false;
            try
            {
                //读卡器初始化
                cardCom = new SerialComIC(cardcom);
                cardCom.OnReadCardNo += (s, c) =>
                {
                    if (OnReadCardNo != null)
                    {
                        OnReadCardNo(s, c);
                    }
                };

                //纸币入
                cashInCom = new CashReceiver(cashIncom);
                open      = cashInCom.Open(out msg);
                if (!open)
                {
                    sb.Append(msg);
                }
                cashInCom.OnAcceptMoney += cashInCom_OnAcceptMoney;

                //硬币入
                var con = new ConnectionRs232
                {
                    PortName   = coinIncom,
                    RemoveEcho = true
                };
                Dictionary <byte, CoinTypeInfo> coins;
                coins         = CoinAcceptor.DefaultConfig;
                coinAcceptor3 = new CoinAcceptor(02, con, coins, null);
                coinAcceptor3.CoinAccepted         += CoinAcceptorCoinAccepted;
                coinAcceptor3.ErrorMessageAccepted += CoinAcceptorErrorMessageAccepted;
                coinAcceptor3.Init();

                //纸币出
                cashOutCom = new SerialCom(cashOutcom);
                if (cashOutCom.Open(out msg) == false)
                {
                    sb.Append(msg);
                }
                StatusCode.Init();
                constrant = new Constrant(cashOutCom);

                //硬币找零
                coin1Com = new CoinCharge(coin1Outcom, ChargeMoneyType.M1, false);
                coin5Com = new CoinCharge(coin5Outcom, ChargeMoneyType.M5, false);

                if (coin1Com.Open(out msg) == false)
                {
                    sb.Append(COIN1_COM_OPEN_ERROR);
                }
                Log.Out("1 yuan OK");
                if (coin5Com.Open(out msg) == false)
                {
                    sb.Append(COIN5_COM_OPEN_ERROR);
                }
                Log.Out("5 yuan OK");
                bInit = true;
            }
            catch (Exception ex)
            {
                msg = ex.Message;
            }
            return(msg);
        }
Exemple #6
0
        public static string Init(string cardcom, string cashIncom, string coinIncom, string cashOutcom, string coin1Outcom, string coin5Outcom)
        {
            if (bInit)
            {
                return("");
            }

            var msg  = "";
            var open = false;
            //com1 = new SerialComIC(cardcom);
            //com1.OnReadCardNo += (s, c) =>
            //{
            //    if (OnReadCardNo != null)
            //    {
            //        OnReadCardNo(s, c);
            //    }
            //};

            ////纸币入
            //com2 = new CashReceiver(cashIncom);
            //open = com2.Open(out msg);
            //if (!open)
            //{
            //    return "";
            //}
            //com2.OnAcceptMoney += Com2_OnAcceptMoney;

            //硬币入
            var con = new ConnectionRs232
            {
                PortName   = coinIncom,
                RemoveEcho = true
            };

            Dictionary <byte, CoinTypeInfo> coins;

            coins          = CoinAcceptor.DefaultConfig;
            _coinAcceptor3 = new CoinAcceptor(02, con, coins, null);
            _coinAcceptor3.CoinAccepted         += CoinAcceptorCoinAccepted;
            _coinAcceptor3.ErrorMessageAccepted += CoinAcceptorErrorMessageAccepted;
            _coinAcceptor3.Init();

            //纸币出
            cashOutCom = new SerialCom(cashOutcom);
            if (cashOutCom.Open(out msg) == false)
            {
                return(msg);
            }
            StatusCode.Init();
            constrant = new Constrant(cashOutCom);

            //coin1_com5 = new CoinCharge(coin1Outcom, ChargeMoneyType.M1);
            //coin5_com6 = new CoinCharge("coin5Outcom", ChargeMoneyType.M5);

            //if (coin1_com5.Open(out msg))
            //{
            //    return "1元找零串口打开失败";
            //}
            //if (coin5_com6.Open(out msg))
            //{
            //    return "5元找零串口打开失败";
            //}
            bInit = true;
            return(string.Empty);
        }