PDA

Click to See Complete Forum and Search --> : can not open comport


bcincin
Feb 19th, 2009, 02:24 AM
Hi, I'm newbie and I don't know what the problem is. Sometimes program can not open serial port. For example the code below, was working just fine for com9 yesterday, now it's not. It tries to run "MSComm1.PortOpen = True" the goes to error. Same error occurs for some other ports, time to time. Can you help me?



Private Sub cmdBasla_Click()
On Error GoTo hata
MSComm1.CommPort = Val(Replace(Combo1.Text, "Comm", ""))

If MSComm1.PortOpen = False Then MSComm1.PortOpen = True
cmdBasla.Enabled = False
Exit Sub
hata:
Call subLogEkle("cmdBasla_Click " & Err.Description)
End Sub

grahamk
Feb 22nd, 2009, 05:16 PM
Are you sure that the port is not already opened by another application? If the port has been opened already by another app (eg. Hyperterminal) it will generate an error.

bcincin
Feb 23rd, 2009, 02:57 AM
No I'm not sure. I do not run HyperTerminal but some programs (eq virtual daemon manager) run at startup. Does it use comport? By the way, this occurs for several ports, not just for one.

grahamk
Feb 23rd, 2009, 04:26 PM
Its hard to guess what is going on from here. Have you tried stripping out the code and putting it into a small exe project? If you remove as many layers of complexity as you can, you can establish at what layer the problem begins. If you write a tiny program that does nothing but open the port and you still have a problem then it might be an issue with your OS or hardware.

I have done a lot of work using the mscomm object, and I have found it to be very stable. Have you tried using another piece of commercial software to test the com ports? You might find PortMon (http://technet.microsoft.com/en-us/sysinternals/bb896644.aspx) useful. I have found it extremely helpful. You can see a lot more of what is happening outside your code.

Good luck.

grahamk
Feb 23rd, 2009, 04:36 PM
More thoughts.

When you write the test program just put the code onto Form_Load, and use a hard wired literal for the port number. Make sure that the port opens from hyperterminal first. If you can't get a connection from hyperterminal there is no point in trying from VB.

You also need to make sure that the port settings are correct. I think the default is 9600,8,1,none. You need to check the device specs to make sure you have them set correctly.