nikel
28-02-2010, 13:32
Programmatori di tutte le razze buogiorno!
ho un altra volta un bisogno disperato del vostro aiuto!
quello che cerco di realizzare è tanto semplice quanto impossibile (almeno per me:muro: )...
in pratica ho bisogno di un codice che mi faccia inviare file da un dispositivo all'altro via bluetooth...
e qui nascono i primi problemi... con tutti i codici che ho testato e scritto nell'ultima settimana riesco a inviare file da pc a qualunque telefono tranne su quello che mi interessa (un omnia con wm6.1)
e ovviamente non riesco a inviare file dall'omnia al pc con lo stesso codice...
come posso fare? avete qualche sample da propormi?
codice che ho scritto:
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 System.IO;
using System.Reflection;
using InTheHand.Net.Bluetooth;
using InTheHand.Net.Sockets;
using InTheHand.Net;
namespace FINALWM
{
public partial class blueconfig : Form
{
public blueconfig()
{
InitializeComponent();
}
bool impedisci1 = false; //impedisce di cercare 2 volte i dispositivi
string devicename; //nome device
Int32 i = 401; //numero
private void Paint_a(object sender, PaintEventArgs e) //stampa lo sfondo
{
Assembly asm = Assembly.GetExecutingAssembly();
Bitmap backgroundImage = Properties.Resources.sfodobt;
e.Graphics.DrawImage(backgroundImage, this.ClientRectangle,
new Rectangle(0, 0, backgroundImage.Width, backgroundImage.Height),
GraphicsUnit.Pixel);
}
private void button1_Click(object sender, EventArgs e) //ricerca dispositivi
{
if (impedisci1 == false)
{
impedisci1 = true;
// try
// {
if (!BluetoothRadio.IsSupported)
{
listBox1.Items.Add("NO BLUETOOTH");
}
if (BluetoothRadio.PrimaryRadio.Mode == RadioMode.PowerOff)
{
BluetoothRadio.PrimaryRadio.Mode = RadioMode.Connectable;
}
BluetoothClient me = new BluetoothClient();
BluetoothDeviceInfo[] devices = me.DiscoverDevices();
foreach (BluetoothDeviceInfo device in devices)
{
device.Update();
device.Refresh();
listBox1.Items.Add(device.DeviceName);
}
/* }
catch
{
listBox1.Items.Add("IMPOSSIBILE ESEGUIRE");
} */
}
}
private void button2_Click(object sender, EventArgs e) //connetti e invia un piccolo file
{
BluetoothClient me = new BluetoothClient();
BluetoothDeviceInfo[] devices = me.DiscoverDevices();
foreach (BluetoothDeviceInfo device in devices)
{
device.Update();
device.Refresh();
devicename=(string)listBox1.SelectedItem;
if (device.DeviceName == (string)listBox1.SelectedItem)
{
// Authenticate with the device
if (!device.Authenticated)
{
// Use pin "0000" for authentication
if (!BluetoothSecurity.PairRequest(device.DeviceAddress, "0000"))
{
listBox1.Items.Add("ERRORE");
}
}
if(File.Exists("ping.dat")) File.Delete("ping.dat"); //crea un piccolo file da trasferire
FileStream fs = File.Create("ping.dat");
BinaryWriter bw = new BinaryWriter(fs);
bw.Write(i);
bw.Write(i);
bw.Close();
fs.Close();
device.SetServiceState(BluetoothService.ObexObjectPush, true);
Uri uri = new Uri("obex://" + device.DeviceAddress + "ping.dat");
ObexWebRequest req = new ObexWebRequest(uri);
req.ReadFile(@"ping.dat");
ObexWebResponse rsp = (ObexWebResponse)req.GetResponse();
me.Close();
}
}
}
}
}
grazie!!:D
ho un altra volta un bisogno disperato del vostro aiuto!
quello che cerco di realizzare è tanto semplice quanto impossibile (almeno per me:muro: )...
in pratica ho bisogno di un codice che mi faccia inviare file da un dispositivo all'altro via bluetooth...
e qui nascono i primi problemi... con tutti i codici che ho testato e scritto nell'ultima settimana riesco a inviare file da pc a qualunque telefono tranne su quello che mi interessa (un omnia con wm6.1)
e ovviamente non riesco a inviare file dall'omnia al pc con lo stesso codice...
come posso fare? avete qualche sample da propormi?
codice che ho scritto:
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 System.IO;
using System.Reflection;
using InTheHand.Net.Bluetooth;
using InTheHand.Net.Sockets;
using InTheHand.Net;
namespace FINALWM
{
public partial class blueconfig : Form
{
public blueconfig()
{
InitializeComponent();
}
bool impedisci1 = false; //impedisce di cercare 2 volte i dispositivi
string devicename; //nome device
Int32 i = 401; //numero
private void Paint_a(object sender, PaintEventArgs e) //stampa lo sfondo
{
Assembly asm = Assembly.GetExecutingAssembly();
Bitmap backgroundImage = Properties.Resources.sfodobt;
e.Graphics.DrawImage(backgroundImage, this.ClientRectangle,
new Rectangle(0, 0, backgroundImage.Width, backgroundImage.Height),
GraphicsUnit.Pixel);
}
private void button1_Click(object sender, EventArgs e) //ricerca dispositivi
{
if (impedisci1 == false)
{
impedisci1 = true;
// try
// {
if (!BluetoothRadio.IsSupported)
{
listBox1.Items.Add("NO BLUETOOTH");
}
if (BluetoothRadio.PrimaryRadio.Mode == RadioMode.PowerOff)
{
BluetoothRadio.PrimaryRadio.Mode = RadioMode.Connectable;
}
BluetoothClient me = new BluetoothClient();
BluetoothDeviceInfo[] devices = me.DiscoverDevices();
foreach (BluetoothDeviceInfo device in devices)
{
device.Update();
device.Refresh();
listBox1.Items.Add(device.DeviceName);
}
/* }
catch
{
listBox1.Items.Add("IMPOSSIBILE ESEGUIRE");
} */
}
}
private void button2_Click(object sender, EventArgs e) //connetti e invia un piccolo file
{
BluetoothClient me = new BluetoothClient();
BluetoothDeviceInfo[] devices = me.DiscoverDevices();
foreach (BluetoothDeviceInfo device in devices)
{
device.Update();
device.Refresh();
devicename=(string)listBox1.SelectedItem;
if (device.DeviceName == (string)listBox1.SelectedItem)
{
// Authenticate with the device
if (!device.Authenticated)
{
// Use pin "0000" for authentication
if (!BluetoothSecurity.PairRequest(device.DeviceAddress, "0000"))
{
listBox1.Items.Add("ERRORE");
}
}
if(File.Exists("ping.dat")) File.Delete("ping.dat"); //crea un piccolo file da trasferire
FileStream fs = File.Create("ping.dat");
BinaryWriter bw = new BinaryWriter(fs);
bw.Write(i);
bw.Write(i);
bw.Close();
fs.Close();
device.SetServiceState(BluetoothService.ObexObjectPush, true);
Uri uri = new Uri("obex://" + device.DeviceAddress + "ping.dat");
ObexWebRequest req = new ObexWebRequest(uri);
req.ReadFile(@"ping.dat");
ObexWebResponse rsp = (ObexWebResponse)req.GetResponse();
me.Close();
}
}
}
}
}
grazie!!:D