H HARRY Active Member Licensed User Longtime User Dec 31, 2018 #1 In a For/Next loop I have to set an IO-Port High and after a while (say 5 msec) to set it Low again. I tried it as follows: Code: Sub DoStep CSU.CallSubPlus(Me,"StepUp",5) CSU.CallSubPlus(Me,"StepDown",5) End Sub Sub StepUp PStep.State=True End Sub Sub StepDown PStep.State=False End Sub After a while I get the following error info: Code: java.lang.OutOfMemoryError: unable to create new native thread at java.lang.Thread.start0(Native Method) at java.lang.Thread.start(Thread.java:714) at anywheresoftware.b4a.objects.Timer.startTicking(Timer.java:68) at anywheresoftware.b4a.objects.Timer.setEnabled(Timer.java:77) at b4j.example.callsubutils._plusimpl(callsubutils.java:153) at b4j.example.callsubutils._callsubplus2(callsubutils.java:167) at b4j.example.callsubutils._callsubplus(callsubutils.java:81) at b4j.example.main._dostep(main.java:124) at b4j.example.main._scan(main.java:290) at b4j.example.main._stream2_newtext(main.java:426) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:497) at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:625) at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.j ava:237) at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:168) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:497) at anywheresoftware.b4a.BA.raiseEvent2(BA.java:90) at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:94) at anywheresoftware.b4a.keywords.Common.CallSub4(Common.java:487) at anywheresoftware.b4a.keywords.Common.access$0(Common.java:467) at anywheresoftware.b4a.keywords.Common$CallSubDelayedHelper.run(Common.java:541) at anywheresoftware.b4a.keywords.SimpleMessageLoop.runMessageLoop(SimpleMessageLoop.java:30) at anywheresoftware.b4a.StandardBA.startMessageLoop(StandardBA.java:26) at anywheresoftware.b4a.ShellBA.startMessageLoop(ShellBA.java:115) at anywheresoftware.b4a.keywords.Common.StartMessageLoop(Common.java:153) at anywheresoftware. b4a.shell.Shell.raiseEventImpl(Shell.java:308) at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:168) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:497) at anywheresoftware.b4a.BA.raiseEvent2(BA.java:90) at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:94) at anywheresoftware.b4a.BA.raiseEvent(BA.java:77) at b4j.example.main.main(main.java:29) Fout op regel: 47 (CallSubUtils) java.lang.RuntimeException: java.lang.RuntimeException: java.lang.OutOfMemoryError: unable to create new native thread at anywheresoftware.b4a.keywords.Common.CallSub4(Common.java:496) at anywheresoftware.b4a.keywords.Common.access$0(Common.java:467) at anywheresoftware.b4a.keywords.Common$CallSubDelayedHelper.run(Common.java:541) at anywheresoftware.b4a.keywords.SimpleMessageLoop.runMessageLoop(SimpleMessageLoop.java:30) at anywheresoftware.b4a.StandardBA.startMessageLoop(StandardBA.java:26) at anywheresoftware.b4a.ShellBA.startMessageLoop(ShellBA.java:115) at anywheresoftware.b4a.keywords.Common.StartMessageLoop(Common.java:153) at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:308) at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:168) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.l ang.reflect.Method.invoke(Method.java:497) at anywheresoftware.b4a.BA.raiseEvent2(BA.java:90) at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:94) at anywheresoftware.b4a.BA.raiseEvent(BA.java:77) at b4j.example.main.main(main.java:29) Caused by: java.lang.RuntimeException: java.lang.OutOfMemoryError: unable to create new native thread at anywheresoftware.b4a.BA.raiseEvent2(BA.java:119) at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:94) at anywheresoftware.b4a.keywords.Common.CallSub4(Common.java:487) ... 16 more Caused by: java.lang.OutOfMemoryError: unable to create new native thread at java.lang.Thread.start0(Native Method) at java.lang.Thread.start(Thread.java:714) at anywheresoftware.b4a.objects.Timer.startTicking(Timer.java:68) at anywheresoftware.b4a.objects.Timer.setEnabled(Timer.java:77) at b4j.example.callsubutils._plusimpl(callsubutils.java:153) at b4j.example.callsubutils._callsubplus2(callsubutils.java:167) at b4j.example.callsubutils._callsubplus(callsubutils.jav a:81) at b4j.example.main._dostep(main.java:124) at b4j.example.main._scan(main.java:290) at b4j.example.main._stream2_newtext(main.java:426) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:497) at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:625) at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:237) at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:168) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:497) at anywheresoftware.b4a.BA.raiseEvent2(BA.java:90) ... 18 more java.lang.RuntimeException: java.util.NoSuchElementException at anywheresoftware.b4a.BA.raiseEvent2(BA.java:119) at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:94) at anywheresoftware.b4a.BA.raiseEvent(BA.java:77) at b4j.example.main.main(main.java:29) Caused by: java.util.NoSuchElementException at java.util.LinkedList.removeFirst(LinkedList.java:270) at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:327) at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:168) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:497) at anywheresoftware.b4a.BA.raiseEvent2(BA.java:90) ... 3 more Program terminated (StartMessageLoop was not called). I also tried to use Sleep, but then, as far as I understand, the For/Next loop is continued while Sleeping. Of course I could use a time consuming loop, but the cpu has to run also another program, so that is not really an option. Any suggestion? Harry
In a For/Next loop I have to set an IO-Port High and after a while (say 5 msec) to set it Low again. I tried it as follows: Code: Sub DoStep CSU.CallSubPlus(Me,"StepUp",5) CSU.CallSubPlus(Me,"StepDown",5) End Sub Sub StepUp PStep.State=True End Sub Sub StepDown PStep.State=False End Sub After a while I get the following error info: Code: java.lang.OutOfMemoryError: unable to create new native thread at java.lang.Thread.start0(Native Method) at java.lang.Thread.start(Thread.java:714) at anywheresoftware.b4a.objects.Timer.startTicking(Timer.java:68) at anywheresoftware.b4a.objects.Timer.setEnabled(Timer.java:77) at b4j.example.callsubutils._plusimpl(callsubutils.java:153) at b4j.example.callsubutils._callsubplus2(callsubutils.java:167) at b4j.example.callsubutils._callsubplus(callsubutils.java:81) at b4j.example.main._dostep(main.java:124) at b4j.example.main._scan(main.java:290) at b4j.example.main._stream2_newtext(main.java:426) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:497) at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:625) at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.j ava:237) at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:168) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:497) at anywheresoftware.b4a.BA.raiseEvent2(BA.java:90) at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:94) at anywheresoftware.b4a.keywords.Common.CallSub4(Common.java:487) at anywheresoftware.b4a.keywords.Common.access$0(Common.java:467) at anywheresoftware.b4a.keywords.Common$CallSubDelayedHelper.run(Common.java:541) at anywheresoftware.b4a.keywords.SimpleMessageLoop.runMessageLoop(SimpleMessageLoop.java:30) at anywheresoftware.b4a.StandardBA.startMessageLoop(StandardBA.java:26) at anywheresoftware.b4a.ShellBA.startMessageLoop(ShellBA.java:115) at anywheresoftware.b4a.keywords.Common.StartMessageLoop(Common.java:153) at anywheresoftware. b4a.shell.Shell.raiseEventImpl(Shell.java:308) at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:168) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:497) at anywheresoftware.b4a.BA.raiseEvent2(BA.java:90) at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:94) at anywheresoftware.b4a.BA.raiseEvent(BA.java:77) at b4j.example.main.main(main.java:29) Fout op regel: 47 (CallSubUtils) java.lang.RuntimeException: java.lang.RuntimeException: java.lang.OutOfMemoryError: unable to create new native thread at anywheresoftware.b4a.keywords.Common.CallSub4(Common.java:496) at anywheresoftware.b4a.keywords.Common.access$0(Common.java:467) at anywheresoftware.b4a.keywords.Common$CallSubDelayedHelper.run(Common.java:541) at anywheresoftware.b4a.keywords.SimpleMessageLoop.runMessageLoop(SimpleMessageLoop.java:30) at anywheresoftware.b4a.StandardBA.startMessageLoop(StandardBA.java:26) at anywheresoftware.b4a.ShellBA.startMessageLoop(ShellBA.java:115) at anywheresoftware.b4a.keywords.Common.StartMessageLoop(Common.java:153) at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:308) at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:168) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.l ang.reflect.Method.invoke(Method.java:497) at anywheresoftware.b4a.BA.raiseEvent2(BA.java:90) at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:94) at anywheresoftware.b4a.BA.raiseEvent(BA.java:77) at b4j.example.main.main(main.java:29) Caused by: java.lang.RuntimeException: java.lang.OutOfMemoryError: unable to create new native thread at anywheresoftware.b4a.BA.raiseEvent2(BA.java:119) at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:94) at anywheresoftware.b4a.keywords.Common.CallSub4(Common.java:487) ... 16 more Caused by: java.lang.OutOfMemoryError: unable to create new native thread at java.lang.Thread.start0(Native Method) at java.lang.Thread.start(Thread.java:714) at anywheresoftware.b4a.objects.Timer.startTicking(Timer.java:68) at anywheresoftware.b4a.objects.Timer.setEnabled(Timer.java:77) at b4j.example.callsubutils._plusimpl(callsubutils.java:153) at b4j.example.callsubutils._callsubplus2(callsubutils.java:167) at b4j.example.callsubutils._callsubplus(callsubutils.jav a:81) at b4j.example.main._dostep(main.java:124) at b4j.example.main._scan(main.java:290) at b4j.example.main._stream2_newtext(main.java:426) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:497) at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:625) at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:237) at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:168) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:497) at anywheresoftware.b4a.BA.raiseEvent2(BA.java:90) ... 18 more java.lang.RuntimeException: java.util.NoSuchElementException at anywheresoftware.b4a.BA.raiseEvent2(BA.java:119) at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:94) at anywheresoftware.b4a.BA.raiseEvent(BA.java:77) at b4j.example.main.main(main.java:29) Caused by: java.util.NoSuchElementException at java.util.LinkedList.removeFirst(LinkedList.java:270) at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:327) at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:168) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:497) at anywheresoftware.b4a.BA.raiseEvent2(BA.java:90) ... 3 more Program terminated (StartMessageLoop was not called). I also tried to use Sleep, but then, as far as I understand, the For/Next loop is continued while Sleeping. Of course I could use a time consuming loop, but the cpu has to run also another program, so that is not really an option. Any suggestion? Harry
Erel B4X founder Staff member Licensed User Longtime User Dec 31, 2018 #2 There is no reason to use CallSubPlus. Change your code to: Code: Sub DoStep Sleep(5) StepUp Sleep(5) StepDown End Sub Upvote 0
There is no reason to use CallSubPlus. Change your code to: Code: Sub DoStep Sleep(5) StepUp Sleep(5) StepDown End Sub
H HARRY Active Member Licensed User Longtime User Dec 31, 2018 #3 Sorry Erel, That doesn't work. The For Next is: Code: For stepsdone = 0 To stepstodo -1 Step 1 DoStep Next . Code: Sub DoStep Sleep(5) StepUp Sleep(5) StepDown End Sub When running the first Sleep(5) is executed and then the next DoStep is activated. StepUp is never called. In fact I need an 'old' Sleep, not resumable. Harry Upvote 0
Sorry Erel, That doesn't work. The For Next is: Code: For stepsdone = 0 To stepstodo -1 Step 1 DoStep Next . Code: Sub DoStep Sleep(5) StepUp Sleep(5) StepDown End Sub When running the first Sleep(5) is executed and then the next DoStep is activated. StepUp is never called. In fact I need an 'old' Sleep, not resumable. Harry
XbNnX_507 Active Member Licensed User Longtime User Dec 31, 2018 #4 I think this should help Code: For stepsdone = 0 To stepstodo -1 Step 1 wait for ( DoStep ) Complete Next Sub DoStep as resumablesub Sleep(5) StepUp Sleep(5) StepDown return End Sub Upvote 0
I think this should help Code: For stepsdone = 0 To stepstodo -1 Step 1 wait for ( DoStep ) Complete Next Sub DoStep as resumablesub Sleep(5) StepUp Sleep(5) StepDown return End Sub
Erel B4X founder Staff member Licensed User Longtime User Jan 1, 2019 #5 Almost. You must have a return value. Code: For stepsdone = 0 To stepstodo -1 Step 1 wait for ( DoStep) Complete (Unused As Boolean) Next Sub DoStep as resumablesub Sleep(5) StepUp Sleep(5) StepDown return True End Sub More info: [B4X] Resumable subs that return values (ResumableSub) Upvote 0
Almost. You must have a return value. Code: For stepsdone = 0 To stepstodo -1 Step 1 wait for ( DoStep) Complete (Unused As Boolean) Next Sub DoStep as resumablesub Sleep(5) StepUp Sleep(5) StepDown return True End Sub More info: [B4X] Resumable subs that return values (ResumableSub)