开发者

Send/Receive Text and Data to bluetooth (Com Port) using C#

开发者 https://www.devze.com 2023-03-10 11:46 出处:网络
I am creating a program which can send test or data to Bluetooth devices. For this purpose I want to use the virtual serial ports supplied by Bluetooth software.

I am creating a program which can send test or data to Bluetooth devices. For this purpose I want to use the virtual serial ports supplied by Bluetooth software.

Q. Is there is any w开发者_JAVA百科ay to send network stream to virtual serial port like socket programming in LAN?

Q. How do I receive data form Bluetooth? Does it is in the form of Network Stream?

Q. Which is the fast method to send and receive data over Bluetooth?

Because I not only send text to the device but also Images and other type of data.


1) Not certain about Bluetooth virtual ports, but I suspect that you can just use readFile/writeFile, (or the 'Ex' asynchronous versions), to the handle returned by CreateFile(), just like a 'normal' serial port. If so, you can handle the handle, (sorry!), just like the socket handle raised in a client socket connect() or a server listener accept(). So you should be able to use a dedicated thread, an I/Ocompletion routine, or IO completion ports to communicate with the virtual port.

I have done something like this before, but with Delphi and a 'real' serial port and a client network connection. I used an IO completion routine where an 'IOhandler' class was transferred to the completion routine in the 'hEvent' field. The serial port and client socket classes were IOhandler descendants, so the same IO completion routine code worked for both. It worked OK, (eventually:). I don't know of any reason why it would not work OK in C#.

2) Again, certain about Bluetooth virtual ports. Given that many Bluetooth implementations can supply these virtual COM ports as an interface, then the transport must surely be an 'octet stream', just like TCP or a 'real' COM port.

3) On Windows? I suspect IO completion ports. Probably dosn't matter much because Bluetooth bandwidth is not that great compared with what Windows can handle.

Rgds, Martin


might this will help you mCore™ .NET SMS Library

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号