Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/280.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Xamarin体重秤读数问题_C#_Xamarin_Bluetooth Lowenergy - Fatal编程技术网

C# Xamarin体重秤读数问题

C# Xamarin体重秤读数问题,c#,xamarin,bluetooth-lowenergy,C#,Xamarin,Bluetooth Lowenergy,我和我的团队是BLE Android开发的新手,我们正在使用C#Xamarin 我们正在尝试连接并读取一个可调体重秤和血氧计(Berrymed设备)上的读数,我们能够连接并读取设备信息,但无法读取实际读数、日期和时间 我们什么都试过了,但运气不好。任何关于C#代码示例的帮助或建议都会非常有用。我们看到了很多Java示例,但没有看到Xamarin 该设备是一个中国黑地体重秤 using System; using System.Collections.Generic; using System.L

我和我的团队是BLE Android开发的新手,我们正在使用C#Xamarin

我们正在尝试连接并读取一个可调体重秤和血氧计(Berrymed设备)上的读数,我们能够连接并读取设备信息,但无法读取实际读数、日期和时间

我们什么都试过了,但运气不好。任何关于C#代码示例的帮助或建议都会非常有用。我们看到了很多Java示例,但没有看到Xamarin

该设备是一个中国黑地体重秤

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Android.App;
using Android.Bluetooth;
using Android.OS;
using Android.Widget;
using AndroidBluetoothLE.Bluetooth.Client;
using Java.Util;
public class ReadCharacteristicView : BaseCharacteristicView
    {
        private BluetoothGattCharacteristic _characteristic;
        private DeviceReadingHandler _readingHandler;

        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            SetContentView(Resource.Layout.ReadCharacteristicView);

            InitializeView();
        }

        protected override void OnDestroy()
        {
            base.OnDestroy();
            _readingHandler.Dispose();
        }

        private void InitializeView()
        {
            var connectionHandler = BluetoothClient.Instance.ConnectionHandler;
            _readingHandler = new DeviceReadingHandler(connectionHandler.GattValue, GattClientObserver.Instance);
            _characteristic = GetCharacteristic(connectionHandler.GetServiceList());

            var readButton = FindViewById<Button>(Resource.Id.ReadCharacteristicButton);
            readButton.Click += ReadButtonOnClick;
        }

        private BluetoothGattCharacteristic GetCharacteristic(IEnumerable<BluetoothGattService> serviceList)
        {
            var uuid = (UUID)Intent.GetSerializableExtra("Characteristic");

            var service = serviceList.First(s => s.Characteristics.Any(ch => ch.Uuid.Equals(uuid)));
            return service.Characteristics.First(ch => ch.Uuid.Equals(uuid));
        }

        private void ReadButtonOnClick(object sender, EventArgs eventArgs)
        {
            var hexText = FindViewById<TextView>(Resource.Id.HexReadText);
            var stringText = FindViewById<TextView>(Resource.Id.StringReadText);

            ShowDialog("Start reading...");
            _readingHandler.Read(_characteristic, (bytes, status) => RunOnUiThread(() => 
            {
                if (status != GattStatus.Success)
                {
                    ShowDialog("Reading failed with status: " + status);
                    return;
                }

                hexText.SetText(BitConverter.ToString(bytes), TextView.BufferType.Normal);
                stringText.SetText(Encoding.ASCII.GetString(bytes), TextView.BufferType.Normal);
                ShowDialog("Read Success!");
            }));
        }

        private void ShowDialog(string message)
        {
            DialogView.ShowDialog(message, this);
        }
    }
使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用系统文本;
使用Android.App;
使用Android.Bluetooth;
使用Android.OS;
使用Android.Widget;
使用AndroidBluetoothLE.Bluetooth.Client;
使用Java.Util;
公共类ReadCharacteristicView:BaseCharacteristicView
{
私人蓝牙特征(特征);;
私人设备制造商readingHandler;
创建时受保护的覆盖无效(捆绑包)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.ReadCharacteristicView);
初始化视图();
}
受保护的覆盖无效OnDestroy()
{
base.ondestory();
_readingHandler.Dispose();
}
private void InitializeView()
{
var connectionHandler=BluetoothClient.Instance.connectionHandler;
_readingHandler=new DeviceReadingHandler(connectionHandler.GattValue,GattClientObserver.Instance);
_characteristic=GetCharacteristic(connectionHandler.GetServiceList());
var readButton=findviewbyd(Resource.Id.ReadCharacteristicButton);
readButton.Click+=ReadButtonNonclick;
}
私有BluetoothGattCharacteristic GetCharacteristic(IEnumerable serviceList)
{
var uuid=(uuid)Intent.GetSerializableExtra(“特征”);
var service=serviceList.First(s=>s.Characteristics.Any(ch=>ch.Uuid.Equals(Uuid));
返回service.Characteristics.First(ch=>ch.Uuid.Equals(Uuid));
}
私有void readButtonNonclick(对象发送方,EventArgs EventArgs)
{
var hexText=findviewbyd(Resource.Id.HexReadText);
var stringText=findviewbyd(Resource.Id.StringReadText);
ShowDialog(“开始阅读…”);
_readingHandler.Read(_特征,(字节,状态)=>RunOnUiThread(()=>
{
如果(状态!=GattStatus.Success)
{
ShowDialog(“读取失败,状态:+状态”);
返回;
}
SetText(位转换器.ToString(字节),TextView.BufferType.Normal);
SetText(Encoding.ASCII.GetString(字节),TextView.BufferType.Normal);
ShowDialog(“阅读成功!”);
}));
}
私有void显示对话框(字符串消息)
{
DialogView.ShowDialog(消息,此);
}
}

欢迎来到stackoverflow。请访问该网站,了解stackoverflow是如何工作的,以及如何提出好的问题。然后回来问你的问题。包括您尝试的代码,以及任何错误消息。提出具体问题。大多数人都乐意帮忙,但不想为你做工作。像“我怎么做x?”这样的问题,如果没有显示出你这方面的任何研究成果,很可能会被忽略。你有这种电子秤的BLE装置的详细信息吗?您是否有任何设备可以读取它(例如,PC?)它可能使用特定的服务/特征或通用的服务/特征如果没有,您可以从LightBlue之类的应用程序开始,通过打孔-您可以看到哪些服务和特征可用,甚至可以读取它们。避免说“我们已经尝试了所有东西”特别是当你试过的东西的开头都没有显示的时候。BLE体重秤是中国制造的-通用体重-海泰体重秤。这是我们正在使用的代码