Notice: This forum has been recovered from an old backup, so some content, links, and dates may be outdated. The forum is currently read-only while we restore sign-in and registration functionality. Details

If you find this forum valuable and would like to help keep it online, donations to help cover hosting and domain costs are greatly appreciated, but never expected. You can support the forum through Buy Me a Coffee or Ko-fi. Thank you for helping preserve the EventGhost community.

Drops on reading from serial port

If you have a question or need help, this is the place to be.
User avatar
kgschlosser
Site Admin
Posts: 5190
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: Drops on reading from serial port

Post by kgschlosser »

ok i pretty much re wrote the whole plugin. it compiles and attaches to the com port as well no logs in the debug log file. it closes nice and clean.

and i am using win32api for the serial port not the eventghost serial thread.

it runs in it's own thread. i i did a subclass of threading and went that route.

made it a little longer code wise. but in all reality it may not be. because there is a huge amount of code in the eg serial thread about 600 lines or so. i bypassed that and loaded the win32api just like the serial thread but i didn't set 3/4 of the settings the serial thread does.

i am thinking it may have been one of those settings boogered it up

i also changed the the spinner in the config panel. i didn't like the say it used an int for the spin and then did some math to convert it to milliseconds.

so i just changed it so the spinner displays in hundredths of a second. with the max being a 1.0 and the bottom being .01 or some such

i also changed the description to include the information about the spinner being that way. it's a little easier to understand.

again i cannot test this thing so if you wouldn't mind posting any traceback information you get that would be helpful. i think i have put the end enduring event function in the right place. but not to sure on that one because i have never messed with it.


i also added a control to the plugin config to change the prefix of an event.

i am not sure if i have set it to the one that was set before. so you may need to put this plugin in and change it to what you had before so you don't have to change all of the events in your macros.

this plugin is drop and play you shouldn't have to remove the old plugin from the EG tree

i would make a backup of the original onto your desktop. and then replace the __init__.py file in the x10 mouse folder with the new one.

and then restart EG

see if this works now and possibly solved your problem.

I hope it does well.

K
If you like the work I have been doing then feel free to Image
igvk
Experienced User
Posts: 60
Joined: Wed Jan 09, 2013 7:22 pm

Re: Drops on reading from serial port

Post by igvk »

Thank you very much for the code of the plugin!
I'll put it to the test and return with my results.
igvk
Experienced User
Posts: 60
Joined: Wed Jan 09, 2013 7:22 pm

Re: Drops on reading from serial port

Post by igvk »

While testing the plugin:
I get the following error when a button is pressed:

Code: Select all

02:13:11         Exception in thread Thread-6:
02:13:11         Traceback (most recent call last):
02:13:11           File "threading.pyc", line 532, in __bootstrap_inner
02:13:11           File "C:\Program Files (x86)\EventGhost\plugins\X10Mouse\__init__.py", line 129, in run
02:13:11             reply = self.plugin.Decode(ord(buf))
02:13:11         AttributeError: 'X10Mouse' object has no attribute 'Decode'
02:13:11         
And no events are fired.
User avatar
kgschlosser
Site Admin
Posts: 5190
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: Drops on reading from serial port

Post by kgschlosser »

Ooooops I forgot to remove the plugin from that command. I am not at home now but if you look in the unit file and either go to line 129, or if you don't have an editor that shows line numbers open the file in a text editor look for a class called Server and a def run just under the class Server and you will see that exact line

Code: Select all

reply = self.plugin.Decode(ord(buf))
Change that line to this

Code: Select all

reply = self.Decode(ord(buf))
It's good that it is receive the serial packets so this error was happening when it was passing the packet to get decoded I was going to set the plugin up a little different and I forgot to remove the plugin from the command.
If you like the work I have been doing then feel free to Image
User avatar
kgschlosser
Site Admin
Posts: 5190
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: Drops on reading from serial port

Post by kgschlosser »

Here I downloaded an editor on my phone and changed the line
If you like the work I have been doing then feel free to Image
igvk
Experienced User
Posts: 60
Joined: Wed Jan 09, 2013 7:22 pm

Re: Drops on reading from serial port

Post by igvk »

Now it's another error:

Code: Select all

03:06:55   Exception in thread Thread-6:
03:06:55   Traceback (most recent call last):
03:06:55     File "threading.pyc", line 532, in __bootstrap_inner
03:06:55     File "C:\Program Files (x86)\EventGhost\plugins\X10Mouse\__init__.py", line 129, in run
03:06:55       reply = self.Decode(ord(buf))
03:06:55   TypeError: ord() expected string of length 1, but buffer found
I guess this isn't the code path you are able to debug?
I tried to change buf to buf[0] - it worked. The events X10-Mouse.<Button> are fired - but only once for each button, the next press of the same button is ignored.
Nevertheless, it's functioning, although I will experiment more (and will certainly change the prefix to nothing).
(Don't like the part with buf[0], actually.)
P.S. I could change the code myself if all that was needed was to remove ".plugin", but I have little knowledge on the internals of EG (and don't use python, too).
User avatar
kgschlosser
Site Admin
Posts: 5190
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: Drops on reading from serial port

Post by kgschlosser »

events for each press. I stated earlier I have not messes around with the enduring events so I may have to change a couple of things. But the buf[0] is because of how the winapi returns the data along with any other information/errors. So it puts it into a list and you are correct about having the [0] on there.

The rest is pretty simple to take care of. I will do so in about 30 minutes when I get home and it should take me maybe 3 minutes to correct the triggering of the event. And I will also have it spit out the hex in the EG log to make sure all the data is correct as well.
If you like the work I have been doing then feel free to Image
User avatar
kgschlosser
Site Admin
Posts: 5190
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: Drops on reading from serial port

Post by kgschlosser »

ok this is going to take me a little bit longer to modify because i am not sure how you want it done.

i can either set it so that if you press the same button multiple times in succession or hold the button down what it will do is it will only fire one event. for all button presses. the purpose to this is so you can set a looping python script to fire the save action over and over again until the event reports back that it has ended. there is a 0.2 second timer for this. or the button press changes.

i can also set it up so that if you fire presses in succession it will for an event for each press or each code received and you can have the event just call the same action over and over again.

the second way is alot easier to work on the user end if you aren't familiar with python code. i do know you can set this loop from the enduring event into place using actions that are defined but i do not know how. so what i will do is code the thing to show an event for each press..

the original plugin was set up to use the enduring but what i am going to do is add an option to the plugin config to let you select the method.

and the original author did some repeat code because of the reply thing is already done in the parent class eg.RawReceiverPlugin and it also ends the event when needed. so there is a lot of code i am going to be able to remove.

so give me more like 30 minutes
If you like the work I have been doing then feel free to Image
User avatar
kgschlosser
Site Admin
Posts: 5190
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: Drops on reading from serial port

Post by kgschlosser »

ok here it is i changed some things about that i didn't like how i did them before. but again it compiles and closes clean no errors.

let me know if there are any errors.

i added that dialog to select to use enduring or not. it is defaulted to not using it.

K
If you like the work I have been doing then feel free to Image
igvk
Experienced User
Posts: 60
Joined: Wed Jan 09, 2013 7:22 pm

Re: Drops on reading from serial port

Post by igvk »

This version of plugin also needed removal of ".plugin" form the line with "self.plugin.Decode".
It works now with sending event for each press of the same button, but I when I tried to configure and set the "Enduring event" option, there was the following error:

Code: Select all

<class 'eg.Classes.ExceptionsProvider.SubSerialOpenFailed'>
After restart, the option was active and it now ignores successive presses of the same button. But it also ignores long button press, that should actually allow repeated events.
The original plugin had this 145 ms default timeout to not fire an event twice when one press of a button sent multiple events due to "chattering". But it allowed multiple events when the button was pressed and was automatically sending repeated presses.

I am also unable to edit the timeout in the Configure dialog (it simply doesn't allow me to change the value), so I left it set to 0.10.
igvk
Experienced User
Posts: 60
Joined: Wed Jan 09, 2013 7:22 pm

Re: Drops on reading from serial port

Post by igvk »

I also suggest removing the prefix by default, so that it sends simple events like "Play" and not "X10-Mouse.Play".
Changing the prefix to empty string still sends ".Play" - this is undesirable.
Edit: this suggestion seems wrong from my side, I take it back for now.
Only suggest to change the prefix to "X10Mouse" for compatibility.
Last edited by igvk on Sun Jun 12, 2016 3:31 pm, edited 3 times in total.
User avatar
kgschlosser
Site Admin
Posts: 5190
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: Drops on reading from serial port

Post by kgschlosser »

igvk wrote:This version of plugin also needed removal of ".plugin" form the line with "self.plugin.Decode".
i can't believe i forgot to remove that .plugin still LOL
igvk wrote:It works now with sending event for each press of the same button, but I when I tried to configure and set the "Enduring event" option, there was the following error:

Code: Select all

<class 'eg.Classes.ExceptionsProvider.SubSerialOpenFailed'>
After restart, the option was active and it now ignores successive presses of the same button. But it also ignores long button press, that should actually allow repeated events.
the enduring event doesn't ignore anything. its how the enduring event works. you have to poll the event to see if it is still active this is for generating a loop instead of having multiple events show up in the log. and i will fix the error for the change to enduring i have to backup the override first and put it back into place upon stopping the plugin
igvk wrote:The original plugin had this 145 ms default timeout to not fire an event twice when one press of a button sent multiple events due to "chattering". But it allowed multiple events when the button was pressed and was automatically sending repeated presses.

I am also unable to edit the timeout in the Configure dialog (it simply doesn't allow me to change the value), so I left it set to 0.10.
not sure what is going on with the timeout i will take a look
If you like the work I have been doing then feel free to Image
igvk
Experienced User
Posts: 60
Joined: Wed Jan 09, 2013 7:22 pm

Re: Drops on reading from serial port

Post by igvk »

As for enduring event, your implementation is correct, I tested it.
It correctly handles repeated sequences from buttons. At first I didn't understand that.
I also suggest that when "Enduring event" is off, there should be protection from "button chatter", meaning no repeated events during timeout (0.1s).
User avatar
kgschlosser
Site Admin
Posts: 5190
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: Drops on reading from serial port

Post by kgschlosser »

i have modified the plugin. and i forgot to mention eventghost is designed around a prefix.suffix format. it has to have a prefix.suffix.

if i don't set the prefix it will default to "Main"

and if i don't set the suffix i get a traceback

Code: Select all

09:40:56      Traceback (most recent call last):
09:40:56        Python script "15", line 1, in <module>
09:40:56          eg.TriggerEvent(prefix="testprefix")
09:40:56      TypeError: TriggerEvent() takes at least 2 non-keyword arguments (1 given)
so there is no way around this unless i override the builtin TriggerEvent and the built in TriggerEnduringEvent

which i can do but is some work.

everything else seems to be working.

the only thing i am not sure of is the timeout. i may have to set a threaded timer for that instead of passing the timeout for the serial to handle

this is going to require more testing.

i do apologize for not being able to get this running 100% out of the gate. but i do not own an x-10 remote and this ends up being the process to get these sort of things going (excluding the .plugin, that's just raw stupidity on my part)

the timeout spinner was working you just couldn't see it because it's actually 3 decimal places, i had to tell the control to show all 3, never used more than 2 before so i had to do some research to find out how. but it was spinning just wasn't visible

i also added a check box to print all the bytes received and to also print out a completed command.

i set up a virtual serial port on my end and tested with the hex from previous posts and it seems to be working properly. i really can't test the timeout because i do not have a means to simulate an accidental long press on a remote or "chatter" as you call it

and i usually handle that kind of thing differently than having a user adjustable timeout because if you want to press and hold the button down those accidental long presses would be ignored because of that timeout. so something like every other command wouldn't be processed slowing the movement by 50%

normally what i do is add a timer that if the 2 press falls within the timer and is the same code it won't fire it but will reset the timer with a smaller window and it keeps doing this until the window reaches 0. and that makes sure that all the commands will come through.

and when talking in these terms we are speaking in milliseconds of time. so full speed happens in about a half of a second. this way if you want to say move the mouse across the screen it will cruise right along when wanted to. or volume up or down.

the way it was before wouldn't work that way and would skip commands. i think i would have to look at the original code again

if you would like me to implement that kind of routine let me know
Last edited by kgschlosser on Sun Jun 12, 2016 4:00 pm, edited 1 time in total.
If you like the work I have been doing then feel free to Image
User avatar
kgschlosser
Site Admin
Posts: 5190
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: Drops on reading from serial port

Post by kgschlosser »

duh, i forgot to attach the plugin
If you like the work I have been doing then feel free to Image
Post Reply