Coder Social home page Coder Social logo

utopiantools / node-visca Goto Github PK

View Code? Open in Web Editor NEW
16.0 5.0 3.0 130 KB

Advanced nodejs library for working with VISCA-based PTZ cameras over IP and over serial connections.

TypeScript 100.00%
visca javascript ptz-control ptzoptics sony nodejs typescript

node-visca's Introduction

node-visca

(( THIS CODE IS IN DEVELOPMENT AND IS UNTESTED ))

Description

This is a complete implementation of the Sony VISCA Protocol for the EVI-H100s and similar cameras. It also contains commands to implement the additional features from PTZOptics and LUMiO12x cameras. The library assumes you know which commands will work on your cameras, but don't worry; commands not recognized by your camera will simply be ignored.

Installation

From inside your project directory...

npm i @utopian/visca --save

Usage

Rationale...

Of course, the main reason for this module is to fully implement the VISCA protocol without any reliance on libvisca the main C library for VISCA commands.

I did it as a challenge to myself, but also so that the VISCA protocol could be more easily understood by Javascript/Typescript developers who are not comfortable reading protocol documentation or C source code.

Finally, by implementing it in Typescript, I have been able to create a code-base that can be parsed easily by Visual Studio Code (and presumably other IDEs) providing intelligent code suggestions to make calling VISCA commands much easier on the developer.

The biggest challenge for the Javascript/Typescript ecosystem in managing Visca connections is that Visca commands are intended to be executed in the following manner:

  • send a command over the serial or network connection
  • wait for an ACK (for most commands)
  • wait for a DONE (for many commands)

Javascript doesn't like to work this way. Javascript/Typescript code wants everything to run asynchronously, so this library virtualizes VISCA cameras to maintain command buffers and callbacks. As VISCA commands come in, the Camera objects will update themselves and then emit an 'update' event. As a developer, you only need to send commands and listen for changes on the various objects.

node-visca's People

Contributors

cgarwood avatar hrueger avatar jeffmikels avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

node-visca's Issues

Syntax error sending Preset Recall to Prisual Camera

When testing the library with a Prisual 20x Camera using UDP Visca I am receiving a syntax error sending the Preset Recall command and Preset Set Commands.

Here is the code

import { Camera } from "../src/visca/visca";
import { ViscaController,ViscaCameraConfig, ViscaControllerConfig,ViscaCommand } from "../src/visca/visca";

let config = {
    viscaSerial:{port:"COM7",baud:9600},
    //viscaIPCameras: [],
    viscaServer:{basePort: 52381,}
}
let ipConfig = {
    
} as ViscaCameraConfig;
let viscaConfig = config as ViscaControllerConfig;
viscaConfig.viscaSerial.baud = 9600;
viscaConfig.viscaSerial.port = "COM7";
ipConfig.id = 1;
ipConfig.ip = "192.168.100.88";
ipConfig.name= "Test";
ipConfig.port=1259;
const controller = new ViscaController(viscaConfig);
let cam1 = controller.addIPCamera(ipConfig);
cam1.on('update',()=>{
    console.log('cam 1 updated:');
    console.log(JSON.stringify(cam1));
});
let cmd = ViscaCommand.cmdCameraPresetRecall(1,1);
console.log(JSON.stringify(cmd));
cmd = ViscaCommand.cmdCameraPresetSet(1,1);
console.log(JSON.stringify(cmd));
cmd.onError = function(err){
    console.log(`preset error: ${err}`);
};
cam1.sendCommand(cmd);
console.log("started")


Attached is the log output.
node-visca.log

Basic Usage Example

Hi. Great work. Thank you. Is there any chance you could provide a basic usage example for Visca over IP please?

Lib Crashing when creating a new `Camera`

Hi @jeffmikels ๐Ÿ‘‹

Firstly, thanks for your work on this project! ๐Ÿ™‚

Today I used patch-package to patch @utopian/[email protected] for the project I'm working on.

When using the UDP Transport, my application would always crash when creating a new Camera object. The following patch should fix that.
It also disables the console.log output.

Here is the diff that solved my problem:

diff --git a/node_modules/@utopian/visca/dist/visca-ip.js b/node_modules/@utopian/visca/dist/visca-ip.js
index 8b20046..146feec 100644
--- a/node_modules/@utopian/visca/dist/visca-ip.js
+++ b/node_modules/@utopian/visca/dist/visca-ip.js
@@ -105,11 +105,11 @@ class UDPTransport extends events_1.EventEmitter {
         if (this.debug)
             console.log('Sent: ' + packet);
         // sending packet
-        this.socket.send(packet, this.port, this.host, function (error) {
+        this.socket.send(Buffer.from(packet), this.port, this.host, (error) => {
             if (error) {
                 this.socket.close();
             }
-            else {
+            else if(this.debug) {
                 console.log('Data sent !!!');
             }
         });

This issue body was partially generated by patch-package.

Note that this auto-generated diff fixes the compiled js, but I don't think it is hard to find that lines in the TS.

Would you accept a PR?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.