Cách tốt nhất để biết thiết bị bluetooth và gửi tệp đến thiết bị bluetooth từ máy tính của bạn là sử dụng mã đó.
public void ExecuteCommandSync(object command)
{
try
{
// create the ProcessStartInfo using "cmd" as the program to be run,
// and "/c " as the parameters.
// Incidentally, /c tells cmd that we want it to execute the command that follows,
// and then exit.
System.Diagnostics.ProcessStartInfo procStartInfo =
new System.Diagnostics.ProcessStartInfo("cmd", "/c " + command);
// The following commands are needed to redirect the standard output.
// This means that it will be redirected to the Process.StandardOutput StreamReader.
procStartInfo.RedirectStandardOutput = true;
procStartInfo.UseShellExecute = false;
// Do not create the black window.
procStartInfo.CreateNoWindow = true;
// Now we create a process, assign its ProcessStartInfo and start it
System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.StartInfo = procStartInfo;
proc.Start();
// Get the output into a string
string result = proc.StandardOutput.ReadToEnd();
// Display the command output.
Console.WriteLine(result);
}
catch (Exception objException)
{
// Log the exception
MessageBox.Show(objException.Message);
}
}
Bạn có thể gọi phương pháp này như
string command = "fsquirt";
ExecuteCommandSync(command);
Vì vậy, BluetoothFileTransferWizard xuất hiện và bạn có thể chọn thiết bị có sẵn và gửi file cho gửi thiết bị đó. Nếu bạn không muốn sử dụng theo cách đó, hãy thử 32feet.net.uk. Điều đó thật tuyệt vời cho việc phát triển bluetooth cho C# và VB.NET.
Ngoài ra, tôi đã thử 32Feet trên Windows 10 và nhận được "32feet.NET không hỗ trợ ngăn xếp Bluetooth trên thiết bị này. " Tôi đã báo cáo vấn đề này, nhưng có vẻ như dự án đã không được cập nhật trong một vài năm ... – LawMan
@LawMan Tôi gặp sự cố tương tự với Windows 10. Nguyên nhân là do Bluetooth đã bị tắt. –
@Juozas Kontvainis Đó là điều đầu tiên tôi kiểm tra. Mặc dù mã của tôi sẽ ghép nối thiết bị nếu nó không được ghép nối (hoặc ít nhất là nó được sử dụng để ... lol), tôi đảm bảo rằng Windows đã ghép nối thành công với thiết bị, sau đó thực thi mã của tôi. Ngoài ra, 32Feet vẫn chưa trả lời được vấn đề của tôi. Đây là liên kết vấn đề nếu có ai quan tâm. https: //32feet.codeplex.com/workitem/43236 – LawMan