如何通过蓝牙发送字符串 [英] How to send Strings via Bluetooth
本文介绍了如何通过蓝牙发送字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何从蓝牙发送字符串?我想向Arduino发送一些文本命令。
How to send a string from Bluetooth ? I want to send some text commands to an Arduino.
推荐答案
你好,我需要通过蓝牙发送一些命令。命令如,
hello, I need to send some commands via bluetooth. The commands like,
command_1
command_1
command_2
command_2
我试过这个,但是,没有用。我需要发送没有换行符的命令。
I tried this but, Did not work. I need to send those commands with no line breaks.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO.Ports;
namespace Smart_Buddy
{
public partial class Form1 : Form
{
SerialPort serialPort1 = new SerialPort();
private string messege;
public Form1()
{
InitializeComponent();
getAvailableComPorts();
}
private void Form1_Load(object sender, EventArgs e)
{
}
void getAvailableComPorts()
{
String[] ports = SerialPort.GetPortNames();
comboBox1.Items.AddRange(ports);
}
private void button1_Click(object sender, EventArgs e)
{
try
{
SerialPort serialPort1 = new SerialPort();
serialPort1.PortName = comboBox1.Text;
serialPort1.BaudRate = 9600;
if (serialPort1.IsOpen)
messege = "d1_on";
serialPort1.WriteLine(messege);
serialPort1.Close();
}
catch
{
label1.Text = "not Connected";
}
}
}
}
这篇关于如何通过蓝牙发送字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文