Link to home
Start Free TrialLog in
Avatar of Upland
Upland

asked on

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.
Avatar of alokanant
alokanant

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

Avatar of Upland

ASKER

alokanant

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.
ASKER CERTIFIED SOLUTION
Avatar of rockie
rockie

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Upland

ASKER

Rockie,
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!
Chris