public CommandHandler(
     BillToBillDevice device, InterfaceCommand interfaceCommand,
     byte[] commandData) : base(device)
 {
     m_CommandData      = commandData;
     m_InterfaceCommand = interfaceCommand;
 }
        /*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 SetRecyclingCassetteTypeCmdHandler(
     BillToBillDevice device,
     byte cassetteNumber, byte billTypeId) :
     base(device, InterfaceCommand.Set_Recycling_Cassette_Type)
 {
     m_CassetteNumber = cassetteNumber;
     m_BillTypeId     = billTypeId;
 }
        static bool CheckDeviceAvalibility(string portName)
        {
            bool deviceAvailable = false;

            Debug.Assert(portName != null, "portName != null");
            var device = new BillToBillDevice(portName);
            //try initialize device
            var deviceOpened = device.Open();

            if (deviceOpened == true)
            {
                //poll device
                //device successfully polled

                if (device.PollDevice() == true)
                {
                    deviceAvailable = true;
                }

                //close device
                device.Close();
            }
            return(deviceAvailable);
        }
Exemple #5
0
 public Cassette(byte cassetteNumber, BillToBillDevice device)
 {
     m_CassetteNumber = (byte)(cassetteNumber);
     m_Device         = device;
 }
 public GetStatusCmdHandler(BillToBillDevice device) :
     base(device, InterfaceCommand.Get_Status, null)
 {
 }
 public DispenseCmdHandler(BillToBillDevice device,
                           DispCmdItem[] dispCmdItems)
     : base(device, InterfaceCommand.Dispense)
 {
     m_DispCmdItems = dispCmdItems;
 }
 public CmdHandlerWithoutRetData(BillToBillDevice device,
                                 InterfaceCommand interfaceCommand)
     : base(device)
 {
     m_InterfaceCommand = interfaceCommand;
 }
 public PollCmdHandler(BillToBillDevice device,
                       InterfaceCommand command, byte[] commandData) : base(
         device, command, commandData)
 {
 }
 public CommandHandlerBase(BillToBillDevice device)
 {
     m_Device = device;
 }
 //readonly GetBillTableResponse m_GetBillTableResponse;
 public GetRecyclingCasseteStatusCmdHandler(
     BillToBillDevice device) :
     base(device, InterfaceCommand.Recycling_Cassette_Status, null)
 {
 }
 public GetBillTableCmdHandler(BillToBillDevice device) :
     base(device, InterfaceCommand.GetBillTable, null)
 {
 }