Beispiel #1
0
        /// <summary>
        ///  Opens connection and request main data from device (e.g. Serial number)
        ///  If there is some data in event buffer - events will be raised
        /// </summary>
        public void Init(bool ignoreLastEvents = true)
        {
            _rawDev.Connection.Open();

            DeviceCategory = _rawDev.CmdRequestEquipmentCategory();
            if (DeviceCategory != CctalkDeviceTypes.CoinAcceptor)
            {
                throw new InvalidOperationException("Connected device is not a coin acceptor. " + DeviceCategory);
            }

            //_rawDev.CmdReset();
            _rawDev.CmdSetMasterInhibitStatus(IsInhibiting);

            //throw new InvalidOperationException("Msg: " + _rawDev.CmdGetMasterInhibitStatus().ToString()); - vraca false znaci da neInhibira.

            SerialNumber = _rawDev.CmdGetSerial();
            PollInterval = _rawDev.CmdRequestPollingPriority();
            Manufacturer = _rawDev.CmdRequestManufacturerId();
            ProductCode  = _rawDev.CmdRequestProductCode();

            var evBuf = _rawDev.CmdReadEventBuffer();

            if (!ignoreLastEvents)
            {
                RaiseLastEvents(evBuf);
            }
            _lastEvent = evBuf.Counter;

            IsInitialized = true;
        }
Beispiel #2
0
        /// <summary>
        ///  Opens connection and request main data from device (e.g. Serial number)
        ///  If there is some data in event buffer - events will be raised
        /// </summary>
        public void Init(Boolean ignoreLastEvents = true)
        {
            _rawDev.Connection.Open();

            DeviceCategory = _rawDev.CmdRequestEquipmentCategory();
            if (DeviceCategory != CctalkDeviceTypes.CoinAcceptor)
            {
                throw new InvalidOperationException("Connected device is not a coin acceptor. " + DeviceCategory);
            }

            //_rawDev.CmdReset();
            _rawDev.CmdSetMasterInhibitStatus(IsInhibiting);
            _rawDev.CmdModifyInhibitStatus(Enumerable.Repeat(true, 16).ToArray());

            SerialNumber = _rawDev.CmdGetSerial();
            PollInterval = _rawDev.CmdRequestPollingPriority();
            Manufacturer = _rawDev.CmdRequestManufacturerId();
            ProductCode  = _rawDev.CmdRequestProductCode();

            var evBuf = _rawDev.CmdReadEventBuffer();

            if (!ignoreLastEvents)
            {
                RaiseLastEvents(evBuf);
            }
            _lastEvent    = evBuf.Counter;
            IsInitialized = true;
        }
Beispiel #3
0
        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();
            }
        }