Author Topic: Help! My Vox isn't running a command except for via the green arrow in cmd edit!  (Read 8205 times)

0 Members and 1 Guest are viewing this topic.

01ste02

  • $upporter
  • Jr. Member
  • *****
  • Posts: 37
  • Karma: 1
  • 16 Years old hobby-developer in home-automation
    • View Profile
    • Company website (Swedish and incomplete)
Hello!

I have this problem where Vox is starting a python file without errors when I click the green arrow in command tree editor, but when I  start the macro by voice it gives me an access denied error.

I made a video about the error, because one picture can tell a thousand words (and with 60 fps and three minutes that is a lot of words  ;) ).

Here is the video link: https://youtu.be/GR8UhhNqK68

Here is the code from the first command that I showed in the video (the process of connecting is exactly the same here as in the second command that I show):
Code: [Select]
<?xml version="1.0" encoding="utf-16"?>
<!--VoxCommando 2.2.0.9-->
<command id="440" name="StartHomeAutomation" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
  <action>
    <cmdType>Launch.RawParam</cmdType>
    <params>
      <param>D:\My files\Programs\EventGhost\EventGhost.exe</param>
      <param />
      <param>True</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>Launch.CMD</cmdType>
    <params>
      <param>sc start "TelldusService"</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>PY.ExecFile</cmdType>
    <params>
      <param>D:\My files\Documets\Dokument\PythonScripts\SendToggle.py</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <event>VC.Loaded</event>
  <event>System.Resume</event>
  <event>WakeupCall</event>
  <phrase>Connect to telldus</phrase>
</command>

Here is the "intestines"  :biglaugh of the second file which is the one that is supposed to connect to the Arduino:

Code: [Select]
import clr
clr.AddReference('System')
from System import *
serialPort = IO.Ports.SerialPort("COM3")
serialPort.BaudRate = 9600
serialPort.DataBits = 8
serialPort.Open()

def arduinoWrite(str):
    serialPort.Write(str)

def CloseSerial():
    serialPort.Close()


Thanks for your time and sorry for my bad pronunciation!

Oskar
What you can´t do now... Go learn it!

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7714
  • Karma: 116
    • View Profile
    • VoxCommando
Hi Oscar,

I'm about to leave for a couple of days so I can't really dig to deeply into your problem but I can suggest a few things.

1 - these types of errors are almost always caused because the serial port is already open, either in VC or opened by another program.

2 - If you open the port in VC it will remain open until you close it.

3 - It is possible that you are trying to open the port too early when your machine is still coming out of hibernation.  If you want to run a bunch of macros when your machines wakes up I recommend that you use VC.SetEventTimer to trigger the startup process at least 60 seconds after the wakeup event.

4 - I know it seems that how you execute the python makes a difference, but I doubt that running it with an event or voice command as opposed to clicking execute in the command tree is likely to make any difference as long as you are setting up the python code correctly.

I will try to have a look when I get back but I thought I would give you some ideas to work on by yourself.  Good luck.

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7714
  • Karma: 116
    • View Profile
    • VoxCommando
In order to really help I would need to see all the commands and full understand the order in which they are being executed.

I can say that it looks like you are redefining the serial port which was already defined when the script ran on the VC.Loaded event.  As soon as you redefine the Serial port you have created a new instance of it and have lost the handle to the original object which means you can no longer close it!  (I think).

Since your script is defining a gloabal variable for the serial port, make sure that you only run that script once, and all your other scripts can continue to use it.

Another option is to create a function in which you open the serial port, write to it, and then close it immediately.  Then you should never run into any problems, unless your Arduino reboots each time the serial port is opened (some Arduduinos, like the Uno, will often do this).

Also consider that if you are using another program like EventGhost or the serial port monitor in the Arduino IDE that is trying to open the same port you will run into conflicts.  The serial port can only be opened by one program at a time.  When someone opens the port, noone else will be able to access it until the process that opened it closes it, or the serial connection is physically borken.

So you must avoid conflicts with other programs, and you must avoid conflicts within your own program as I mentioned above.
« Last Edit: March 02, 2016, 09:24:11 AM by jitterjames »

01ste02

  • $upporter
  • Jr. Member
  • *****
  • Posts: 37
  • Karma: 1
  • 16 Years old hobby-developer in home-automation
    • View Profile
    • Company website (Swedish and incomplete)
Thank you James;D

I found out after reading your post that I opened the port from two separate python scripts, which I have now merged!

Now I think it works, it was just a stupid error which anyone could have come up with. It was just one of those times where anyone but you can see the error.  :bonk

And sorry for wasting your time, I had been working on this for over a week!

Best regards and have fun on your trip!

Oskar

Ps. Now I will post the correct command group in the xml exchange folder as soon as I test it!
What you can´t do now... Go learn it!

Haddood

  • $upporter
  • Hero Member
  • *****
  • Posts: 688
  • Karma: 22
    • View Profile
Oscar,
if you ever need to open the same port by 2 programs you can use something like VSPE (http://www.eterlogic.com/Products.VSPE.html)...
I use it to access XAP800 audiomixer serial port by VC and the software supplied by the manufacturer...
When Voice command gets tough, use hand gestures

01ste02

  • $upporter
  • Jr. Member
  • *****
  • Posts: 37
  • Karma: 1
  • 16 Years old hobby-developer in home-automation
    • View Profile
    • Company website (Swedish and incomplete)
Oscar,
if you ever need to open the same port by 2 programs you can use something like VSPE (http://www.eterlogic.com/Products.VSPE.html)...
I use it to access XAP800 audiomixer serial port by VC and the software supplied by the manufacturer...

Thank you Sir!

It will be useful to me some day, but not right now. I have an task planned which requires just that!

It was just a simple question of merging the two scripts together (I hope, testing in five minutes).

Thanks anyway

Oskar
What you can´t do now... Go learn it!

01ste02

  • $upporter
  • Jr. Member
  • *****
  • Posts: 37
  • Karma: 1
  • 16 Years old hobby-developer in home-automation
    • View Profile
    • Company website (Swedish and incomplete)
Sorry, it doesn't work! I will post the code here as soon as I solve it.

Btw, that part I could use some help on that part!

What I think that the problem is is that Vox doesn't get admin rights when the computer boots from hibernate although it had admin rights before the hibernate.

I don't know how to automatically give it admin rights without a popup as soon as the computer boots from hibernate, can someone teach me? Preferably without regedit...

Thanks

Oskar
What you can´t do now... Go learn it!

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7714
  • Karma: 116
    • View Profile
    • VoxCommando
If VoxCommando was launched with administrative privileges before hibernation, it should still have the same privileges after it wakes up.  ::confused

To be honest, I did not think you even needed admin rights to open a com port but I'm not really sure about this.

01ste02

  • $upporter
  • Jr. Member
  • *****
  • Posts: 37
  • Karma: 1
  • 16 Years old hobby-developer in home-automation
    • View Profile
    • Company website (Swedish and incomplete)
It gives me an error with access denied to the Com port, although I make sure to close the port before I log out, so that windows doesn't assign it to a process that is non-existent when it wakes up.

I can't figure out what it is...

I just saw that it gave me the following error (I included the successful attaching of the file which I use to interface with my Arduino first):

Code: [Select]
04/03/2016 22:38:05 721 Action:  PY.ExecFile - D:\My files\Programs\VoxCommando\Scripts\Arduino.py
04/03/2016 22:38:05 721 [action] PY.ExecFile:D:\My files\Programs\VoxCommando\Scripts\Arduino.py

04/03/2016 22:38:05 725 Action INFO: code OK, no result
04/03/2016 22:38:05 725 action repeat set to: 1


Error:
Code: [Select]
04/03/2016 22:38:05 725 Action:  PY.ExecString - OpenSerial()
04/03/2016 22:38:05 725 [action] PY.ExecString:OpenSerial()

04/03/2016 22:38:05 814 [plugin] Python Error:Line: 16 >>
SystemError: Access to the port 'COM3' is denied.

04/03/2016 22:38:05 949 [plugin] System.UnauthorizedAccessException: Access to the port 'COM3' is denied.
   at System.IO.Ports.InternalResources.WinIOError(Int32 errorCode, String str)
   at System.IO.Ports.SerialStream..ctor(String portName, Int32 baudRate, Parity parity, Int32 dataBits, StopBits stopBits, Int32 readTimeout, Int32 writeTimeout, Handshake handshake, Boolean dtrEnable, Boolean rtsEnable, Boolean discardNull, Byte parityReplace)
   at System.IO.Ports.SerialPort.Open()
   at Microsoft.Scripting.Interpreter.ActionCallInstruction`1.Run(InterpretedFrame frame)
   at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
   at Microsoft.Scripting.Interpreter.LightLambda.Run3[T0,T1,T2,TRet](T0 arg0, T1 arg1, T2 arg2)
   at System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite site, T0 arg0, T1 arg1)
   at Microsoft.Scripting.Interpreter.DynamicInstruction`3.Run(InterpretedFrame frame)
   at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
   at Microsoft.Scripting.Interpreter.LightLambda.Run1[T0,TRet](T0 arg0)
   at IronPython.Compiler.PythonCallTargets.OriginalCallTarget0(PythonFunction function)
   at IronPython.Runtime.FunctionCaller.Call0(CallSite site, CodeContext context, Object func)
   at System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite site, T0 arg0, T1 arg1)
   at Microsoft.Scripting.Interpreter.DynamicInstruction`3.Run(InterpretedFrame frame)
   at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
   at Microsoft.Scripting.Interpreter.LightLambda.Run2[T0,T1,TRet](T0 arg0, T1 arg1)
   at IronPython.Compiler.PythonScriptCode.RunWorker(CodeContext ctx)
   at IronPython.Compiler.PythonScriptCode.Run(Scope scope)
   at IronPython.Compiler.RuntimeScriptCode.InvokeTarget(Scope scope)
   at IronPython.Compiler.RuntimeScriptCode.Run(Scope scope)
   at Microsoft.Scripting.Hosting.CompiledCode.Execute(ScriptScope scope)
   at vcPlugin.iPy.execString(String strCode)
04/03/2016 22:38:05 950 Action ERROR: Line: 16 >>
SystemError: Access to the port 'COM3' is denied.


BUT when I use my voice to first close the com port:

Code: [Select]
04/03/2016 22:38:34 384 guessed text:Close ?? (Kodi Simple actions)
04/03/2016 22:38:34 632 guessed text:Close com ?? (Startup)
04/03/2016 22:38:34 948 Something was recognized
04/03/2016 22:38:34 948 Rulename: root # Semantics: 1
04/03/2016 22:38:34 948 Group: Startup Speech: Close com
04/03/2016 22:38:34 948 semanticID: 529
04/03/2016 22:38:34 948 kvp: command | 529
04/03/2016 22:38:34 949 semanticID: 529
04/03/2016 22:38:34 949 kvp: command | 529
04/03/2016 22:38:34 949 alternate:Close com
04/03/2016 22:38:34 963 doCommand:Close Com3
04/03/2016 22:38:34 963 action repeat set to: 1
04/03/2016 22:38:34 963 Action:  PY.ExecString - CloseSerial()
04/03/2016 22:38:34 963 [action] PY.ExecString:CloseSerial()

04/03/2016 22:38:34 964 Action INFO: code OK, no result

And then open it again:
Code: [Select]
04/03/2016 22:38:38 205 guessed text:open com ?? (Startup)
04/03/2016 22:38:38 509 Something was recognized
04/03/2016 22:38:38 509 Rulename: root # Semantics: 1
04/03/2016 22:38:38 509 Group: Startup Speech: open com
04/03/2016 22:38:38 509 semanticID: 485
04/03/2016 22:38:38 510 kvp: command | 485
04/03/2016 22:38:38 510 semanticID: 485
04/03/2016 22:38:38 510 kvp: command | 485
04/03/2016 22:38:38 510 alternate:open com
04/03/2016 22:38:38 515 doCommand:Open Com3
04/03/2016 22:38:38 515 [plugin] Sending json request:
04/03/2016 22:38:38 515 action repeat set to: 1
04/03/2016 22:38:38 515 [plugin] {"jsonrpc": "2.0", "method": "GUI.ShowNotification", "params":{"title":"open com (70.9)","message":"(1 Open Com3) "},"id": "0"}
04/03/2016 22:38:38 515 Action:  PY.ExecString - OpenSerial()
04/03/2016 22:38:38 515 [action] PY.ExecString:OpenSerial()

04/03/2016 22:38:38 519 Action INFO: code OK, no result

It works! If only it would work this well to do the exact same thing in the macro...  :bonk

I have a weekend now, and what are weekends for (for pupils) but to have free-time... Another programming night! Yay!  :biglaugh

Thanks for all your time Almighty Vox-Meister (James)!  ;D

Oskar

P.S I will test this tonight (now for me) and if it doesn't work I might ask for help here.


What you can´t do now... Go learn it!

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7714
  • Karma: 116
    • View Profile
    • VoxCommando
I'm sure I could help you if I could see everything that is actually happening but it is too difficult to really understand everything that you are doing, and in what order.

I also don't really understand what you are doing with hibernation or why.  Why log out before hibernating?  It seems to defeat the purpose.  At that point you might as well just shut down the machine.  Personally I don't know why anyone uses hibernation unless they have a laptop, but that is another matter.

If you would like to use TeamViewer to look at your problem together I would be happy to try.

I can probably make myself available to you tomorrow at some point.  For today, I think it is too late.

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7714
  • Karma: 116
    • View Profile
    • VoxCommando
I also don't understand why you need to close the port at all.

The way I see it you should do one of the following things (not both).

Option A:  Open the port and keep it open, never close it.  Use it whenever you want but be sure you don't attempt to open it twice.

Option B: Any time you want to use the serial port, Open it, write to it, and then close it.

Sometimes Option B is not really an option for some reason, like maybe you want to listen on the serial port for another device to send you data.  Then choose option A.

In order to close a serial port you must have a handle to the original serial port object that was used to open it.  Also, it is possible that closing a serial port and then trying to open it again too quickly might cause a problem, but I don't understand why one would close it with the intention of just opening it up again immediately.

01ste02

  • $upporter
  • Jr. Member
  • *****
  • Posts: 37
  • Karma: 1
  • 16 Years old hobby-developer in home-automation
    • View Profile
    • Company website (Swedish and incomplete)
I'm sure I could help you if I could see everything that is actually happening but it is too difficult to really understand everything that you are doing, and in what order.

I also don't really understand what you are doing with hibernation or why.  Why log out before hibernating?  It seems to defeat the purpose.  At that point you might as well just shut down the machine.  Personally I don't know why anyone uses hibernation unless they have a laptop, but that is another matter.

If you would like to use TeamViewer to look at your problem together I would be happy to try.

I can probably make myself available to you tomorrow at some point.  For today, I think it is too late.

I am sorry, I didn't mean to say that I logged out. What I meant to say was that I close the com before hibernating. Since I have an Arduino Uno it takes 30 seconds each time I re-open the serial port, so option B is out of the question. Option A I have tried, but if I don't close the port before hibernation I get an error with access denied to the COM-port. The second reason to why I have to close the port is that it won't work (access denied) at first after hibernation, but when I close it, and then open it it works.

Also, I just found out that what you said about admin-rights and hibernation was right. It was just a speculation from my side...

I would perhaps like to use teamviewer (I will see if I can tomorrow, my brother has a birthday party then). Whatever the outcome I thank you for the offer. If I can it can be anytime between 11-~17:00 Stockholm time, but if I can you can decide when (based upon your time zone).

By the way... Can we instead use skype screen-sharing if I can? I think that my parents won't allow me to use team-viewer with someone that the haven't met physically... And if I don't obey them they will take my computer away!  :'(

I can't believe that I haven't posted my xml yet! It will be included here, with the windows sceduler task to wake the computer, and the EventGhost side of things. I will also include the interface script for Arduino.

Oskar
« Last Edit: March 04, 2016, 06:49:48 PM by 01ste02 »
What you can´t do now... Go learn it!

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7714
  • Karma: 116
    • View Profile
    • VoxCommando
Thanks.  Having everything will make it much easier to figure out what is going on.

I have downloaded all your files so if you are at all concerned about something that you left in your voicecommands.xml that might give away too much personal or security information, please delete it from your post.

I will look at this tonight.  Maybe I will see the problem.

I think it is 6 hours later for you than for me so 9:00 AM here would be 15:00 for you and that is a good time.

But 16:00 (your time) would be OK for me too.

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7714
  • Karma: 116
    • View Profile
    • VoxCommando
I think I can see the problem though.

You are using PY.ExecFile to load Arduino.py many, many times in your tree.  It is in multiple commands and each of those can be triggered by multiple events.

You should only ever load this python script one time during the entire time that VC is open.  Make sure this python code is only loaded and executed one single time in a command that is triggered by the VC.Loaded event and I think all your problems will go away.

01ste02

  • $upporter
  • Jr. Member
  • *****
  • Posts: 37
  • Karma: 1
  • 16 Years old hobby-developer in home-automation
    • View Profile
    • Company website (Swedish and incomplete)
I think I can see the problem though.

You are using PY.ExecFile to load Arduino.py many, many times in your tree.  It is in multiple commands and each of those can be triggered by multiple events.

You should only ever load this python script one time during the entire time that VC is open.  Make sure this python code is only loaded and executed one single time in a command that is triggered by the VC.Loaded event and I think all your problems will go away.

Thanks James!

I will try that, but that is because VC doesn't generate a VC.Loaded event after hibernation, so that requires me to initialize the script multiple times (whenever it is needed) so that it is always loaded. Since it doesn't open the com port in the script, and if I try to initialize it two or more times it just says that it is already loaded.. Will it cause an issue?

I will have to check with my parents tomorrow, but if it's fine to do it (over Skype?) 15:00-16:00 is a good time for me.

Thanks for letting me know that you got all the files so that I could delete them from the post!

Oskar
What you can´t do now... Go learn it!