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.
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: