/*public void Test() * { * * }*/ public void LoadSettingsAndStart() { if (m_Initialized == true) { throw new InvalidOperationException("Already initialized"); } string portName; var deviceFound = BillToBillDevice.SearchDevice(out portName); if (deviceFound == true) { //var device = new BillToBillDevice(portName); if (OnSearchResult != null) { OnSearchResult(this, new DeviceInfoEventArgs(portName)); } Debug.Assert(portName != null, "portName != null"); var deviceOpened = this.Open(); Debug.Assert(deviceOpened == true, "deviceOpened == true"); m_Initialized = true; PollDevice(); //send reset command to device (transmit in initial state it) ResetDevice(); } PollResponseCode pollState = PollResponseCode.None; var cycleCount = 0; do { Thread.Sleep(CHECK_DEVICE_TRANSMIT_IN_DISABLED_STATE_INTERVAL_MSEC); //send poll command, check is device trmansmit in disabled state ResponsePoll pollResponse; PollDevice(out pollResponse); if (pollResponse.FirstCode == PollResponseCode.PowerUp) { ResetDevice(); continue; } pollState = pollResponse.FirstCode; Debug.WriteLine( string.Format(" Cycle - {0:X} ", cycleCount)); cycleCount++; } while (cycleCount <= ATTEMPTS_COUNT_WAIT_DEVICE_TRANSMIT_IN_DISABLED_STATE_AFTER_RESET && pollState != PollResponseCode.Unit_Disabled); if (cycleCount > ATTEMPTS_COUNT_WAIT_DEVICE_TRANSMIT_IN_DISABLED_STATE_AFTER_RESET) { throw new Exception("Device startup failed"); } Debug.Assert(pollState == PollResponseCode.Unit_Disabled, "pollState == PollResponseCode.Unit_Disabled"); GetBillTable(out m_BillTable); m_ResyclingCassettes = new List <Cassette>(CreateCassettes()).ToArray(); StartDevicePolling(); }
public ResponsePoll( PollResponseCode firstCode, byte secondCode, byte[] z3) { m_FirstCode = firstCode; m_SecondCode = secondCode; m_Z3 = z3; }
bool CheckApplicableState(PollResponseCode currentState, IEnumerable <PollResponseCode> applicableStates) { bool ret = false; foreach (var state in applicableStates) { if (currentState == state) { ret = true; } } return(ret); }
bool WaitState(PollResponseCode waitingState) { bool ret = false; int sleepTime = 500; int maxCycleCount = 20; //10 sec; for (int i = 0; i < maxCycleCount; i++) { if (m_PollState == waitingState) { Debug.WriteLine("Wait : last cycle - " + i); ret = true; break; } Thread.Sleep(sleepTime); } return(ret); }
void HandlePollResponse(ResponsePoll pollResponse) { Debug.WriteLine( string.Format("Poll - {0:X} , {1:X}", pollResponse.FirstCode, pollResponse.SecondCode)); if (m_PollState != pollResponse.FirstCode) { switch (pollResponse.FirstCode) { case PollResponseCode.Bill_Stacked: HandleBillStacked(pollResponse.SecondCode); break; case PollResponseCode.Idle: break; case PollResponseCode.Drop_Cassete_Out_Of_Position: if (m_PollState != PollResponseCode.Drop_Cassete_Out_Of_Position) { Debug.WriteLine("Casste dropped"); } break; case PollResponseCode.Unit_Disabled: if (m_PollState == PollResponseCode.Dispensed) { if (OnDispenseEnd != null) { OnDispenseEnd(this, EventArgs.Empty); } } break; case PollResponseCode.Dispensing: { if (OnDispensing != null) { OnDispensing(this, EventArgs.Empty); } } break; case PollResponseCode.Jam_In_Acceptor: case PollResponseCode.Jam_In_Stacker: { if (OnJam != null) { OnJam(this, EventArgs.Empty); } break; } default: Debug.WriteLine("BV Poll Response " + pollResponse.FirstCode); break; } m_PollState = pollResponse.FirstCode; if (OnPollStatus != null) { OnPollStatus(this, new PollStatus(pollResponse.FirstCode)); } } }
public PollStatus(PollResponseCode pollResponseCode) { m_PollResponseCode = pollResponseCode; }