private void PoolingCashCode() { if (ccnet.IsOpen()) { BillAcceptorActivity = true; Error = false; ErrorMsg = ""; ccnet.SendCommand(CashCode_CCNET.CCNET_Commands.POOL); CashCode_CCNET.CCNET_STATUS ans = ccnet.ReadAnswer(); if (ans == CashCode_CCNET.CCNET_STATUS.IDLING || ans == CashCode_CCNET.CCNET_STATUS.DISABLED) { BillAcceptorActivity = false; } // Если купюра распозната if (ans == CashCode_CCNET.CCNET_STATUS.ESCROW && AllowMoneyEnterOnPooling) { // проверка на if (ccnet.EnteredMoney == CashCode_CCNET.Money.RUB10 && !accmoney.R10) { ccnet.SendCommand(CashCode_CCNET.CCNET_Commands.RETURN); } else if (ccnet.EnteredMoney == CashCode_CCNET.Money.RUB50 && !accmoney.R50) { ccnet.SendCommand(CashCode_CCNET.CCNET_Commands.RETURN); } else if (ccnet.EnteredMoney == CashCode_CCNET.Money.RUB100 && !accmoney.R100) { ccnet.SendCommand(CashCode_CCNET.CCNET_Commands.RETURN); } else if (ccnet.EnteredMoney == CashCode_CCNET.Money.RUB500 && !accmoney.R500) { ccnet.SendCommand(CashCode_CCNET.CCNET_Commands.RETURN); } else if (ccnet.EnteredMoney == CashCode_CCNET.Money.RUB1000 && !accmoney.R1000) { ccnet.SendCommand(CashCode_CCNET.CCNET_Commands.RETURN); } else if (ccnet.EnteredMoney == CashCode_CCNET.Money.RUB5000 && !accmoney.R5000) { ccnet.SendCommand(CashCode_CCNET.CCNET_Commands.RETURN); } else { ccnet.SendCommand(CashCode_CCNET.CCNET_Commands.STACK); /*System.Threading.Thread.Sleep(30); * * if(ccnet.ReadAnswer() == CashCode_CCNET.CCNET_STATUS.ACK) * { * switch (int.Parse(ccnet.EnteredMoney.ToString().Replace("RUB", ""))) * { * case 10: CountR10++; break; * case 50: CountR50++; break; * case 100: CountR100++; break; * case 500: CountR500++; break; * case 1000: CountR1000++; break; * case 5000: CountR5000++; break; * * } * Amount += Decimal.Parse(ccnet.EnteredMoney.ToString().Replace("RUB", "")); * BillCount++; * ccnet.EnteredMoney = CashCode_CCNET.Money.RUB0; * }*/ } } if (ans == CashCode_CCNET.CCNET_STATUS.ACCEPTING) { switch (int.Parse(ccnet.EnteredMoney.ToString().Replace("RUB", ""))) { case 10: CountR10++; break; case 50: CountR50++; break; case 100: CountR100++; break; case 500: CountR500++; break; case 1000: CountR1000++; break; case 5000: CountR5000++; break; } Amount += Decimal.Parse(ccnet.EnteredMoney.ToString().Replace("RUB", "")); if (ccnet.EnteredMoney != CashCode_CCNET.Money.RUB0) { BillCount++; } ccnet.EnteredMoney = CashCode_CCNET.Money.RUB0; }/* * if (ans == CashCode_CCNET.CCNET_STATUS.RETURN) * { * switch (int.Parse(ccnet.EnteredMoney.ToString().Replace("RUB", ""))) * { * case 10: CountR10--; break; * case 50: CountR50--; break; * case 100: CountR100--; break; * case 500: CountR500--; break; * case 1000: CountR1000--; break; * case 5000: CountR5000--; break; * * } * Amount -= Decimal.Parse(ccnet.EnteredMoney.ToString().Replace("RUB", "")); * BillCount--; * ccnet.EnteredMoney = CashCode_CCNET.Money.RUB0; * }*/ if (ans == CashCode_CCNET.CCNET_STATUS.ERROR) { Error = true; ErrorMsg = ccnet.LastError.ToString() + "-" + ccnet.LastErrorMessage; } /*if (ans == CashCode_CCNET.CCNET_STATUS.NULL) * { * Error = true; * ErrorMsg = "Not answer."; * }*/ } else { Error = true; ErrorMsg = "Port not open."; } }
public Acceptor() { List <string> comports = new List <string>(); log.AddToLog("\r\n-------------------------------------------------------"); log.AddToLog("Поиск купюроприемника"); try { using (RegistryKey comdevices = Registry.LocalMachine.OpenSubKey("HARDWARE").OpenSubKey("DEVICEMAP").OpenSubKey("SERIALCOMM")) { string[] devices = comdevices.GetValueNames(); foreach (string s in devices) { Match m = Regex.Match(s, @"QCUSB_COM", RegexOptions.IgnoreCase); if (m.Success) { Object o1 = comdevices.GetValue(s); comports.Add(o1.ToString()); } } } } catch (Exception ex) { log.AddToLog(ex.Message); } log.AddToLog("Поиск доступных портов..."); availablePorts = System.IO.Ports.SerialPort.GetPortNames(); for (int i = 0; i < availablePorts.Length; i++) { if (comports.Count > 0) { string s = comports.Find(p => p == availablePorts[i]); if (!String.IsNullOrEmpty(s)) { continue; } } try { log.AddToLog("Поиск eba на порту " + availablePorts[i] + "..."); eba = new EBA03(availablePorts[i]); log.AddToLog("отправка команды EBA03.EBA03_Commands.VersionRequest"); eba.SendCommand(EBA03.EBA03_Commands.VersionRequest); eba.ReadAnswer(); if (eba.Version != null) { if (eba.Version.IndexOf("ID003") != -1) { model = Model.EBA03; PortNumber = availablePorts[i]; log.AddToLog("Ответ получен. Купюроприемник: " + model.ToString()); break; } } log.AddToLog("не получен ожидаемый ответ..."); if (eba != null) { log.AddToLog("Закрытие eba"); eba.Close(); } log.AddToLog("Поиск CashCode на порту " + availablePorts[i]); ccnet = new CashCode_CCNET(availablePorts[i]); log.AddToLog("отправка команды CashCode_CCNET.CCNET_Commands.POOL"); ccnet.SendCommand(CashCode_CCNET.CCNET_Commands.POOL); CashCode_CCNET.CCNET_STATUS ans = ccnet.ReadAnswer(); log.AddToLog("получен ответ " + ans); if (ans == CashCode_CCNET.CCNET_STATUS.IDLING) { log.AddToLog("отправка команды CashCode_CCNET.CCNET_Commands.DISABLE_MONEY"); ccnet.SendCommand(CashCode_CCNET.CCNET_Commands.DISABLE_MONEY); ans = ccnet.ReadAnswer(); log.AddToLog("получен ответ " + ans); } if (ans == CashCode_CCNET.CCNET_STATUS.INITIALIZE || ans == CashCode_CCNET.CCNET_STATUS.DISABLED || ans == CashCode_CCNET.CCNET_STATUS.POWER_UP || ans == CashCode_CCNET.CCNET_STATUS.PAUSE) { log.AddToLog("отправка команды CashCode_CCNET.CCNET_Commands.RESET"); ccnet.SendCommand(CashCode_CCNET.CCNET_Commands.RESET); ans = ccnet.ReadAnswer(); log.AddToLog("получен ответ " + ans); } log.AddToLog("отправка команды CashCode_CCNET.CCNET_Commands.IDENT"); ccnet.SendCommand(CashCode_CCNET.CCNET_Commands.IDENT); // System.Threading.Thread.Sleep(50); CashCode_CCNET.CCNET_STATUS st = ccnet.ReadAnswer(); log.AddToLog("получен ответ " + st.ToString()); if (st == CashCode_CCNET.CCNET_STATUS.Version || st == CashCode_CCNET.CCNET_STATUS.ILLEGAL_COMMAND) { if (ccnet.Version != null) { if (ccnet.Version.IndexOf("SM") != -1 || ccnet.Version.IndexOf("VU") != -1 || ccnet.Version.IndexOf("FL") != -1) { Match m = Regex.Match(ccnet.Version, @"'(?<val>.*?)\s", RegexOptions.IgnoreCase); if (m.Success) { Version = m.Groups["val"].ToString(); Version = Regex.Replace(Version, @"[^A-Z^А-Я^0-9^\-^:^;^.^,^\s^?]", string.Empty, RegexOptions.IgnoreCase); } } } model = Model.CASHCODE; log.AddToLog("Найден купюроприемник " + model.ToString() + ". Порт " + availablePorts[i]); PortNumber = availablePorts[i]; break; } else { log.AddToLog("не получен ожидаемый ответ..."); if (ccnet != null) { log.AddToLog("закрытие ccnet..."); ccnet.Close(); } } } catch (Exception ex) { if (eba != null) { eba.Close(); } if (ccnet != null) { ccnet.Close(); } model = Model.NULL; log.AddToLog("Ошибка при определении купюроприемника. " + ex.Message); } } BillAcceptorActivity = false; log.AddToLog("Выход"); }