Witam
Obecnie pracuje nad aplikacją potrafiącą:
1. wyszukac odbiorniki BT
2. polaczyc sie
3. wysylać kilka rozkazow (kazdy pod innym buttonem ,oraz jeden button polaczony z zawartoscia okna tekstowego)
4. odbierac krotkie tresci ascii,lub hex i wyswietlac w polu tekstowym
przykladowe tresci nadawane z WM: read1, read2 , read 3 , read3+zawartosc pola tekstowego , np. read3_123456 przykladowe tresci odbierane : transmission ok, transmission not ok, value_123456 - te miały by byc wyswietlane w polu tekstowym,lub przewijanym polu tekstowym
ma byc to zwykla symulacja portu comm, ale nie chce recznie go wybierac a znajdowac urzadzenia z listy w zasiegu BT
docelowo aplikacja ma sterowac modulem przemysłowym BT,zarzadzanym przez mikrokontroler ATMEGA ,
procesor bedzie wiedział co dalej z tym co odbierze z BT , i bedzie nadawał poprzez BT potwierdzenia wykonania tego co otrzymał.
Prace nad ATMEGA wykona kto inny.
Obecnie napisałem aplikacje ktora potrafi wyszukać i połączyć sie z odbiornikiem BT, nie umiem jednak okreslic typu usługi , czy wykonac nadania danych/ odbioru.
w moim przykładzie korzystałem z biblioteki InTheHand.Net.Bluetooth.dll
poniżej kod:
using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using InTheHand.Net;
using InTheHand.Net.Sockets;
using InTheHand.Net.Bluetooth;
namespace SmartDeviceProject7
{
public partial class Form1 : Form
{
private BluetoothClient bluetoothClient;
private Guid service = BluetoothService.DialupNetworking;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
BluetoothRadio.PrimaryRadio.Mode = RadioMode.Discoverable;
bluetoothClient = new BluetoothClient();
Cursor.Current = Cursors.WaitCursor;
BluetoothDeviceInfo[] bluetoothDeviceInfo = { };
bluetoothDeviceInfo = bluetoothClient.DiscoverDevices(10);
comboBox1.DataSource = bluetoothDeviceInfo;
comboBox1.DisplayMember = "DeviceName";
comboBox1.ValueMember = "DeviceAddress";
comboBox1.Focus();
Cursor.Current = Cursors.Default;
}
private void button2_Click(object sender, EventArgs e)
{
if (comboBox1.SelectedValue != null)
{
try
{
bluetoothClient.Connect(new BluetoothEndPoint((BluetoothAddress)comboBox1.SelectedValue, service));
pictureBox2.Visible = true;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
private void button3_Click(object sender, EventArgs e)
{
}
private void button4_Click(object sender, EventArgs e)
{
}
private void setLabel(string lText)
{
labeltext = labeltext + "\n" + lText;
label1.Text = labeltext;
label1.Invalidate();
}
private void button5_Click(object sender, EventArgs e)
{
{
try
{
if (bluetoothClient.Connected)
{
NetworkStream peer = bluetoothClient.GetStream();
peer.Read(bufr, 1, 5);
setLabel("Stream:" + bufr[0].ToString());
peer.Close();
//bluetoothClient.Close();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
private void button6_Click(object sender, EventArgs e)
{
{
try
{
if (bluetoothClient.Connected)
{
NetworkStream peer = bluetoothClient.GetStream();
Byte raw = System.Text.Encoding.ASCII.GetBytes("AT");
//Dim raw() as byte =
System.Text.Encoding.ASCII.GetBytes("AT" & vbCrLf);
peer.Write(raw, 0, raw.Length);
setLabel("Stream:" + raw.ToString());
peer.Close();
//bluetoothClient.Close();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
private void label1_ParentChanged(object sender, EventArgs e)
{
}
}
}
Obecnie pisze to w Visual Studio 2008
SKD windows mobile 5
urzadzenie do testow HTC DIamond2.
ewentualnie zlece napisanie takiej krotkiej aplikacji.
autoelektronika.vadis@gmail.com