Getting Started
Installation
yarn add @ham-js/cat
npm install @ham-js/cat
The same package can be used in the browser or with nodejs.
NodeJS with SerialPort
Also have a look at the /examples folder.
import { SerialPort } from "serialport"
import { SerialPortDriver, YaesuGenericTransceiver, VFOType } from "@ham-js/cat"
const serialPort = new SerialPort({
autoOpen: false,
path: "/dev/tty.SLAB_USBtoUART5", // replace with your serial port
baudRate: 4800, // replace with the correct baudRate for your trx
})
const serialPortDriver = new SerialPortDriver(serialPort)
const device = new YaesuGenericTransceiver(serialPortDriver);
(async () => {
await device.open()
console.log({ vfo: await device.getVFOFrequency({ vfo: VFOType.Current }) })
await device.setVFOFrequency({ frequency: 14_250_300, vfo: VFOType.Current })
console.log({ vfo: await device.getVFOFrequency({ vfo: VFOType.Current }) })
console.log("Listening to events from TRX")
device.events.subscribe(console.log)
process.on("SIGINT", async () => await device.close())
})()
React with WebSerial
Also have a look at the source code of the playground.
import { useCallback, useState } from "react"
import { VFOType, WebSerialDriver, YaesuGenericTransceiver } from "@ham-js/cat"
export const TRXComponent = () => {
const [vfoFrequency, setVFOFrequency] = useState<number>()
const getVFOFrequency = useCallback(() => {
(async () => {
const port = await navigator.serial.requestPort() // you might need to install a driver for your device
const driver = new WebSerialDriver(port, {baudRate: 4800}) // replace with the correct baud rate of your device
const device = new YaesuGenericTransceiver(driver)
await device.open()
setVFOFrequency(await device.getVFOFrequency({ vfo: VFOType.Current }))
await device.close()
})()
}, [])
return <>
<button onClick={getVFOFrequency} type="button">Get VFO Frequency</button>
<p>VFO Frequency: {vfoFrequency}</p>
</>
}
VFO Frequency:
Refer to the API docs for further drivers.
Logging
// log low-level communication
await device.open({ logDriver: true })
device.driverLog.subscribe(console.log)
// log commands send to device and their result
await device.open({ logDevice: true })
device.deviceLog.subscribe(console.log)
// or log both at once
await device.open({ log: true })