Hi Velleman,
I have the K8090 Relay Controller and like it very much. It’s a little overkill for my app (I’m using it to control all the lights in my fancy new PC) but otherwise very useful. Anyway, here’s my question:
Would it be possible to get the source code for the Velleman.Kits.dll assembly.
I’m a software engineer, very proficient in .NET and a strong electronics hardware background and I think this would help me more quickly understand the nuts and bolts of operating the K8090.
Here’s the source code for the Velleman.Kits assembly
velleman.eu/downloads/files/ … DotNet.zip
It uses the native K8090 DLL to communicate with the board, but in your case you could easily write something that simply uses the .NET SerialPort class instead, which would be a better solution since using unmanaged code is generally not recommended. We could not do that because we needed to demonstrate how to use the native DLL. Just review the protocol to know what to send and what to expect.
How does the current solution work?
The native DLL uses a window handle to send asynchronous events (in the form of windows messages) back to an application when a packet is received. So what the .NET class does is create a message-only window which it passes to the native DLL to be able to capture those events. This solution also solves threading issues, because the native DLL uses a separate reader thread, and since the message will be received in the thread that created the window, this problem automagically solves itself.
Thank you very much! This is just what I needed. It clears up everything but the bottom layer of the DLL itself and, between your code and your explanation, I think I can figure that out from here.
I agree with you that it would be nice to have a purely .NET solution. I’ll take a look at the SerialPort class and modify Velleman.Kits to use it. when I get it working, I’ll post it back here.
I decided to take a slightly different tack. Instead of modifying Velleman.Kits, I wrote my app. (K8090control) from the ground up using what I learned from your Velleman.Kits code (and plagiarizing liberally from your structure, code and comments, hope that’s OK).
You can find the source code for K8090Control here (you’ll need Visual Studio 2010 to build it):
https://bitbucket.org/ByteMeister/k8090.net
Best Regards, and thanks again.
Brief Description:
Currently there are 3 projects in the K8090.NET solution:
- Project K8090
K8090Board - Encapsulates the K8090 board itself.
All commands in the K8090 Protocol Manual are implemented.
K8090Command - Abstract layer used to encode and decode K8090 data packets
to/from the serial port.
K8090EventArgs - Defines the CommandReceived serial port event and its arguments.
- Project K8090ChannelUserControl
K8090UserControl - User interface for a single relay channel on the K8090 board.
Issues user-initiated Commands to the main UI and displays
status from the main UI.
- Project K8090control
MainForm - The top level user interface for the K8090Board class.
Sends and receives commands to/from the K8090 board.
Acts as conduit between K8090Board and K8090UserControl instances.
It’s Not Quite Done Yet - - -
Known Issues:
- The DateTimePickers showing the timer delays don’t display the correct value.
Entering a new value works correctly.
- The “Send Command” button is hard coded to some timer delay experiments.
Trying to figure out why the DateTimePickers aren’t working correctly.
- Appologies for the odd coloring. I’m trying to figure out how to get the ToolStrips to behave.
Future Enhancements:
- Fix Send Command to allow user to send low level command to board.
Use a new ToolBar to display this feature.
- Add a parser to allow user to enter command textually (using same format as log output pane).
- Add ability to execute commands read from a file.
Provide some simple additional sequencing commands (command rate, nop command, loop structure).