By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,916 Members | 1,286 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,916 IT Pros & Developers. It's quick & easy.

Virtual Serial Port Bluetooth System.IO.Ports

P: n/a
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"
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 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,
port.Write("Hello World")
End Sub

Stack Trace
System.IO.IOException was unhandled
Message="The network connection was gracefully closed.
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
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(MouseEventAr gs 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)
System.Windows.Forms.Control.ControlNativeWindow.O nMessage(Message& m)
System.Windows.Forms.Control.ControlNativeWindow.W ndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallba ck(IntPtr
hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
System.Windows.Forms.UnsafeNativeMethods.DispatchM essageW(MSG& msg)
System.Windows.Forms.Application.ComponentManager. System.Windows.Forms.UnsafeNativeMethods.IMsoCompo nentManager.FPushMessageLoop(Int32
dwComponentID, Int32 reason, Int32 pvLoopData)
System.Windows.Forms.Application.ThreadContext.Run MessageLoopInner(Int32
reason, ApplicationContext context)
System.Windows.Forms.Application.ThreadContext.Run MessageLoop(Int32
reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(ApplicationCo ntext
Microsoft.VisualBasic.ApplicationServices.WindowsF ormsApplicationBase.OnRun()
Microsoft.VisualBasic.ApplicationServices.WindowsF ormsApplicationBase.DoApplicationModel()
Microsoft.VisualBasic.ApplicationServices.WindowsF ormsApplicationBase.Run(String[]
at WindowsApplication1.My.MyApplication.Main(String[] Args) in
17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
at System.AppDomain.nExecuteAssembly(Assembly assembly, String[]
at System.AppDomain.ExecuteAssembly(String assemblyFile,
Evidence assemblySecurity, String[] args)
Microsoft.VisualStudio.HostingProcess.HostProc.Run UsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context( Object
at System.Threading.ExecutionContext.Run(ExecutionCon text
executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()

Jan 8 '06 #1
Share this Question
Share on Google+
1 Reply

P: n/a
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

Dim PortNames() As String =


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



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 for details and contact information.
Jan 9 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.