Kaluma Agent is a desktop service application to communicate Kaluma-compatible boards from external applications (e.g. Kaluma IDE).
Main features of Kaluma Agent are:
- Periodically scan available devices. (default 3 seconds)
- Allow to manage multiple opened devices.
It provides socket.io based protocol and the socket port is 54094.
Before to send command or listen to events, you need to establish a connection to the agent via socket.io protocol.
const io = require('socket.io-client')
var socket_client = io('http://localhost:54094')
socket_client.on('connect', () => { /* ... */ })
socket_client.on('disconnect', () => { /* ... */ })Here are some commands which can be sent to Kaluma Agent.
callback:<Function>err:<Error>devices:<Array<DeviceObject>>
Request a list of available devices (ready to open -- already plugged to USB or discovered wirelessly) connected via serial ports.
socket_client.emit('cmd:list', (err, deviceObjects) => {
if (err) {
// handle error
} else {
console.log(deviceObjects)
}
})path:<string>callback:<Function>err:<Error>
Request to open the specified serial port.
socket_client.emit('cmd:open', '/dev/tty.usbmodem0001' (err) => {
if (err) {
// handle error
} else {
console.log('opened')
}
})path:<string>callback:<Function>err:<Error>
Request to close the specified serial port.
socket_client.emit('cmd:close', '/dev/tty.usbmodem0001' (err) => {
if (err) {
// handle error
} else {
console.log('closed')
}
})path:<string>data:<string|Uint8Array>callback:<Function>err:<Error>
Send data to the serial port.
socket_client.emit('cmd:write', '/dev/tty.usbmodem0001', '1+2\r', err => {
if (err) {
// handle error
} else {
console.log('done')
}
})path:<string>code:<string>callback:<Function>err:<Error>
Upload code to the serial port.
socket_client.emit('cmd:upload', '/dev/tty.usbmodem0001', 'console.log("hello,world!")', (err) => {
if (err) {
// handle error
} else {
console.log('code uploaded.')
}
})Here are some events from Agent. You can also use events from original socket.io (e.g. connect, disconnect, connect_error, connect_timeout, error, ... For more: Socket.IO Client API).
path:<string>
Triggered when the serial port is open.
socket_client.on('event:open', (path) => {
console.log(path)
})path:<string>
Triggered when the serial port is closed.
socket_client.on('event:close', (path) => {
console.log(path)
})path:<string>
Triggered when the serial port is closed by disconnection (e.g. unplug the device from computer)
socket_client.on('event:close-disconnected', (path) => {
console.log(path)
})path:<string>data:<string>Received data.
Triggered when data is received from the serial port.
socket_client.on('event:data', (path, data) => {
console.log(path, data)
})path:<string>err:<string>Error message.
Triggered when error is occurred.
socket_client.on('event:data', (path, err) => {
console.error(path, err)
})Device object is JSON object including device's information:
path:<string>manufacturer:<string>serialNumber:<string>pnpId:<string>locationId:<string>vendorId:<string>productId:<string>