Virtual Serial Port Bluetooth System.IO.Ports

H

henrycortezwu

Hi All,
I'm trying to connect to a virtual port (COM19, OUTGOING, "Bluetooth
Serial Port") using VS2005 System.IO.Ports.

When I ran the ff code below here's what happens.
1) VS2005 Compiles w/o errors
2) My Nokia 6600 prompted me the message "Accept Connection request
from DEMON?"
note: DEMON is my computers name.
3) Using my Nokia 6600, I hit the button that refers to the "Yes"
command.
4) Error prompted at port.Open(), saying that "The network connection
was gracefully closed."

note also that : "Passkey" is enabled on my cellphone/computer and was
entered correctly when asked.

i also so somewhere on the net that baudrate will be ignored for
bluetooth driver will be the one to autodiscover and adjust to whats
the real value? is this true?

i wish to send jpg images to my cellphone using my serial connection,
is this possible? sending out bytes of data?

I've tried using http://32feet.net/ but it proves to be difficult using
OBEX and on the fly sample projects failed to compile on VS2005.

serial connection using virtual serial ports and VS2005's new Serial
Port feature seems the easiest way to go.

Hope anyone can help out on this. I'll be very much gratefull on any
clues/leads/solutions that you may give.

Many Thanks,
Henry :)

Code Used
----------------------------------------------------------------------------------------------------
Imports System.IO.Ports

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

Dim port As SerialPort = New SerialPort("COM19", 9600, Parity.None, 8,
StopBits.One)
port.Open()
port.Write("Hello World")
port.Close()


End Sub
----------------------------------------------------------------------------------------------------



Stack Trace
----------------------------------------------------------------------------------------------------
System.IO.IOException was unhandled
Message="The network connection was gracefully closed.
"
Source="System"
StackTrace:
at System.IO.Ports.InternalResources.WinIOError(Int32 errorCode,
String str)
at System.IO.Ports.SerialStream.InitializeDCB(Int32 baudRate,
Parity parity, Int32 dataBits, StopBits stopBits, Boolean discardNull)
at System.IO.Ports.SerialStream..ctor(String portName, Int32
baudRate, Parity parity, Int32 dataBits, StopBits stopBits, Int32
readTimeout, Int32 writeTimeout, Handshake handshake, Boolean
dtrEnable, Boolean rtsEnable, Boolean discardNull, Byte parityReplace)
at System.IO.Ports.SerialPort.Open()
at WindowsApplication1.Form1.SendSampleData() in E:\My
Documents\Visual Studio 2005\Projects\Bluetooth\Bluetooth\Form1.vb:line
17
at WindowsApplication1.Form1.Button1_Click(Object sender,
EventArgs e) in E:\My Documents\Visual Studio
2005\Projects\Bluetooth\Bluetooth\Form1.vb:line 76
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m,
MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at
System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at
System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr
hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at
System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at
System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32
dwComponentID, Int32 reason, Int32 pvLoopData)
at
System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32
reason, ApplicationContext context)
at
System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32
reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(ApplicationContext
context)
at
Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
at
Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
at
Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[]
commandLine)
at WindowsApplication1.My.MyApplication.Main(String[] Args) in
17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
at System.AppDomain.nExecuteAssembly(Assembly assembly, String[]
args)
at System.AppDomain.ExecuteAssembly(String assemblyFile,
Evidence assemblySecurity, String[] args)
at
Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object
state)
at System.Threading.ExecutionContext.Run(ExecutionContext
executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
----------------------------------------------------------------------------------------------------
 
D

DickGrier

Hi Henry,

(You sent me email about this offline, but you didn't say you were using VS
2005, so I assumed that you were using VS 2003.)

Personally, I HATE using the Constructor to configure the serial object.
What I do is to create a simple object (New), then use the individual
properties, such as BaudRate, Parity, DataBits, StopBits, and PortName.
This (IMO) makes the code more readable (sure, a little more verbose, but
you get what you pay for).

Just use the GetPortNames method to see what port names that the serial port
object likes. For example, here is some code that I use to populate a
listbox:

Dim PortNames() As String =

..SerialPort.GetPortNames()

For I = PortNames.Length - 1 To 0 Step -1

lstCommPort.Items.Add(PortNames(I))

Next

As I mentioned in my email reply, I'd need your BT hardware in order to try
to figure out what is going on. It may be easy, it may be hard. Sorry.
--
Richard Grier, MVP
Hard & Software
Author of Visual Basic Programmer's Guide to Serial Communications, Fourth
Edition, ISBN 1-890422-28-2, Mabry Publishing (391 pages, includes CD-ROM).
July 2004.
See www.hardandsoftware.net for details and contact information.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top