Sunday, 3 February 2013

Macro actions (mouse and keyboard) with Delphi

I know this could be an old topic, but I find really useful to know how to send the key strokes or how to simulate the mouse click using our favourite language: Delphi. It's for this, that I have create a small open source project where you can find one of my latest tools "thundax macro actions". In here you will be able to add a sequence of actions e.g move the mouse to a particular position, perform right click or left click and type any kind of message or just press a special key like CONTROL or F1, etc. to automate repetitive tasks or actions that you usually perform and that you need to do as quick as possible. As I always automate everything, it was a really nice idea to come up with this solution and it is quite pleasant to see it working for you. All the source code is available and it is free for anybody to inspect, comment and give suggestions to improve this little tool. I have used the tool to perform a series of operations without me interacting and it saved me loads of time.

Imagine that you need to go through a text where you need to add an extra character or something which would be really tedious to perform manually. With this stand-alone tool, you will be able to perform the same operation with just defining the list of actions to execute and off you go.

The code is really easy to understand and the way to send the key strokes or to perform the left/right click of the mouse are really easy to do. You'll find hundreds of examples on the net:

Here is the tool:

Download it from the following link:
There are still loads of things to do to complete the tool, but at least there is a working solution which can now be used.

Related links:

Monday, 14 January 2013

Using Quick Sequence Diagram Editor (sdedit) in your Delphi applications

My first article of the year is about Quick Sequence Diagram Editor (sdedit), a tool for creating UML sequence diagrams from textual descriptions of objects and messages that follow a really easy syntax. The ones who follow my blog will realise that I love logging details for my applications and with this component you will be able to create a nice sequence diagram from any of your real business scenarios. I have been dealing lately with loads of different multi-threaded applications and it was when doing some of my homework for Uni when I found this marvellous gem.
I have written a small and quite straight-forward wrapper in Delphi which will help you to generate the ".sdx" file and run the converter calling the library via java command. All the source code and examples can be found in my personal repository on Google code: thundax-delphi-personal-repository where I keep all my tests and things I want to try out.
With few easy callings, you can instantiate the TUML class and use "start" and "call" methods to generate things like this:

More complex example:


It is really useful when doing reports or to display any of your business scenarios in a nice way. One of my tasks was to create a small application which would send messages across different instances in a supercomputer and this is the best way I found to really present what was going on in there. You can generate huge diagrams and sdedit will cope with it.

Here is the piece of code for the wrapper:
And this is a more realistic approach, where we can have for example 3 different threads which will perform different operations at a different times. All of them are asynchronous and they use the TUML class to show how long every thread took to finish its processing.

Example:

A more realistic approach (Output):

I hope you find this article interesting enough to catch you attention as it is always good when finding tools like this an that are easy enough to integrate with any language and with great results.

Don't forget to leave your comment.

Jordi Corbilla

Thursday, 13 December 2012

Capturing console output with Delphi 2010/XE (revised)

Following my previous post (Capturing console output with Delphi 2010/XE) and with all the great comments received on it, I have decided to publish the new solution provided by Lübbe Onken which solves the hanging issue when capturing the output for different kind of commands like ping, netstat, etc. The problem occurs on the last ReadFile which this solution will fix.
Here I'm summarizing Lübbe Onken comments on this issue:
"The current implementation assumes that if the external process is not finished yet, there must be something available to be read from the read pipe. This is not necessarily the case. If we use PeekNamedPipe to check for available data before entering the internal repeat loop, everything is fine.
I also put the CloseHandle into try ... finally and moved Application.ProcessMessages behind the internal read loop, because IMHO the screen update is better handled after processing the callback than before. But this is just cosmetic."

Here you can find the source code:


usage:

I want to say thanks to everyone who spend time looking at this issue and for making the community work and grow.
Jordi

Monday, 6 August 2012

Rpi and GPIO testing

In this article I'm showing my progress with the RPi using the GPIO. There are lots of interesting articles where people is doing the same, but you won't get the same feeling that I have until you test it by yourself. This application processor board is extremely delicate and you need the get used to its I/O, typical voltage values (3.3V), maximum current (8-11mA), etc. Few basic things that will help you not to burn the RPi (connect resistors after every LED, etc). My example is quite simple but with academical purposes and I'm sure it will inspire others. I'm using the slice of a pi extension board where you can easily get the connectors for GP0-GP7 outputs and lit some LED's programmatically.

Material (apart from your RPi):


First thing is to correctly identify the GP Inputs/Outputs from the Slice of Pi (GP0 to GP7 pins). Here are my findings and the correct pin numeration:
GPIO     Slice of Pi
Pin 11   GP0
Pin 12   GP1
Pin 13   GP2
Pin 15   GP3
Pin 16   GP4
Pin 18   GP5
Pin 22   GP6
Pin 07   GP7

As you can see, they are not in order, so you need to spend time looking for the right pins. I still need to identify all the other pins but I'll get to it.

The following code is just lighting up 8 LED's using 8 GPIO pins as outputs. Each pin is connected to a 220 ohm resistance plus a red LED and all terminations to GND.

Source code:


Example with two LED's:

Here is the video displaying the results:


Keep playing!.

Sunday, 29 July 2012

Raspberry Pi...the basics

After playing for a day with my Raspberry Pi, here I'm compiling a list of tools that would help you setting RPi up correctly. As I'm testing everything under Python and I want to control it using my laptop (Windows 7), I need different ways to be more productive and faster when developing on it. In my case, I'll need a Python editor like geany, GPIO library and remote desktop using Xming and PuTTY via SSH. As stated in my previous post I'll build a small robot using the following mechanical and electronic parts (All of them bought from HobbyTronics) expending less than £50:
Update the system first:
root@raspberrypi:~# apt-get update
Installing Geany:
root@raspberrypi:~# apt-get install python geany xterm
Downloading GPIO RPi Python from Google code:
root@raspberrypi:~# wget https://raspberry-gpio-python.googlecode.com/files/python-rpi.gpio_0.3.1a-1_armhf.deb
--2012-07-29 10:20:19--
https://raspberry-gpio-python.googlecode.com/files/python-rpi.gpio_0.3.1a-1_armhf.deb
Resolving raspberry-gpio-python.googlecode.com
(raspberry-gpio-python.googlecode.com)... 173.194.66.82,
2a00:1450:400b:c00::52
Connecting to raspberry-gpio-python.googlecode.com
(raspberry-gpio-python.googlecode.com)|173.194.66.82|:443...
connected.
HTTP request sent, awaiting response... 200 OK
Length: 10824 (11K) [application/x-debian-package]
Saving to: `python-rpi.gpio_0.3.1a-1_armhf.deb'

100%[======================================] 10,824      --.-K/s   in 0.1s

2012-07-29 10:20:27 (71.2 KB/s) - `python-rpi.gpio_0.3.1a-1_armhf.deb'
saved [10824/10824]
Installing the package GPIO RPi:
root@raspberrypi:~# sudo dpkg -i
python-rpi.gpio_0.3.1a-1_armhf.debSelecting previously unselected
package python-rpi.gpio.
(Reading database ... 54876 files and directories currently installed.)
Unpacking python-rpi.gpio (from python-rpi.gpio_0.3.1a-1_armhf.deb) ...
Setting up python-rpi.gpio (0.3.1a-1) ...
Testing the GPIO Rpi library:
Just open Geany and paste the following source code:

import RPi.GPIO as GPIO
import time

GPIO.setmode(GPIO.BOARD)

GPIO.setup(11, GPIO.IN)
GPIO.setup(12, GPIO.OUT)

#set up output 12 as true.

GPIO.output(12, GPIO.HIGH)

while True:
        time.sleep(1)
        input_11 = GPIO.input(11)
        print "%s %r" % ("Input 11 value is", input_11)
        time.sleep(1)

Compile it and run it. It should display the value of Pin 11. If you can change the state of that input, the display will show the change.

Starting up the SSH server:
root@raspberrypi:~# service ssh start

Download PuTTY and Xming and install them:
Once installed, run PuTTY and under Session options, use the IP of the RPi. (to get the IP just run the ifconfig command):

And enable the option X11 forwarding under connection options:

Once done, open the connection and use your credential to login (by default user: pi password: raspberry).

As soon as you are in, type startlxde and Xming will take over and it will display the RPi desktop on your local machine.


Check out the parameters for Xming as the short-cut should call: "...Xming.exe" -clipboard -rootless.

Related links: