Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > .NET Framework > Forum > ช่วยทำให้โปรแกรมส่งข้อมูลผ่านบลูทูธส่งได้อัตโนมัติหน่อยครับ



 

ช่วยทำให้โปรแกรมส่งข้อมูลผ่านบลูทูธส่งได้อัตโนมัติหน่อยครับ

 



Topic : 072564



โพสกระทู้ ( 15 )
บทความ ( 0 )



สถานะออฟไลน์




หน้าโปรแกรมที่ออกแบบ

พอดีจะเขียนให้ส่งข้อมูลออกทางบลูทูธโดยอัตโนมัติแล้วค้นหาเพื่อส่งวนไปเรื่อยๆตอนนี้ทำได้แค่ส่งแต่ต้องกดปุ่มเลือกเชื่อมต่อแล้วก็กดส่ง...ได้ทีละตัว...ท่านใดเคยทำในลักษณะนี้บ้างช่วยแนะนำหน่อยครับ

Code (C#)
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace BluetoothOPPClientDemo
{
    public partial class fmMain : Form
    {
        public fmMain()
        {
            InitializeComponent();
        }

        private void fmMain_Load(object sender, EventArgs e)
        {
            wclAPI.Load();
        }

        private void fmMain_FormClosed(object sender, FormClosedEventArgs e)
        {
            wclAPI.Unload();
        }

       

        private void btDiscover_Click(object sender, EventArgs e)
        {

            wcl.wclBluetoothRadios Radios = new wcl.wclBluetoothRadios();
            if (wcl.wclErrors.wclShowError(wclBluetoothDiscovery.EnumRadios(Radios)))
            {
                Radios = null;
                return;
            }

            wcl.wclErrors.wclShowError(wclBluetoothDiscovery.Discovery(Radios[0]));
            Radios = null;
        }

        private void wclBluetoothDiscovery_OnDiscoveryStarted(object sender, wcl.wclBluetoothDiscoveryStartedEventArgs e)
        {
            lvDevices.Items.Clear();
           
        }

        private void wclBluetoothDiscovery_OnDiscoveryComplete(object sender, wcl.wclBluetoothDiscoveryCompleteEventArgs e)
        {
            if (e.Devices == null)
                MessageBox.Show("Error discovering");
            else
                if (e.Devices.Count == 0)
                    MessageBox.Show("Nothing found");
                else
                    for (uint i = 0; i < e.Devices.Count; i++)
                    {
                        wcl.wclBluetoothDevice Device = e.Devices[i];
                        ListViewItem Item = lvDevices.Items.Add(Device.Address);
                        string str = "";
                        Device.GetName(e.Radio, ref str);
                        Item.SubItems.Add(str);
                    
                    }
        }

        private void btConnect_Click(object sender, EventArgs e)
        {
            if (lvDevices.Items.Count == 0)
                MessageBox.Show("Select device");
            else
            {
                wcl.wclBluetoothRadios Radios = new wcl.wclBluetoothRadios();
                if (wcl.wclErrors.wclShowError(wclBluetoothDiscovery.EnumRadios(Radios)))
                {
                    Radios = null;
                    return;
                }

                wclClient.BluetoothParams.Address = lvDevices.SelectedItems[0].Text;
                wclClient.BluetoothParams.Radio = Radios[0];
                wclClient.Transport = wcl.wclClientTransport.ctBluetooth;
                wcl.wclErrors.wclShowError(wclClient.Connect());

                Radios = null;
            }
        }

        private void wclClient_OnConnect(object sender, wcl.wclConnectEventArgs e)
        {

        }

        private void wclClient_OnDisconnect(object sender, EventArgs e)
        {
            MessageBox.Show("Disconnected");
        }

        private void btDisconnect_Click(object sender, EventArgs e)
        {
            wclClient.Disconnect();
        }

        private void btOpenOBEX_Click(object sender, EventArgs e)
        {
            wcl.wclErrors.wclShowError(wclClient.OpenOBEXSession());
            if (OpenFileDialog.ShowDialog() == DialogResult.OK)
            {
                System.IO.FileStream Stream = new System.IO.FileStream(OpenFileDialog.FileName, System.IO.FileMode.Open, System.IO.FileAccess.Read);
                String AFile = System.IO.Path.GetFileName(OpenFileDialog.FileName);
                wcl.wclErrors.wclShowError(wclClient.Put(AFile, Stream));
            }
        }

        private void btCloseOBEX_Click(object sender, EventArgs e)
        {
            wcl.wclErrors.wclShowError(wclClient.CloseOBEXSession());
        }

        private void wclClient_OnOBEXConnect(object sender, wcl.wclConnectEventArgs e)
        {

        }

        private void wclClient_OnOBEXDisconnect(object sender, EventArgs e)
        {
    
        }

        private void wclClient_OnOBEXProgress(object sender, wcl.wclOBEXProgressEventArgs e)
        {
            ProgressBar.Maximum = (int)e.Size;
            ProgressBar.Value = (int)e.Position;
        }

        private void wclClient_OnOBEXPutComplete(object sender, wcl.wclConnectEventArgs e)
        {
            ProgressBar.Value = 0;
            if (e.Error == wcl.wclErrors.WCL_E_SUCCESS)
                MessageBox.Show("Put complete with success");
            else
                MessageBox.Show("Put complete with error: " + e.Error.ToString());
            wclClient.Disconnect();
            wcl.wclErrors.wclShowError(wclClient.CloseOBEXSession());
        }

    }
}


นี่เป็นโค้ดที่ทำไว้ครับ



Tag : C#, VS 2008 (.NET 3.x)







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2012-01-24 19:27:50 By : konmuen View : 1910 Reply : 8
 

 

No. 1



โพสกระทู้ ( 15 )
บทความ ( 0 )



สถานะออฟไลน์


ใช้ Visual C# ในการเขียน

ใช้ Visual C# ในการเขียน






แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-01-24 19:40:58 By : konmuen
 


 

No. 2



โพสกระทู้ ( 154 )
บทความ ( 0 )



สถานะออฟไลน์


ผมเองก็ไม่ได้ลงพวก Library จำพวก WCL และก็ไม่มีตัวทดสอบสัญญาณด้วยนะ แต่จะขอแนะนำเป็นแนวทางคร่าว ๆ แล้วกันครับว่า ปกติพวก Function Library ยังไงก็ต้องมีการ Return ค่ากลับมา ถ้าต้องการเขียนเป็น loop เพื่อส่งข้อมูลแบบอัตโนมัติ เราจะไม่ใช้ Event Return แต่เราจะต้องไปใช้ Function Return แทนครับ ให้เขียนทีี่ Procedure เดียวไปเลย เป็น While (true) { } statement ไปเลยครับ

ลักษณะจากตัวอย่าง

Code (C#)
wcl.wclErrors.wclShowError(wclClient.Connect());


ปกติถ้าเชื่อมต่อ สำเร็จหรือไม่สำเร็จ Library พวกนี้จะ Return ค่าไปยัง Handler ตาม Function Point เช่น OnConnectSuccess หรือ OnConnectFailure เป็นต้น แต่ว่าอย่างที่บอกถ้าต้องการตรวจสอบว่า Function ทำงานได้ตามปกติก็ให้ใช้รูปแบบนี้แทน

Code (C#)
if (wcl.wclErrors.wclShowError(wclClient.Connect()) == true) {

}


ก็คือเปลี่ยนมาใช้เป็นการ Return จาก Caller แทนครับ แบบนี้เราจะควบคุมการทำงานของ Function ต่าง ๆ ตามที่เราต้องการได้แล้ว จะสามารถเขียนเป็น loop ได้ครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-01-26 12:11:43 By : gunnermontana
 

 

No. 3



โพสกระทู้ ( 15 )
บทความ ( 0 )



สถานะออฟไลน์


ขอบคุณ Gunner มากครับที่ให้คำแนะนำ

ตอนนี้ผมกำลังหาวิธีที่จะดึงข้อมูลที่เก็บไว้ในฟังก์ชันนี้

Code (C#)
 private void wclBluetoothDiscovery_OnDiscoveryComplete(object sender, wcl.wclBluetoothDiscoveryCompleteEventArgs e)
        {
            if (e.Devices == null)
                MessageBox.Show("Error discovering");
            else
                if (e.Devices.Count == 0)
                    MessageBox.Show("Nothing found");
                else
                    for (uint i = 0; i < e.Devices.Count; i++)
                    {
                        wcl.wclBluetoothDevice Device = e.Devices[i];
                        ListViewItem Item = lvDevices.Items.Add(Device.Address);
                        string str = "";
                        Device.GetName(e.Radio, ref str);
                        Item.SubItems.Add(str);
                    
                    }
        }


คือที่เก็บไว้ที่จะไปแสดงใน ListView น่าจะเป็น (lvDevices) ที่หาอุปกรณ์มาได้หลายตัวแต่ต้องการจะให้มันเลือกส่งทีละตัวเป็นอันดับ1,2,3,4,...ไปเรื่อยๆเมื่อหมดในชุดแรกก็ให้มันค้าหาใหม่แล้วก็เลือกส่งทีละตัวอ่ะครับ
ตอนนี้รู้แค่ว่ามันเลือกตรงใหนคือฟังก์ชันนี้

wclClient.BluetoothParams.Address= lvDevices.SelectedItems[0].Text;
wclClient.BluetoothParams.Radio = Radios[0];
wclClient.Transport = wcl.wclClientTransport.ctBluetooth;
wcl.wclErrors.wclShowError(wclClient.Connect());

wclClient.BluetoothParams.Address= lvDevices.SelectedItems[0].Text;
พอเปลี่ยนให้เป็น
wclClient.BluetoothParams.Address= lvDevices.Items[0].SubItems[0].Text;เพื่อเลือกบรรทัดแรก
มันก็จะฟ้องว่าผิดพล้าดที่บรรทัดนี้
wclClient.BluetoothParams.Radio = Radios[0];
ผมเลย งง ไม่รุจะทำงัย



รายละเอียดอีกส่วนผมส่งให้ทางเมลพี่แล้วนะครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-01-26 16:18:14 By : konmuen
 


 

No. 4



โพสกระทู้ ( 154 )
บทความ ( 0 )



สถานะออฟไลน์


ลองตรวจสอบดูจากการ debug ว่าคำสั่งทั้ง 2 ได้ค่าเดียวกันหรือไม่

Code (C#)
wclClient.BluetoothParams.Address= lvDevices.SelectedItems[0].Text; 
wclClient.BluetoothParams.Address= lvDevices.Items[0].SubItems[0].Text;


ผมคิดว่าไม่น่าจะได้ค่าเดียวกัน เพราะว่า subitem ที่ index 0 จะเป็นค่าแรกของ subitem เท่านั้น ซึ่งจะไม่ใช่ค่า item ของ listview นะครับ คิดว่าน่าจะเปลี่ยนมาเป็นแบบนี้มากกว่า

Code (C#)
wclClient.BluetoothParams.Address= lvDevices.Items[0].Text;

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-01-26 19:46:13 By : gunnermontana
 


 

No. 5



โพสกระทู้ ( 15 )
บทความ ( 0 )



สถานะออฟไลน์


Error

มันฟ้องบรรทัดที่บอกอ่ะครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-01-26 20:34:18 By : konmuen
 


 

No. 6



โพสกระทู้ ( 154 )
บทความ ( 0 )



สถานะออฟไลน์


พอดีได้ลองอ่าน paper ดูแล้ว ดูจาก code แล้ว รู้สึกว่าที่คุณทำมานั้น ในส่วนของ Radios[0] น่าจะพลาดจากการ set ค่า wcl.wclBluetoothAPI ใน paper บอกไว้ว่า ตัว Radio จะจับสัญญาณไปตาม Device ที่ต้อง set ขึ้นก่อน โดยจะถูกเรียกว่า Dongle (ดองเกิล) ซึ่งเป็นภาษาคอมพิวเตอร์ คือหลักการเชื่อมต่อเพื่อทำความรู้จักกับตัวอุปกรณ์ระหว่าง 2 ตัว ซึ่งค่านี้ใน paper บอกว่าจะมีค่าเป็น enumerator มีทั้งหมด 4 ค่าคือ

baBlueSoleil
baMicrosoft
baToshiba
baWidComm

และ method ที่ต้องทำการ set ค่า Radio ก็คือ Property ชื่อ API อยู่ใน class wclBluetoothRadio ซึ่งเมื่อได้ค่า Radio แล้ว ก่อนจะทำการกำหนดค่า Radio ได้ จะต้องสั่งทำ Dongle API ก่อน ด้วยคำสั่งประมาณนี้ครับ

Code (C#)
Radio[0].API = wcl.wclBluetoothAPI.baMicrosoft;
wclClient.BluetoothParams.Radio = Radios[0];


คิดว่าต้องทำแบบนี้ถึงจะสามารถสั่งงาน Radio ได้
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-01-27 00:27:24 By : gunnermontana
 


 

No. 7



โพสกระทู้ ( 15 )
บทความ ( 0 )



สถานะออฟไลน์


ขอบคุณมากครับพี่...


private void btConnect_Click(object sender, EventArgs e)
{

if (lvDevices.Items.Count == 0)
MessageBox.Show("Select device");
else
{
wcl.wclBluetoothRadios Radios = new wcl.wclBluetoothRadios();
if (wcl.wclErrors.wclShowError(wclBluetoothDiscovery.EnumRadios(Radios)))
{
Radios = null;
return;
}

string DeAddress;
DeAddress = lvDevices.Items[0].Text ;
wclClient.BluetoothParams.Address = DeAddress;
wclClient.BluetoothParams.Radio = Radios[0];
wclClient.Transport = wcl.wclClientTransport.ctBluetooth;
wcl.wclErrors.wclShowError(wclClient.Connect());

Radios = null;
}
}

ถ้าเราจะให้มันวนรอบการทำงานให้เท่ากับตัวอุปกรณ์ที่ค้าหาเจอพร้อมทั้งเปลี่ยนให้เชื่อมต่อ lvDevices.Items[0].Text ไปเท่ากับจำนวนที่พบอุปกรณ์เริ่มตั้งแต่ตัวแรกจนถึงตัวสุดท้ายจะต้องทำงัยหรอครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-01-28 19:50:48 By : konmuen
 


 

No. 8



โพสกระทู้ ( 15 )
บทความ ( 0 )



สถานะออฟไลน์


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace BluetoothOPPClientDemo
{
public partial class fmMain : Form
{
public fmMain()
{
InitializeComponent();
}

private void fmMain_Load(object sender, EventArgs e)
{
wclAPI.Load();
}

private void fmMain_FormClosed(object sender, FormClosedEventArgs e)
{
wclAPI.Unload();
}



private void btDiscover_Click(object sender, EventArgs e)
{

wcl.wclBluetoothRadios Radios = new wcl.wclBluetoothRadios();
if (wcl.wclErrors.wclShowError(wclBluetoothDiscovery.EnumRadios(Radios)))
{
Radios = null;
return;
}

wcl.wclErrors.wclShowError(wclBluetoothDiscovery.Discovery(Radios[0]));
Radios = null;
}

private void wclBluetoothDiscovery_OnDiscoveryStarted(object sender, wcl.wclBluetoothDiscoveryStartedEventArgs e)
{
lvDevices.Items.Clear();

}

private void wclBluetoothDiscovery_OnDiscoveryComplete(object sender, wcl.wclBluetoothDiscoveryCompleteEventArgs e)
{
if (e.Devices == null)
MessageBox.Show("Error discovering");
else
if (e.Devices.Count == 0)
MessageBox.Show("Nothing found");
else
for (uint i = 0; i < e.Devices.Count; i++)
{
wcl.wclBluetoothDevice Device = e.Devices[i];
ListViewItem Item = lvDevices.Items.Add(Device.Address);
string str = "";
Device.GetName(e.Radio, ref str);
Item.SubItems.Add(str);

}
//__________________________________วนลูปทั้งชุดด้านล่าง

if (lvDevices.Items.Count == 0)
MessageBox.Show("Select device");
else
{
wcl.wclBluetoothRadios Radios = new wcl.wclBluetoothRadios();
if (wcl.wclErrors.wclShowError(wclBluetoothDiscovery.EnumRadios(Radios)))
{
Radios = null;
return;
}
string DeAddress = lvDevices.Items[0].Text; ;

wclClient.BluetoothParams.Address = DeAddress;
wclClient.BluetoothParams.Radio = Radios[0];
wclClient.Transport = wcl.wclClientTransport.ctBluetooth;
wcl.wclErrors.wclShowError(wclClient.Connect());

Radios = null;
}
}

private void wclClient_OnConnect(object sender, wcl.wclConnectEventArgs e)
{

}

private void wclClient_OnDisconnect(object sender, EventArgs e)
{

}

private void btDisconnect_Click(object sender, EventArgs e)
{
wclClient.Disconnect();
}
private void btOpenOBEX_Click(object sender, EventArgs e)
{

wcl.wclErrors.wclShowError(wclClient.OpenOBEXSession());
if (OpenFileDialog.ShowDialog() == DialogResult.OK)
{
System.IO.FileStream Stream = new System.IO.FileStream(OpenFileDialog.FileName, System.IO.FileMode.Open, System.IO.FileAccess.Read);
String AFile = System.IO.Path.GetFileName(OpenFileDialog.FileName);
wcl.wclErrors.wclShowError(wclClient.Put(AFile, Stream));
}
}

private void btCloseOBEX_Click(object sender, EventArgs e)
{
wcl.wclErrors.wclShowError(wclClient.CloseOBEXSession());
}

private void wclClient_OnOBEXConnect(object sender, wcl.wclConnectEventArgs e)
{

}

private void wclClient_OnOBEXDisconnect(object sender, EventArgs e)
{

}

private void wclClient_OnOBEXProgress(object sender, wcl.wclOBEXProgressEventArgs e)
{
ProgressBar.Maximum = (int)e.Size;
ProgressBar.Value = (int)e.Position;
}

private void wclClient_OnOBEXPutComplete(object sender, wcl.wclConnectEventArgs e)
{
ProgressBar.Value = 0;
if (e.Error == wcl.wclErrors.WCL_E_SUCCESS)
MessageBox.Show("Put complete with success");
else
MessageBox.Show("Put complete with error: " + e.Error.ToString());
wclClient.Disconnect();
wcl.wclErrors.wclShowError(wclClient.CloseOBEXSession());
}
}
}

ทำมาหลายวันล่ะงงมากเลยครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-01-29 19:57:07 By : konmuen
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : ช่วยทำให้โปรแกรมส่งข้อมูลผ่านบลูทูธส่งได้อัตโนมัติหน่อยครับ
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 02
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่