Command line to open CoolTerm instance connected?

If you have specific questions or problems with any of my Freeware applications, post them here.
jmuhammad
Posts: 26
Joined: Wed Aug 17, 2022 10:21 pm

Re: Command line to open CoolTerm instance connected?

Post by jmuhammad »

Greetings,
The script was working fine but this morning I got the following error:

Code: Select all

 COM4 (AQ043AA4)
 COM9 (S/N not available)
COM13 (S/N not available)
 1000 (Exit)

Select available COM number from list (e.g. 1-256) or '1000' to exit: 4
CoolTerm is already running...
ERROR: Could not connect to CoolTerm
Traceback (most recent call last):
  File "H:\Python\_PyProjects\usbser2ct\usbser2ct.pyw", line 234, in <module>
    ID1 = s.LoadSetting(template_settings_file)  # myapp.cooltermsettings
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "H:\Python\_PyProjects\usbser2ct\CoolTerm.py", line 345, in LoadSetting
    Response = self._SendPacket(Packet)
               ^^^^^^^^^^^^^^^^^^^^^^^^
  File "H:\Python\_PyProjects\usbser2ct\CoolTerm.py", line 278, in _SendPacket
    self.skt.sendall(Packet)
OSError: [WinError 10057] A request to send or receive data was disallowed because the socket is not connected and (when sending on a datagram socket using a sendto call) no address was supplied
Do you think it is a matter of retrying to connect socket / waiting for confirmation that socket is connected? Admittedly I did not add 'retries' to this hurriedly assembled script (I had in previous version) but before I try I wanted a little more info on the error message. Also is there a 'smart' way to confirm socket is connected or is it just 'try..except' s=CoolTerm.CoolTermSocket() a number of times?
TIA.
---
Edit 20260111-1530
OK, I got confirmation that the socket is connected but I got similar error:

Code: Select all

 COM4 (AQ043AA4)
 COM9 (S/N not available)
COM13 (S/N not available)
 1000 (Exit)

Select available COM number from list (e.g. 1-256) or '1000' to exit: 4
CoolTerm is already running...
ERROR: Could not connect to CoolTerm
  2)  Creating Socket...
ERROR: Could not connect to CoolTerm
      CoolTermSocket('127.0.0.1',51413) connected.
Traceback (most recent call last):
  File "H:\Python\_PyProjects\usbser2ct\usbser2ct.pyw", line 281, in <module>
    ID1 = s.LoadSetting(template_settings_file)  # myapp.cooltermsettings
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "H:\Python\_PyProjects\usbser2ct\CoolTerm.py", line 345, in LoadSetting
    Response = self._SendPacket(Packet)
               ^^^^^^^^^^^^^^^^^^^^^^^^
  File "H:\Python\_PyProjects\usbser2ct\CoolTerm.py", line 278, in _SendPacket
    self.skt.sendall(Packet)
OSError: [WinError 10057] A request to send or receive data was disallowed because the socket is not connected and (when sending on a datagram socket using a sendto call) no address was supplied
---
Edit 20260111-1609
The only way to get the script working again was to shut down and restart CoolTerm. Then the script worked again. But:
a) What is the issue and why did the issue occur?
b) Is this only way to fix (manually restart)?
User avatar
roger
Site Admin
Posts: 542
Joined: Fri Apr 24, 2009 12:41 am
Contact:

Re: Command line to open CoolTerm instance connected?

Post by roger »

I haven't had any issues with the remote socket spontaneously disconnecting, so I don't know what may have happened in your case.

You can use the "Ping" command to check if you're connected. It returns true if you're connected and false if not.
jmuhammad
Posts: 26
Joined: Wed Aug 17, 2022 10:21 pm

Re: Command line to open CoolTerm instance connected?

Post by jmuhammad »

I think what happened is that if the GUI is not fully up before creating the socket the IDE generates these [unhelpful] errors.
So I have had to put a 10s delay before creating the socket. At least on my machine.
To test just try to start CoolTerm then immediately create/connect a socket...those errors will get produced.
Without feedback as to when the socket can be created/connected a hard-coded delay has to be used. If I make it too small then sometimes it will work and sometimes it won't. Seems 10s is safe.
If you have any thoughts on this please advise, thanks.
---
Edit 20260111-2300
The timers say GUI Detection took 12.4949 seconds to be 'ready' (although I physically saw the GUI maybe 1-2 seconds earlier).
But I believe that if you try to create/connect a socket before the application is 'ready' it will produce errors. Knowing when it is 'ready' requires some kind of monitoring. I am trying a dlg.wait('ready', timeout=timeout) function and it seems to block the create/connect a socket until CoolTerm is ready in lieu of hard-coding time.sleep() delays.
I use time.sleep(1) for additional instances and they complete in less than 1 second.
Post Reply