Question Anyone familiar with RS232 port programming?

aeskan

Well-known member
Joined
Aug 10, 2011
Messages
63
Programming Experience
3-5
Hello everybody,

Previously I had written an application with VB6 that works with COM Ports via MSCommLib.MSComm. It works properly with COM1 as RS232 port and runs its codes perfectly. Lately I'm writing another application with VB.Net 2010 which needs to deal with RS232 port. Therefore I'm using System.IO.Ports.SerialPort instead of MSComm.

In my VB6 application I simply wrote:

Private Sub Form_Load()
If MSComm1.PortOpen Then MSComm1.PortOpen = False
MSComm1.CommPort = 1
MSComm1.Settings = "9600,n,8,1"
MSComm1.RThreshold = 1
MSComm1.PortOpen = True

End Sub

And then in the MSComm1_OnComm() sub, I catched the MSComm events as bellow:
Private Sub MSComm1_OnComm()
Select Case MSComm1.CommEvent
Case comEvCD
If MSComm1.CDHolding Then ....
Case comEvCTS
If MSComm1.CTSHolding Then ....
Case comEvDSR
If MSComm1.DSRHolding Then ....
Case comEvRing
Case comEvReceive
Case comEvSend
Case comEvEOF
End Select

End Sub

Which works perfectly. The problem is;
In the same time and same PC, MSComm in VB6 works fine with COM1 but System.IO.Ports.SerialPort in .Net does not work and always throw exception "COM1 access is denied" (means Port is in use).

With many thanks & regards.
 
Last edited:
My guess is that the MSComm in VB6 is not closing correctly - hence denying the .NET access to COM1.

1. Post your .NET code here, so we can check it.
2. Try NOT running the VB6 version at all, to see if the .NET version works.
 
InertiaM;

Your guess was almost right, not in VB6 version, but in my .Net version I had a forgotten Dialing function which used the Modem and did not close MSComm correctly, therefore it impressed on System.IO.Ports.SerialPort as well. By closing MSComm in that function the probelm is solved.

Thank you so much, for your intelligently advice and your attention.
 
Back
Top