![]()
Adding an interface for the ShackLan-4 system into a logging program is a simple process using Windows messages. This method is preferred as it requires no DLL files and generates no errors if files are not found. Simply add a few variables and a message handler to build the remote control interface. Step by step instructions are listed below. Sample code is in Delphi Pascal but is easily adapted to other languages. We assume you are fluent in the language of your choice and cannot help you implement the interface into your software.
Message definitions (in hex):
01h - Get Shacklan-4 application handle
02h - Shacklan-4 handle
03h - Switch focus to logger
04h - Test connection
05h - Connection good
11h - Radio 1 band
12h - Radio 2 band
Declarations
First declare variables for the application handle of the ShackLan-4 software, Shacklan-4 message, connection timer and bands for each radio. Next add constants for the messages and connection timeout timer.
var
ShacklanHandle: THandle;
ShacklanMsg: cardinal;
ShacklanTimer: integer;
Radio1Band,
Radio2Band:
integer;
const
msgGetShacklanHandle = $01;
msgShacklanHandle = $02;
msgBringToFront = $03;
msgTestConnection = $04;
msgConnectionGood = $05;
msgRadio1Band = $11;
msgRadio2Band = $12;
ShacklanTimeout = 5;
Logger Startup
When your program is started it should first register a "shacklan4" message with the operating system. Next reset the handle for the Shacklan-4 application and the connection timer. The last step in starting is to send a broadcast message to locate the Shacklan-4 application. If it is running it send a message containing the application handle which is used in all other messages.
Sample code:
ShacklanMsg :=
RegisterWindowMessage ('shacklan4');
ShacklanHandle := 0;
ShacklanTimer := 0;
SendMessage (HWND_BROADCAST, ShacklanMsg, msgShacklanHandle, 0);
Handling messages
There are 3 messages sent from the Shacklan-4 application to your logger that you need to handle.
procedure TMsgDemo.AppMessage (var
Msg: TMsg; var Handled: Boolean);
begin
if (Msg.Hwnd = Application.Handle) then // Is
message for your logger?
begin
if Msg.Message = ShacklanMsg then // Is
message from Shacklan-4 application?
begin
case Msg.wParam of //
Message type is in WParam, data is in LParam
msgShacklanHandle: // Message containing
handle of Shacklan-4 application
begin
ShacklanHandle := Msg.LParam; // Set handle for
further messages to Shacklan-4 application
Handled :=
true;
ShacklanTimer
:= ShacklanTimeout; // Reset link timeout timer
end;
msgConnectionGood: // Message from Shacklan-4
application indicating good link
begin
Handled :=
true;
ShacklanTimer
:= ShacklanTimeout; // Reset link timeout timer
end;
msgBringToFront: // Message to set user
focus to logger
begin
SetForegroundWindow (Application.MainForm.Handle);
Handled :=
true;
end;
end;
end;
end;
inherited;
end;
Sending band information
Band information is sent in numerical format indicating the band according to the following table:
| Band # | Actual Band |
| 0 | None |
| 1 | 160M |
| 2 | 80M |
| 3 | 75M |
| 4 | 60M |
| 5 | 40M |
| 6 | 30M |
| 7 | 20M |
| 8 | 17M |
| 9 | 15M |
| 10 | 12M |
| 11 | 10M |
| 12 | 6M |
PostMessage (ShacklanHandle,
ShacklanMsg, msgRadio1Band, Radio1Band);
PostMessage (ShacklanHandle, ShacklanMsg, msgRadio2Band, Radio2Band);
Maintaining a robust connection
It is important that you have a system in place to maintain the connection even if the Shacklan-4 application is closed and restarted. This is the purpose of the timeout timer. The following sample code executes once every second.
procedure TMsgDemo.Timer1Timer
(Sender: TObject);
begin
if ShacklanHandle <> 0 then // If connection
has been established
PostMessage (ShacklanHandle, ShacklanMsg, msgConnection,
GetForegroundWindow)
else // If no connection
PostMessage (HWND_BROADCAST, ShacklanMsg, msgLoggerHandle,
Application.Handle);
if ShacklanTimer > 0 then // Decrement timeout timer.
dec (ShackLanTimer)
else
ShacklanHandle := 0; // Reset
Shacklan-4 application handle if no response for timeout period
//Send the band information every second
PostMessage (ShacklanHandle,
ShacklanMsg, msgRadio1Band, Radio1Band);
PostMessage (ShacklanHandle, ShacklanMsg, msgRadio2Band, Radio2Band);
end;