hamlib 0.1.4 → 0.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/Readme.md CHANGED
@@ -4,6 +4,7 @@ A comprehensive Node.js wrapper for [Hamlib](https://hamlib.github.io/) - contro
4
4
 
5
5
  ## 🚀 Features
6
6
 
7
+ - **Async/Await Support**: All operations are asynchronous and non-blocking for optimal performance
7
8
  - **Built-in Methods**: Complete radio control API including memory channels, RIT/XIT, scanning, levels, functions, and more
8
9
  - **303+ Supported Radios**: Works with Yaesu, Icom, Kenwood, Elecraft, FlexRadio, and many more
9
10
  - **Multi-platform**: Pre-built binaries for Windows x64, Linux x64/ARM64, macOS ARM64
@@ -11,6 +12,25 @@ A comprehensive Node.js wrapper for [Hamlib](https://hamlib.github.io/) - contro
11
12
  - **TypeScript Support**: Full type definitions and IntelliSense
12
13
  - **Modern JavaScript**: CommonJS and ES Modules support
13
14
 
15
+ ## ⚡ Async Operations
16
+
17
+ **All radio control operations are asynchronous** to prevent blocking the Node.js event loop during I/O operations:
18
+
19
+ ```javascript
20
+ // ✅ Correct - Using async/await
21
+ await rig.setFrequency(144390000);
22
+ const frequency = await rig.getFrequency();
23
+
24
+ // ✅ Correct - Using Promises
25
+ rig.setFrequency(144390000)
26
+ .then(() => rig.getFrequency())
27
+ .then(freq => console.log('Frequency:', freq))
28
+ .catch(err => console.error('Error:', err));
29
+
30
+ // ❌ Incorrect - Operations are no longer synchronous
31
+ // rig.setFrequency(144390000); // This won't work as expected
32
+ ```
33
+
14
34
  ## 📦 Quick Start
15
35
 
16
36
  ```bash
@@ -20,25 +40,29 @@ npm install node-hamlib
20
40
  ```javascript
21
41
  const { HamLib } = require('node-hamlib');
22
42
 
23
- // Find your radio model
24
- const rigs = HamLib.getSupportedRigs();
25
- console.log('Supported radios:', rigs.length);
43
+ async function controlRadio() {
44
+ // Find your radio model
45
+ const rigs = HamLib.getSupportedRigs();
46
+ console.log('Supported radios:', rigs.length);
26
47
 
27
- // Connect to radio
28
- const rig = new HamLib(1035, '/dev/ttyUSB0'); // FT-991A
29
- rig.open();
48
+ // Connect to radio
49
+ const rig = new HamLib(1035, '/dev/ttyUSB0'); // FT-991A
50
+ await rig.open();
30
51
 
31
- // Basic control
32
- rig.setFrequency(144390000); // 144.39 MHz
33
- rig.setMode('FM');
34
- rig.setPtt(true);
52
+ // Basic control
53
+ await rig.setFrequency(144390000); // 144.39 MHz
54
+ await rig.setMode('FM');
55
+ await rig.setPtt(true);
35
56
 
36
- // Get status
37
- console.log('Frequency:', rig.getFrequency());
38
- console.log('Mode:', rig.getMode());
39
- console.log('Signal:', rig.getStrength());
57
+ // Get status
58
+ console.log('Frequency:', await rig.getFrequency());
59
+ console.log('Mode:', await rig.getMode());
60
+ console.log('Signal:', await rig.getStrength());
40
61
 
41
- rig.close();
62
+ await rig.close();
63
+ }
64
+
65
+ controlRadio().catch(console.error);
42
66
  ```
43
67
 
44
68
  ## 📡 Complete API Reference
@@ -74,9 +98,9 @@ const rig = new HamLib(1035, 'localhost:4532'); // rigctld
74
98
  #### `open()` / `close()` / `destroy()`
75
99
  Connection control
76
100
  ```javascript
77
- rig.open(); // Open connection
78
- rig.close(); // Close (can reopen)
79
- rig.destroy(); // Destroy permanently
101
+ await rig.open(); // Open connection
102
+ await rig.close(); // Close (can reopen)
103
+ await rig.destroy(); // Destroy permanently
80
104
  ```
81
105
 
82
106
  #### `getConnectionInfo()`
@@ -93,22 +117,22 @@ console.log('Status:', info.status);
93
117
  #### Frequency Control
94
118
  ```javascript
95
119
  // Set frequency (Hz)
96
- rig.setFrequency(144390000);
97
- rig.setFrequency(144390000, 'VFO-A');
120
+ await rig.setFrequency(144390000);
121
+ await rig.setFrequency(144390000, 'VFO-A');
98
122
 
99
123
  // Get frequency
100
- const freq = rig.getFrequency();
101
- const freqA = rig.getFrequency('VFO-A');
124
+ const freq = await rig.getFrequency();
125
+ const freqA = await rig.getFrequency('VFO-A');
102
126
  ```
103
127
 
104
128
  #### Mode Control
105
129
  ```javascript
106
130
  // Set mode
107
- rig.setMode('FM');
108
- rig.setMode('USB', 'wide');
131
+ await rig.setMode('FM');
132
+ await rig.setMode('USB', 'wide');
109
133
 
110
134
  // Get mode
111
- const mode = rig.getMode();
135
+ const mode = await rig.getMode();
112
136
  console.log('Mode:', mode.mode);
113
137
  console.log('Bandwidth:', mode.bandwidth);
114
138
  ```
@@ -116,22 +140,22 @@ console.log('Bandwidth:', mode.bandwidth);
116
140
  #### VFO Control
117
141
  ```javascript
118
142
  // Set VFO
119
- rig.setVfo('VFO-A');
120
- rig.setVfo('VFO-B');
143
+ await rig.setVfo('VFO-A');
144
+ await rig.setVfo('VFO-B');
121
145
 
122
146
  // Get current VFO
123
- const vfo = rig.getVfo();
147
+ const vfo = await rig.getVfo();
124
148
  ```
125
149
 
126
150
  #### PTT Control
127
151
  ```javascript
128
- rig.setPtt(true); // Transmit
129
- rig.setPtt(false); // Receive
152
+ await rig.setPtt(true); // Transmit
153
+ await rig.setPtt(false); // Receive
130
154
  ```
131
155
 
132
156
  #### Signal Monitoring
133
157
  ```javascript
134
- const strength = rig.getStrength();
158
+ const strength = await rig.getStrength();
135
159
  console.log('Signal strength:', strength);
136
160
  ```
137
161
 
@@ -284,6 +308,109 @@ rig.setAntenna(2); // Select antenna 2
284
308
  const antenna = rig.getAntenna();
285
309
  ```
286
310
 
311
+ ### ⚙️ Serial Port Configuration
312
+
313
+ #### `getSupportedSerialConfigs()`
314
+ Get available serial configuration options
315
+ ```javascript
316
+ const configs = rig.getSupportedSerialConfigs();
317
+ console.log('Data bits:', configs.serial.data_bits); // ['5', '6', '7', '8']
318
+ console.log('Stop bits:', configs.serial.stop_bits); // ['1', '2']
319
+ console.log('Parity:', configs.serial.serial_parity); // ['None', 'Even', 'Odd']
320
+ console.log('Handshake:', configs.serial.serial_handshake); // ['None', 'Hardware', 'Software']
321
+ console.log('PTT types:', configs.ptt_type); // ['RIG', 'DTR', 'RTS', 'PARALLEL', ...]
322
+ console.log('DCD types:', configs.dcd_type); // ['RIG', 'DSR', 'CTS', 'CD', ...]
323
+ ```
324
+
325
+ #### `setSerialConfig(param, value)` / `getSerialConfig(param)`
326
+ Configure serial port parameters
327
+ ```javascript
328
+ // Basic serial configuration (most common)
329
+ rig.setSerialConfig('data_bits', '8'); // 8 data bits
330
+ rig.setSerialConfig('stop_bits', '1'); // 1 stop bit
331
+ rig.setSerialConfig('serial_parity', 'None'); // No parity
332
+ rig.setSerialConfig('serial_handshake', 'None'); // No flow control
333
+
334
+ // Hardware flow control (if supported)
335
+ rig.setSerialConfig('serial_handshake', 'Hardware');
336
+
337
+ // Control line states
338
+ rig.setSerialConfig('rts_state', 'ON'); // Set RTS high
339
+ rig.setSerialConfig('dtr_state', 'OFF'); // Set DTR low
340
+
341
+ // Get current configuration
342
+ const dataBits = rig.getSerialConfig('data_bits');
343
+ const parity = rig.getSerialConfig('serial_parity');
344
+ ```
345
+
346
+ #### `setPttType(type)` / `getPttType()`
347
+ Configure PTT (Push-to-Talk) method
348
+ ```javascript
349
+ // Use CAT command for PTT (recommended)
350
+ rig.setPttType('RIG');
351
+
352
+ // Use DTR line for PTT (legacy interfaces)
353
+ rig.setPttType('DTR');
354
+
355
+ // Use RTS line for PTT (alternative)
356
+ rig.setPttType('RTS');
357
+
358
+ // Disable PTT control
359
+ rig.setPttType('NONE');
360
+
361
+ // Get current PTT type
362
+ const pttType = rig.getPttType();
363
+ console.log('PTT method:', pttType);
364
+ ```
365
+
366
+ #### `setDcdType(type)` / `getDcdType()`
367
+ Configure DCD (Data Carrier Detect) method
368
+ ```javascript
369
+ // Use CAT command for DCD (software squelch)
370
+ rig.setDcdType('RIG');
371
+
372
+ // Use DSR line for DCD (hardware squelch)
373
+ rig.setDcdType('DSR');
374
+
375
+ // Use CTS line for DCD (alternative)
376
+ rig.setDcdType('CTS');
377
+
378
+ // Get current DCD type
379
+ const dcdType = rig.getDcdType();
380
+ console.log('DCD method:', dcdType);
381
+ ```
382
+
383
+ #### Common Serial Configurations
384
+
385
+ **Yaesu Radios:**
386
+ ```javascript
387
+ rig.setSerialConfig('data_bits', '8');
388
+ rig.setSerialConfig('stop_bits', '1');
389
+ rig.setSerialConfig('serial_parity', 'None');
390
+ rig.setSerialConfig('serial_handshake', 'None');
391
+ rig.setPttType('RIG'); // Use CAT command
392
+ // Baud rate: 4800/9600 (set in constructor)
393
+ ```
394
+
395
+ **Kenwood Radios:**
396
+ ```javascript
397
+ rig.setSerialConfig('data_bits', '8');
398
+ rig.setSerialConfig('stop_bits', '2'); // Note: 2 stop bits
399
+ rig.setSerialConfig('serial_parity', 'None');
400
+ rig.setSerialConfig('serial_handshake', 'None');
401
+ rig.setPttType('RIG');
402
+ // Baud rate: 9600
403
+ ```
404
+
405
+ **Legacy Interface (DTR/RTS PTT):**
406
+ ```javascript
407
+ rig.setSerialConfig('data_bits', '8');
408
+ rig.setSerialConfig('stop_bits', '1');
409
+ rig.setSerialConfig('serial_parity', 'None');
410
+ rig.setPttType('DTR'); // Use DTR for PTT
411
+ rig.setDcdType('DSR'); // Use DSR for squelch
412
+ ```
413
+
287
414
  ## 🎯 Complete Example
288
415
 
289
416
  ```javascript
@@ -303,39 +430,48 @@ async function radioControl() {
303
430
  const rig = new HamLib(ft991a.rigModel, '/dev/ttyUSB0');
304
431
 
305
432
  try {
306
- rig.open();
433
+ await rig.open();
307
434
  console.log('Connected to', rig.getConnectionInfo().port);
308
435
 
309
436
  // Set up radio
310
- rig.setFrequency(144390000);
311
- rig.setMode('FM');
312
- rig.setLevel('RFPOWER', 0.5);
313
- rig.setFunction('NB', true);
437
+ await rig.setFrequency(144390000);
438
+ await rig.setMode('FM');
439
+ await rig.setLevel('RFPOWER', 0.5);
440
+ await rig.setFunction('NB', true);
314
441
 
315
442
  // Store memory channel
316
- rig.setMemoryChannel(1, {
443
+ await rig.setMemoryChannel(1, {
317
444
  frequency: 144390000,
318
445
  mode: 'FM',
319
446
  description: 'Local Repeater'
320
447
  });
321
448
 
322
449
  // Monitor signal
323
- setInterval(() => {
324
- const freq = rig.getFrequency();
325
- const mode = rig.getMode();
326
- const strength = rig.getStrength();
327
-
328
- console.log(`${freq/1000000} MHz ${mode.mode} S:${strength}`);
450
+ const monitorInterval = setInterval(async () => {
451
+ try {
452
+ const freq = await rig.getFrequency();
453
+ const mode = await rig.getMode();
454
+ const strength = await rig.getStrength();
455
+
456
+ console.log(`${freq/1000000} MHz ${mode.mode} S:${strength}`);
457
+ } catch (err) {
458
+ console.error('Monitor error:', err.message);
459
+ }
329
460
  }, 1000);
330
461
 
462
+ // Stop monitoring after 30 seconds
463
+ setTimeout(() => {
464
+ clearInterval(monitorInterval);
465
+ }, 30000);
466
+
331
467
  } catch (error) {
332
468
  console.error('Error:', error.message);
333
469
  } finally {
334
- rig.close();
470
+ await rig.close();
335
471
  }
336
472
  }
337
473
 
338
- radioControl();
474
+ radioControl().catch(console.error);
339
475
  ```
340
476
 
341
477
  ## 📋 Supported Radios
package/index.d.ts CHANGED
@@ -142,6 +142,47 @@ type VfoOperationType = 'CPY' | 'XCHG' | 'FROM_VFO' | 'TO_VFO' | 'MCL' | 'UP' |
142
142
  'DOWN' | 'BAND_UP' | 'BAND_DOWN' | 'LEFT' | 'RIGHT' |
143
143
  'TUNE' | 'TOGGLE';
144
144
 
145
+ /**
146
+ * Serial configuration parameter names
147
+ */
148
+ type SerialConfigParam = 'data_bits' | 'stop_bits' | 'serial_parity' | 'serial_handshake' |
149
+ 'rts_state' | 'dtr_state';
150
+
151
+ /**
152
+ * PTT (Push-to-Talk) types
153
+ */
154
+ type PttType = 'RIG' | 'DTR' | 'RTS' | 'PARALLEL' | 'CM108' | 'GPIO' | 'GPION' | 'NONE';
155
+
156
+ /**
157
+ * DCD (Data Carrier Detect) types
158
+ */
159
+ type DcdType = 'RIG' | 'DSR' | 'CTS' | 'CD' | 'PARALLEL' | 'CM108' | 'GPIO' | 'GPION' | 'NONE';
160
+
161
+ /**
162
+ * Serial configuration options interface
163
+ */
164
+ interface SerialConfigOptions {
165
+ /** Serial port basic parameters */
166
+ serial: {
167
+ /** Data bits options */
168
+ data_bits: string[];
169
+ /** Stop bits options */
170
+ stop_bits: string[];
171
+ /** Parity options */
172
+ serial_parity: string[];
173
+ /** Handshake options */
174
+ serial_handshake: string[];
175
+ /** RTS state options */
176
+ rts_state: string[];
177
+ /** DTR state options */
178
+ dtr_state: string[];
179
+ };
180
+ /** PTT type options */
181
+ ptt_type: string[];
182
+ /** DCD type options */
183
+ dcd_type: string[];
184
+ }
185
+
145
186
  /**
146
187
  * HamLib class - for controlling amateur radio devices
147
188
  */
@@ -183,25 +224,25 @@ declare class HamLib {
183
224
  * Must be called before other operations
184
225
  * @throws Throws error when connection fails
185
226
  */
186
- open(): void;
227
+ open(): Promise<number>;
187
228
 
188
229
  /**
189
230
  * Set VFO (Variable Frequency Oscillator)
190
231
  * @param vfo VFO identifier, typically 'VFO-A' or 'VFO-B'
191
232
  * @throws Throws error when device doesn't support or operation fails
192
233
  */
193
- setVfo(vfo: VFO): void;
234
+ setVfo(vfo: VFO): Promise<number>;
194
235
 
195
236
  /**
196
237
  * Set frequency
197
238
  * @param frequency Frequency value in hertz
198
239
  * @param vfo Optional VFO to set frequency on ('VFO-A' or 'VFO-B'). If not specified, uses current VFO
199
240
  * @example
200
- * rig.setFrequency(144390000); // Set to 144.39MHz on current VFO
201
- * rig.setFrequency(144390000, 'VFO-A'); // Set to 144.39MHz on VFO-A
202
- * rig.setFrequency(144390000, 'VFO-B'); // Set to 144.39MHz on VFO-B
241
+ * await rig.setFrequency(144390000); // Set to 144.39MHz on current VFO
242
+ * await rig.setFrequency(144390000, 'VFO-A'); // Set to 144.39MHz on VFO-A
243
+ * await rig.setFrequency(144390000, 'VFO-B'); // Set to 144.39MHz on VFO-B
203
244
  */
204
- setFrequency(frequency: number, vfo?: VFO): void;
245
+ setFrequency(frequency: number, vfo?: VFO): Promise<number>;
205
246
 
206
247
  /**
207
248
  * Set radio mode
@@ -209,60 +250,60 @@ declare class HamLib {
209
250
  * @param bandwidth Optional bandwidth setting ('narrow', 'wide', or default)
210
251
  * @note Operates on the current VFO (RIG_VFO_CURR)
211
252
  * @example
212
- * rig.setMode('USB');
213
- * rig.setMode('FM', 'narrow');
253
+ * await rig.setMode('USB');
254
+ * await rig.setMode('FM', 'narrow');
214
255
  */
215
- setMode(mode: RadioMode, bandwidth?: 'narrow' | 'wide'): void;
256
+ setMode(mode: RadioMode, bandwidth?: 'narrow' | 'wide'): Promise<number>;
216
257
 
217
258
  /**
218
259
  * Set PTT (Push-to-Talk) status
219
260
  * @param state true to enable PTT, false to disable PTT
220
261
  * @note Operates on the current VFO (RIG_VFO_CURR)
221
262
  */
222
- setPtt(state: boolean): void;
263
+ setPtt(state: boolean): Promise<number>;
223
264
 
224
265
  /**
225
266
  * Get current VFO
226
267
  * @returns Current VFO identifier
227
268
  */
228
- getVfo(): string;
269
+ getVfo(): Promise<string>;
229
270
 
230
271
  /**
231
272
  * Get current frequency
232
273
  * @param vfo Optional VFO to get frequency from ('VFO-A' or 'VFO-B'). If not specified, uses current VFO
233
274
  * @returns Current frequency value in hertz
234
275
  * @example
235
- * rig.getFrequency(); // Get frequency from current VFO
236
- * rig.getFrequency('VFO-A'); // Get frequency from VFO-A
237
- * rig.getFrequency('VFO-B'); // Get frequency from VFO-B
276
+ * await rig.getFrequency(); // Get frequency from current VFO
277
+ * await rig.getFrequency('VFO-A'); // Get frequency from VFO-A
278
+ * await rig.getFrequency('VFO-B'); // Get frequency from VFO-B
238
279
  */
239
- getFrequency(vfo?: VFO): number;
280
+ getFrequency(vfo?: VFO): Promise<number>;
240
281
 
241
282
  /**
242
283
  * Get current radio mode
243
284
  * @returns Object containing mode and bandwidth information
244
285
  * @note Operates on the current VFO (RIG_VFO_CURR)
245
286
  */
246
- getMode(): ModeInfo;
287
+ getMode(): Promise<ModeInfo>;
247
288
 
248
289
  /**
249
290
  * Get current signal strength
250
291
  * @returns Signal strength value
251
292
  * @note Operates on the current VFO (RIG_VFO_CURR)
252
293
  */
253
- getStrength(): number;
294
+ getStrength(): Promise<number>;
254
295
 
255
296
  /**
256
297
  * Close connection to device
257
298
  * Does not destroy object, can re-establish connection by calling open()
258
299
  */
259
- close(): void;
300
+ close(): Promise<number>;
260
301
 
261
302
  /**
262
303
  * Destroy connection to device
263
304
  * Should delete object reference after calling to enable garbage collection
264
305
  */
265
- destroy(): void;
306
+ destroy(): Promise<number>;
266
307
 
267
308
  /**
268
309
  * Get connection information
@@ -444,6 +485,89 @@ declare class HamLib {
444
485
  * @returns Current antenna number
445
486
  */
446
487
  getAntenna(): number;
488
+
489
+ // Serial Port Configuration
490
+
491
+ /**
492
+ * Set serial port configuration parameter
493
+ * @param paramName Parameter name ('data_bits', 'stop_bits', 'serial_parity', 'serial_handshake', 'rts_state', 'dtr_state')
494
+ * @param paramValue Parameter value
495
+ * @example
496
+ * // Set data bits to 8
497
+ * hamlib.setSerialConfig('data_bits', '8');
498
+ *
499
+ * // Set parity to even
500
+ * hamlib.setSerialConfig('serial_parity', 'Even');
501
+ *
502
+ * // Set handshake to hardware
503
+ * hamlib.setSerialConfig('serial_handshake', 'Hardware');
504
+ */
505
+ setSerialConfig(paramName: SerialConfigParam, paramValue: string): void;
506
+
507
+ /**
508
+ * Get serial port configuration parameter
509
+ * @param paramName Parameter name to retrieve
510
+ * @returns Parameter value
511
+ * @example
512
+ * // Get current data bits setting
513
+ * const dataBits = hamlib.getSerialConfig('data_bits');
514
+ *
515
+ * // Get current parity setting
516
+ * const parity = hamlib.getSerialConfig('serial_parity');
517
+ */
518
+ getSerialConfig(paramName: SerialConfigParam): string;
519
+
520
+ /**
521
+ * Set PTT (Push-to-Talk) type
522
+ * @param pttType PTT type ('RIG', 'DTR', 'RTS', 'PARALLEL', 'CM108', 'GPIO', 'GPION', 'NONE')
523
+ * @example
524
+ * // Use DTR line for PTT
525
+ * hamlib.setPttType('DTR');
526
+ *
527
+ * // Use RTS line for PTT
528
+ * hamlib.setPttType('RTS');
529
+ *
530
+ * // Use CAT command for PTT
531
+ * hamlib.setPttType('RIG');
532
+ */
533
+ setPttType(pttType: PttType): void;
534
+
535
+ /**
536
+ * Get current PTT type
537
+ * @returns Current PTT type
538
+ */
539
+ getPttType(): string;
540
+
541
+ /**
542
+ * Set DCD (Data Carrier Detect) type
543
+ * @param dcdType DCD type ('RIG', 'DSR', 'CTS', 'CD', 'PARALLEL', 'CM108', 'GPIO', 'GPION', 'NONE')
544
+ * @example
545
+ * // Use DSR line for DCD
546
+ * hamlib.setDcdType('DSR');
547
+ *
548
+ * // Use CTS line for DCD
549
+ * hamlib.setDcdType('CTS');
550
+ *
551
+ * // Use CAT command for DCD
552
+ * hamlib.setDcdType('RIG');
553
+ */
554
+ setDcdType(dcdType: DcdType): void;
555
+
556
+ /**
557
+ * Get current DCD type
558
+ * @returns Current DCD type
559
+ */
560
+ getDcdType(): string;
561
+
562
+ /**
563
+ * Get supported serial configuration options
564
+ * @returns Object containing all supported configuration parameters and their possible values
565
+ * @example
566
+ * const configs = hamlib.getSupportedSerialConfigs();
567
+ * console.log('Supported data bits:', configs.serial.data_bits);
568
+ * console.log('Supported PTT types:', configs.ptt_type);
569
+ */
570
+ getSupportedSerialConfigs(): SerialConfigOptions;
447
571
  }
448
572
 
449
573
  /**
@@ -456,7 +580,7 @@ declare const nodeHamlib: {
456
580
  // Export types for use elsewhere
457
581
  export { ConnectionInfo, ModeInfo, SupportedRigInfo, VFO, RadioMode, MemoryChannelData,
458
582
  MemoryChannelInfo, SplitModeInfo, SplitStatusInfo, LevelType, FunctionType,
459
- ScanType, VfoOperationType, HamLib };
583
+ ScanType, VfoOperationType, SerialConfigParam, PttType, DcdType, SerialConfigOptions, HamLib };
460
584
 
461
585
  // Support both CommonJS and ES module exports
462
586
  export = nodeHamlib;