Serial Port AX - Problem when opening multiple ports one after the other (Read 11631 times)

I´m just evaluating your serial port activeX for my project. I am using the activex with VB 6 (SP 6). In my application I have placed one SPORTAX control. Now I first determine all existent COM-ports with this control (works perfectly). Afterwards I try to open each port, send a special string and wait for the answer of my device. If no answer occurs within a certain time period (timed by a VB Timer), I close the port and try to open the next port. Problem is: the next port is never opened! The SPORTAX.OPEN-method returns "false", when trying to open the second port.

This is more or less the code used:

Do while not portFound
if SPORTAX.OPEN ("COM" & existPortsArray(portcounter))
  SPORTAX.InitString ("9600,n,8,1")
  SPORTAX.WriteStr "ATZ" & Chr$(13)
end if

 ..check for Answer with ">" in it - if answer is correct then set portFound to True

Any suggestions?


Dear Matthias,

Before you try to open second COM port, please make sure that the first COM port is closed.


the problem is solved now. I had a SPORTAX.Close() call  in the code, but somehow it didn´t work - I changed the code slightly and everything works as expected.

But now I´m experiencing another problem, I can´t figure out:

When one of the ports, I am opening to find my device, is a bluetooth-COM-Port, which does not have a device connected to it, the whole program freezes! I don´t get any exception, which I can handle in the code. I have to close the app using the taskmanager!

The same occurs with your VB6 AND the VC6 sample application (unmodified!), when opening a Bluetooth-Port with no device connected to it, and then typing a letter in the terminal-textfield - the Port is opened OK - but immediately after typing the letter, the application freezes! (System Win XP-SP3, Bluetooth: Broadcom /Widcomm drivers (newest available)).

The latter problem really makes the activeX useless to me! So I really appreciate any help/workaround or patch!
« Last Edit: October 02, 2009, 10:03:12 AM by moDiag »

Dear Matthias,

Please, set the Timeout for Write Operation:

WriteTotalTimeoutMultiplier = 100

Dear Tina,

thank you, you saved my day! It works!

Just one single wish I have for the future:

Please make the OnRXFLAG-Event fire only when the EventChar really is in the inputbuffer. Right now it fires twice: the first time right after the event TXEMPTY (the inputbuffer does not contain data at this moment) and the second time when the eventcharacter really is in the buffer. I know activeX-controls which can handle that better (but have other flaws). I can handle this behaviour in the code for now. But it would be nicer when the event fires only once! You can see this behaviour in your sample progs when you add the line SPORTAX1.CharEvent=ASC(">") right after the .Open("COM1") - line. As soon as you open the port (without having a device connected to the port!) and type in a letter, you will get the messages "1 Byte sent";"OnTxEmpty";"OnRxFlag" - altough the event OnRxChar is NOT fired and no bytes were received (obviously because there is no device present)! Thanks again!


Dear Matthias,

Please, note that Serial Port ActiveX Control does not handle the events. It does not detect when exactly the event occurs, it just sends the event to the application.


Sitemap 1 2 3 4 5