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.

[solved] KMK USB 5 Input 8 Output Channels Controller

If you have a question or need help, this is the place to be.
krambriw
Plugin Developer
Posts: 2570
Joined: Sat Jun 30, 2007 2:51 pm
Location: Stockholm, Sweden
Contact:

Re: KMK USB 5 Input 8 Output Channels Controller

Post by krambriw »

Hello Jostein,

After having some problems calling the OCX from a thread :twisted: I think I have a version that should work

To describe some typical features and the idea behind:

You can configure each input what is the normal state (0 or 1) for it

You shall create a separate on and off action for each output and put it in a macro together with events that shall trigger it

At startup the last known output status is sent to board (i.e. after power failure etc it will recover the desired states) Since the api is missing a call that gives the output states, I had to save the state to a file at stop and then I read it again at start

The plugin reads the inputs via a separate thread that is paused by a configurable time (default is 0.1 sec)

The input and output states are kept in alarm memory and output memory during runtime

Please try it with the board if it works ok

For debugging, I left the printing ON for the output list. If it works ok you can comment it out in the py code

You can use my simple xml file to test it. Just execute some macros and you should see the outputs change

Best regards, Walter


KMK.xml
(2.96 KiB) Downloaded 91 times
KMK_5I8O.zip
(82.48 KiB) Downloaded 98 times
Jostein
Experienced User
Posts: 108
Joined: Sun Feb 15, 2009 12:59 pm

Re: KMK USB 5 Input 8 Output Channels Controller

Post by Jostein »

At first i dident get any response from the card.

I fund out that by some reason when closing the port you need a smal time delay for it to work. I inserted a smal line time.sleep(0.1) everyplase you close the port. So that ypu can se the change i made i marked it with ########### input ######## over and under.

The input part then works.

The output part is not that great on the other hand.
I can run theme as i want but everytiem the "timer"(the one that prints the current status of the output and so on)
the hole board goes dark. If i then turn on or off something i get the same thing.

Hope you can understand what i mean. (tried explaning with the screanshot)
There is proparly a smal fix for it, i just cant se it.

Will try more later tonight.

Thanks.

-Jostein
Attachments
scr.JPG
KMK_5I8O.zip
Edited whit "time delay"
(82.51 KiB) Downloaded 90 times
krambriw
Plugin Developer
Posts: 2570
Joined: Sat Jun 30, 2007 2:51 pm
Location: Stockholm, Sweden
Contact:

Re: KMK USB 5 Input 8 Output Channels Controller

Post by krambriw »

Hi Jostein,

I think also this is strange, I do not see (yet) where it goes wrong in the code......

The thread that fires every five seconds is only reading the inputs...is it maybe so that we also have to set the outputs every time we read inputs? Sounds strange if this is required

Maybe you can try to modify the code if the attached version is not working better

Code: Select all

        while not stopThreadEvent.isSet():
            AxkmkusbT.port_open_close = 1
            inputs = str(AxkmkusbT.binary)
            AxkmkusbT.out = str(kmkSum)
            ########################################## input #############################################
            time.sleep(0.1)
            ########################################## input #############################################
            AxkmkusbT.port_open_close = 0
            inputList = []

I have anyway made some smaller changes and then we can take it from there. I have changed the output data type to string (str(kmkSum)) in all places where it is used. I have also modified the actions so that the kmkSum only is sent if there is a change of the data

Best regards, Walter

PS another idea I got is that we could try to change the Thread how it handles the board. Instead of opening/closing the port all the time, we could try to keep the port open until the Thread terminates
KMK_5I8O.zip
(78.26 KiB) Downloaded 89 times
Jostein
Experienced User
Posts: 108
Joined: Sun Feb 15, 2009 12:59 pm

Re: KMK USB 5 Input 8 Output Channels Controller

Post by Jostein »

Yes i was alsow thinking about opening and keeping it open until the plugin is disabled or deleted. Yes i also tried removing the output when reding from my plugin and i got the same fault then. The output needs to be sent befor closing again or it will be lost.

What writer do you use for phyton?

Tried your new plugin with the IO card. Got the same fault.
When i removed the "#" on the line AxkmkusbT.out = str(kmkSum), the first time the timer comes the output gets locked to whatever the output bit is at that time. I canot change it after the timer runs for the first time. Will try more
krambriw
Plugin Developer
Posts: 2570
Joined: Sat Jun 30, 2007 2:51 pm
Location: Stockholm, Sweden
Contact:

Re: KMK USB 5 Input 8 Output Channels Controller

Post by krambriw »

Hi Jostein,

I have re-worked the design a bit. With this new version

- all communication with the OCX is handled ONLY by the thread (earlier the actions also communicated directly with the OCX)
- I keep the port open until the thread stops (basically it will be open as long as EG and the plugin is running)

I hope that you can try it and also, if possible, play with removing all "time.sleep(0.1)" and check if it is still working ;)

(The same KMK.xml as you already have still works)

Best regards, Walter
KMK_5I8O.zip
(78.21 KiB) Downloaded 89 times
PS As editor for python I use UltraEdit32
Jostein
Experienced User
Posts: 108
Joined: Sun Feb 15, 2009 12:59 pm

Re: KMK USB 5 Input 8 Output Channels Controller

Post by Jostein »

Hi krambriw.

I have tested the modified version. When it first start the outputs get set correct. But when i do a change (turn of or on a port) i have to restart EG (Also works yust to disable plugin and enable itagain) for it to hapen.

The input part works.

Also the Loging of the outputs are not there anymore. (the print to log that came every 5 second is not there anymore).
Removed a empty line(337) and it came back.


To show the problem i aded a smal print line (line 338). "print "Output set to: ", str(kmkSum)" Se the screnshot.
Image
What i then found is that when the i turn on output 1 i get this printed to the log: [1, 0, 0, 0, 0, 0, 0, 0] when the timer comes. But the code i added gives: "Output set to: 0" instead of 1. To then get the value 1 i have to restart plugin.( Se screnshot).
Image
Attachments
__init__.py
(13.68 KiB) Downloaded 151 times
SCR of event.JPG
SCR of code.JPG
Jostein
Experienced User
Posts: 108
Joined: Sun Feb 15, 2009 12:59 pm

Re: KMK USB 5 Input 8 Output Channels Controller

Post by Jostein »

Forgot the timers. Tried removing theme but stil the same case. I dont se why they should be there anymore either as the reson for theme were to make smal delay before closing the port but now it stays open the whole time.

-Jostein
krambriw
Plugin Developer
Posts: 2570
Joined: Sat Jun 30, 2007 2:51 pm
Location: Stockholm, Sweden
Contact:

Re: KMK USB 5 Input 8 Output Channels Controller

Post by krambriw »

I'm thinking deep now, I think the problem is in front of me...looking at the syntax

I'm doing wrong when I'm comparing & copying lists (in python)

Back & forth...finally made it in a simpler way. Also added some print statements to help us debug

Attached is the version that works here now (I could see the same problems like you said)

Best regards, Walter
__init__.py
(14.41 KiB) Downloaded 134 times
Jostein
Experienced User
Posts: 108
Joined: Sun Feb 15, 2009 12:59 pm

Re: KMK USB 5 Input 8 Output Channels Controller

Post by Jostein »

Hi krambriw.

Happy to confirm that it works 100%.

I removed some of the print for the debug and changed the "Thread wait time" to 0,1. And it works.

The retriving of data from file works.
The outputs can be changed.
The switches gives events on enabled and disabled.

The only thing i now see that is remaining to make this the perfect plugin is:
  • If it could detect if the card is conected or not. (when i unplug and replug the card i can no longer recive or send comands) A way to detect this could either be the Event showing in eventhost when disconecting and conecting (Se the screnshot). Or to have it shut down when it recives nothing: "" instead of the "11111".
  • The possibility to write to more than one card. You might already have made it that way i can se that every time you write to the card you use AxkmkusbT. instead of Axkmkusb1. Is that for this reason?
None of the 2 above points are of any consern to me as i have no need for it. I only have one board and am not going to disconect it. It would be only for you if you are still conserning to buy one.

I can at least say that the card is working with the plugin. And i was very happy with the service from KMK. The I/O card comes with CD, USB cable, batery clamp to use with 9V batery instead of eliminator, also there is a extra plate under the board to protect it from "shorts" that you cant see on the photos.

Have atached version without the loging.

Thanks a lot for the plugin and for taking the time.

-Jostein
Attachments
KMK_5I8O.zip
Tested version
(82.43 KiB) Downloaded 95 times
SCR.JPG
krambriw
Plugin Developer
Posts: 2570
Joined: Sat Jun 30, 2007 2:51 pm
Location: Stockholm, Sweden
Contact:

Re: KMK USB 5 Input 8 Output Channels Controller

Post by krambriw »

Dear Jostein,

I'm happy to hear that it works that well. This is a very interesting board indeed and I plan to buy one myself. I have a couple of Velleman's k8055 as well and they are working in a similar way.

Interestingly, KMK also have other type of modules like one for measuring temperature. All are interfaced with USB and the OCX approach for programming

Anyway, this little exercise also showed the power and strength of EventGhost, especially with the plugin concept, the source is open and we can all learn from each others

Regarding your questions

1 Its a good idea and I will look into it. You can actually already today create a monitoring function by using already available plugins
- create a new macro
- drag the complete event ("System.DeviceRemoved...) to the macro
- add a suitable plugin like the email plugin
- create an action that sends an email to your mobile phone and put it in the same macro
But this doesn't solve the problem if something breaks down so I will check if I can add some better monitoring function and then create an event if the board is not responding any more that can be used as well

2 Besides that I just found a problem with it, I think this is already possible. You just add the plugin again and insert the serial number for the next board instead. It should work because each plugin handles it owns variables etc
(this is why the line "canMultiLoad = True" is in the code)

I will eventually make some "cosmetic clean up" of the code and anyway publish the first "official version" here so that everyone interested can have access to it

Also thanks for all your effort in testing & contributing with good ideas to improve functionality

Best regards, Walter
krambriw
Plugin Developer
Posts: 2570
Joined: Sat Jun 30, 2007 2:51 pm
Location: Stockholm, Sweden
Contact:

Re: KMK USB 5 Input 8 Output Channels Controller

Post by krambriw »

Hi again,

I have fixed the problem with loading multiple KMK plugins and also introduced a monitoring if the board is responding or not. Can you try it? Remove the connection to the board and it should be detected and a specific event generated, threads will be stopped and you have to restart once the boards are repaired/connected again

A more advanced handling could be that the thread goes into a slow mode and tries to find the board once it is back but this is more complex and I wonder if it is really necessary. Once you have a failure its not temporary, you will most likely have to repair/reconnect something at the site

Best regards, Walter
__init__.py
(14.7 KiB) Downloaded 145 times
Jostein
Experienced User
Posts: 108
Joined: Sun Feb 15, 2009 12:59 pm

Re: KMK USB 5 Input 8 Output Channels Controller

Post by Jostein »

Hi.
Yes i was also considering geting a temprature card.

I have tested latest release. It is not working at all.

16:43:02 KMK5I8O.The board is not responding correctly: KMSHF43V

Se the screnshot.

Instead of a secvense checking to se i the card is responding or not i tought it would be possible to disable on the disconect
and enable on the conect event:
  • 16:42:50 System.DeviceAttached [u'\\\\?\\USB#VID_0403&PID_6001#KMSHF43V#{a5dcbf10-6530-11d2-901f-00c04fb951ed}']
  • 17:00:28 System.DeviceRemoved [u'\\\\?\\USB#VID_0403&PID_6001#KMSHF43V#{a5dcbf10-6530-11d2-901f-00c04fb951ed}']
But i can se now that runing the plugin does not use any CPU power or anything so it might be just as easy to leve it on.

I agre that starting the plugin 2 times would be the best way to control a secondary card.
I dont have the possibility to test this, but there would not be a reson for it before anybody on the forum desides to by multiple cards.

-Jostein
Attachments
SCR.jpg
krambriw
Plugin Developer
Posts: 2570
Joined: Sat Jun 30, 2007 2:51 pm
Location: Stockholm, Sweden
Contact:

Re: KMK USB 5 Input 8 Output Channels Controller

Post by krambriw »

Hi, can you just test this one as well?
I'm trying to detect how the response looks like when the board is not connected (some print statements added)

BestR Walter
__init__.py
(14.77 KiB) Downloaded 116 times
Jostein
Experienced User
Posts: 108
Joined: Sun Feb 15, 2009 12:59 pm

Re: KMK USB 5 Input 8 Output Channels Controller

Post by Jostein »

Same problem.


-Jostein
Attachments
SCR.jpg
krambriw
Plugin Developer
Posts: 2570
Joined: Sat Jun 30, 2007 2:51 pm
Location: Stockholm, Sweden
Contact:

Re: KMK USB 5 Input 8 Output Channels Controller

Post by krambriw »

Sorry, I'm puzzled

Since the inputs are empty, maybe I'm asking the board too fast after opening the port
Last try for tonight, please, I have added a sleep after the opening of the port just to see if it makes any diff

BestR Walter
__init__.py
(14.79 KiB) Downloaded 117 times
Post Reply