• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 625
  • Last Modified:

MScomm.portopen problem

I admit I am new to programming comms - but this isn't exactly rocket science!

I have been given this gizmo to communicate with which should be straightforward (It comes with a DOS program which needs to be rewritten in Win32). I am running Win95, VB5 (SP3).

I have 2 comm ports on the PC with this gizmo plugged into com1 I find that the the command "mscomm.portopen = true" gives me an error claiming "port is already open" (Err 8005) yet when I write to it it says "operation only valid when port is open" (Err 8018). If I break the program and look at the value then sure enough mscomm.portopen IS false!!

If I change the mscomm.commport to com2 then there is no such problem... ie. port starts off closed, then it is opened, then it is written to.

I want to keep it in com1 for now - and at least offer a choice. But the DOS program I am converting is hardcoded to com1.
  • 2
  • 2
1 Solution
Why don't you check the value of mscomm.portopen before setting it to true.
You can do this at several places of the program, to find the exact instance where the value becomes true.

hope this helps.
There are following possible reasons, please check them out one by one, besides the comment given by me -
1> Check whether the address assigned by the software to Com Port 1 is correct or not, this means that your software might be setting the parameters of Com port to address of the second comm port.
2> There may be a problem in the Com Port 1. You can check this by connecting this to some other device.

hope this helps.

UplandAuthor Commented:

Thanks for the reply.....

As I mentioned in the question I HAVE done a break and checked it. Even if I break on the line "mscomm.portopen = True" and look at the value of mscomm.portopen before the line is executed, it tells me it is False - yet as soon as I execute that very same line, it gives me the error about it being already open!

In your answer, I am not sure what you mean by Point 1. According to windows, the address of com1 is 3F8 and com2 is 2F8. This cannot be affected from within VB where you simply pass 1 or 2 to the functions.... or have I missed your point?

In response to your Point 2, the DOS program supplied works just fine on either port.
I have had this same problem with a program,
and mscomm1.portopen said false when I stepped it through.
And as simple as it sounds it is another program or device not associated with your visual basic program is more than likly grabbing the port.  here are some things to try
1.cntrl + alt + del   -   and end all tasks except for     explorer and systray  then try it if that don't work run it on another computer, if you can not run it on another computer boot up in safe mode(the reason why in safe mode you might only see on device on com1 in normal mode but in safe mode you never know how many are realy trying to use that com port, remove them all if there are any "ghost devices") remove your com port and any devices that are using it in your device manager. shut down go into your system bios disable com 1.  Exit save the changes and reboot.  let windows detect the com port and the device you removed on it.  Then go back to your device manager and disable this device ----- try it again after ending all tasks except explorer and systray.

the problem your having dosen't sound like a visual basic problem, but instead a computer problem.
best of luck

UplandAuthor Commented:
Yes... you are absolutely right! The DOS program which I had run did not give up control of the port... as soon as I closed the DOS box the port was freed.
I still find it annoying that it said it was False when it was actually True. Anyway... it is fine now thanks!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now