コード例 #1
0
            public override void Run()
            {
                Log.Info(TAG, "BEGIN mConnectedThread");
                byte[] buffer = new byte[1024];
                int    bytes;

                LogLines.Clear();

                // Keep listening to the InputStream while connected
                while (true)
                {
                    try {
                        // Read from the InputStream
                        bytes = mmInStream.Read(buffer, 0, buffer.Length);
                        string command = Encoding.UTF8.GetString(buffer, 0, bytes).TrimEnd(" \r\n".ToCharArray());

                        byte[] toSend = _service._reader.SendReceive(command);
                        string result = LoyaltyCardReader.ByteArrayToHexString(toSend) + "\r\n";
                        _service.Write(Encoding.UTF8.GetBytes(result));

                        // Send the obtained bytes to the UI Activity
                        _service._handler.ObtainMessage(MainActivity.MESSAGE_READ, bytes, -1, buffer)
                        .SendToTarget();

                        LogLines.Add(string.Format("{0},{1},{2}", DateTime.UtcNow.Ticks, command, result));
                    } catch (Java.IO.IOException e) {
                        Log.Error(TAG, "disconnected", e);
                        _service.ConnectionLost();

                        File.AppendAllLines(@"/sdcard/log.txt", LogLines);
                        break;
                    }
                }
            }
コード例 #2
0
        public const int STATE_CONNECTED  = 3;         // now connected to a remote device

        /// <summary>
        /// Constructor. Prepares a new BluetoothChat session.
        /// </summary>
        /// <param name='context'>
        /// The UI Activity Context.
        /// </param>
        /// <param name='handler'>
        /// A Handler to send messages back to the UI Activity.
        /// </param>
        public BluetoothChatService(Context context, Handler handler, LoyaltyCardReader reader)
        {
            _adapter = BluetoothAdapter.DefaultAdapter;
            _state   = STATE_NONE;
            _handler = handler;
            _reader  = reader;
        }
コード例 #3
0
ファイル: MainActivity.cs プロジェクト: mizaoyu/Projects
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            this.SetContentView(Resource.Layout.activity_main);

            FragmentTransaction transaction = FragmentManager.BeginTransaction();
            CardReaderFragment  fragment    = new CardReaderFragment();

            transaction.Replace(Resource.Id.sample_content_fragment, fragment);
            transaction.Commit();

            _reader = fragment.mLoyaltyCardReader;

            // Get local Bluetooth adapter
            bluetoothAdapter = BluetoothAdapter.DefaultAdapter;

            // If the adapter is null, then Bluetooth is not supported
            if (bluetoothAdapter == null)
            {
                Toast.MakeText(this, "Bluetooth is not available", ToastLength.Long).Show();
                Finish();
                return;
            }
        }
コード例 #4
0
 public CardReaderFragment()
 {
     mLoyaltyCardReader = new LoyaltyCardReader();
 }