This project is a Node.js class designed to interface with rigctld
, the Hamlib TCP server for controlling amateur radio transceivers.
- TCP connection to
rigctld
. - Command queuing mechanism to handle sequential commands.
- Support for various rigctld commands (
get_freq
,set_freq
,get_mode
,set_mode
,get_level
,set_level
, etc.). - Event emitters for connection status (
connect
,end
,close
,error
) and successful dump state parsing (dumpStateParsed
).
npm install netrigctl-node
Then, in your code:
const { RigClient } = require('netrigctl-node'); // Adjust the path as needed
Make sure you have rigctld
running and accessible from the host where your Node.js application is running.
-
Instantiate the client:
const rigClient = new RigClient('your_rigctld_host', 4532); // Replace with your host and port
-
Set up event listeners:
Listen for the
dumpStateParsed
event before sending commands that rely on rig capabilities.rigClient.on('dumpStateParsed', async (dumpState) => { //console.log('Dump State Parsing Complete:', dumpState); // Now you can access and use the parsed data in the dumpState object // e.g., console.log(dumpState.rxRanges); try { const freq = await rigClient.get_freq(); console.log('Current Frequency:', freq); const pttStatus = await rigClient.get_ptt(); console.log('Current PTT Status:', pttStatus); await rigClient.set_freq(14270000); console.log('Set frequency to 14.27 MHz'); const newFreq = await rigClient.get_freq(); console.log('New Frequency:', newFreq); await rigClient.set_mode('USB', 3000); console.log('Set mode to USB 3000'); const { mode, passband } = await rigClient.get_mode(); console.log('Current Mode:', mode, 'Passband:', passband); const nr = await rigClient.get_level('NR'); console.log('Current NR:', nr); } catch (error) { console.error('Command execution error:', error); } finally { rigClient.disconnect(); // Disconnect when done } }); rigClient.on('error', (err) => { console.error('RigClient Error:', err); }); rigClient.on('close', (hadError) => { console.log('RigClient connection closed.'); });
-
Connect to rigctld:
rigClient.connect() .then(() => console.log('Connected to rigctld')) .catch(err => console.error('Connection failed:', err));
-
Disconnect:
rigClient.disconnect();
Commands queued via queueCommand
have a default timeout of 10 seconds. If a response is not received within this time, the command's Promise will be rejected with a timeout error. You can specify a different timeout when calling queueCommand
(although the public methods like get_freq
do not currently expose this option, it's available internally).
The RigClient
automatically parses the \dump_state
output into a structured object available via rigClient.getDumpStateData()
after the dumpStateParsed
event. This data includes supported frequency ranges, modes, filters, and capability bitmasks, which are used internally for the checkCapability
method.
Errors (connection errors, rigctld errors, command timeouts) are emitted via the 'error'
event and also cause the specific command's Promise to be rejected.