 |
|
|
Topic: "out of stack space" error using excel 2000 on a windows xp machine
|
By: scott | Posted on: May 14 2013 at 09:18:51 PM | i have 23 scomm32's instantiated on sheet 2 of my spreadsheet.
i then do:
SComm2.CommPort = 15 'set the com #
SComm2.Settings = "9600,N,8,1"
SComm2.InputLen = 0 ' Read entire buffer
SComm2.PortOpen = True ' Opens the port
it then waits for a few seconds the gives the stack error (when i first open the excel program this might work properly 1 time, but later runs of the macro fail)
hyper term opens the port fine and 'talks' to the serial device?
Any thoughts?
Thanks
Scott | |
By: Guest | Posted on: May 14 2013 at 09:42:59 PM | Out of stack space is almost always caused by re-entrant code.
What do i mean by re-entrant code. For example imagine an event handler that triggers again before the event has finished executing. Calling doevents inside the handler would allow the handler to run again even though the previous instance of the handler hadn't exited. Each instance pushes local variables onto the stack and the stack grows and grows till it runs out of stack space.
Look at your code. Do not call doevents inside an event handler.
Disable the OverlappedIO property of the scomm ocx. If that appears to fix the problem then the problem is in your code and disabling overlappedIO prevents re-entrant comms events. | |
By: scott | Posted on: May 14 2013 at 10:35:16 PM | i will try the OverlappedIO property settings. Also note i can run the above code in single step debug mode, and the line after "SComm2.PortOpen = True" never gets executed, because the error occurs.
Thank for the help.
more ideas welcomed!
Scott | |
By: Guest | Posted on: May 14 2013 at 10:58:09 PM | I notice you code shows sComm2. Do you have sComm1 as well? Whats that one doing? | |
By: Scott | Posted on: May 15 2013 at 09:16:35 PM | Just picked one (i.e. #2), as i said i have 23 of them doing the same thing on different ports | |
By: Mike | Posted on: May 15 2013 at 09:29:30 PM | I guess 'Guest' missed your mention of 23.
I'll ask a question though. You have 23 ports. Does it manage to initialize any of them before the error happens?
Personally i never put something like the comm ocx directly onto a spreadsheet. I prefer to create a form in VBA and put the ocx on that. That way i have a form load event for setting up all the properties and somewhere for the oncomm event and i know whats running and when its running.
On the other hand I've never put 23 of them onto a form either. Do you still get the error if you just have one instance of the ocx ? Maybe try with just one and if that works increase it till it fails. That might give somebody an idea of where the problem is. | |
|