예제 #1
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();
            }
        }
예제 #2
0
 public GenericDevice(GenericCctalkDevice rawDev, Type errorEnumType)
 {
     // Initialize the raw device interface for communicate with the device at low level.
     _rawDev = rawDev;
     // Generate the dictionary of error codes indexed by their name.
     _errCodesByName = GenerateErrorDictionary(errorEnumType);
 }