Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/visca/camera.ts
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,11 @@ export class Camera extends EventEmitter {
break;
}
console.log(`CAMERA ERROR: id: ${this.index}, command socket: ${viscaCommand.socket}, message: ${message}\nRECEIVED: ${viscaCommand.toString()}`);
this.cameraBuffers[socketKey].handleError(message);
if(this.cameraBuffers[socketKey]){
this.cameraBuffers[socketKey].handleError(message);
}else{
console.log("Error: Camera buffer missing!!!");
}
delete (this.cameraBuffers[socketKey]);
this._update();
}
Expand Down
10 changes: 5 additions & 5 deletions src/visca/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,13 @@ export class ViscaController extends EventEmitter {
closeSerial() { this.serialConnection.close(); }
startSerial(portname = "/dev/ttyUSB0", baudRate = 9600, timeout = 1, debug = false) {
this.serialConnection = new SerialTransport(portname, timeout, baudRate, debug);
this.serialConnection.start();
//this.serialConnection.start();

// create callbacks
this.serialConnection.on('open', this.onSerialOpen);
this.serialConnection.on('close', this.onSerialClose);
this.serialConnection.on('error', this.onSerialError);
this.serialConnection.on('data', this.onSerialData);
this.serialConnection.on('open', this.onSerialOpen.bind(this));
this.serialConnection.on('close', this.onSerialClose.bind(this));
this.serialConnection.on('error', this.onSerialError.bind(this));
this.serialConnection.on('data', this.onSerialData.bind(this));

// send enumeration command (on reply, we will send the IF clear command)
this.enumerateSerial();
Expand Down
2 changes: 1 addition & 1 deletion src/visca/visca-ip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export class UDPTransport extends EventEmitter {
this.socket = udp.createSocket( 'udp4' );

// handle replies
this.socket.on( 'message', function ( msg, info ) {
this.socket.on( 'message', ( msg, info ) =>{
console.log( 'Data received from client : ' + msg.toString() );
console.log( 'Received %d bytes from %s:%d\n', msg.length, info.address, info.port );
this.onData( [...msg] );
Expand Down
33 changes: 27 additions & 6 deletions src/visca/visca-serial.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,30 @@ export class SerialTransport extends EventEmitter implements ViscaTransport {

// open the serial port
try {
this.serialport = new SerialPort( this.portname, { baudRate: this.baudRate } );
this.serialport.on( 'open', this.onOpen ); // provides error object
this.serialport.on( 'close', this.onClose ); // if disconnected, err.disconnected == true
this.serialport.on( 'error', this.onError ); // provides error object
this.serialport = new SerialPort( {path:this.portname, baudRate: this.baudRate, autoOpen:false } );
this.serialport.open((err: any) => {
if (err) {
return console.log('Error opening port: ', err.message);
}
});

this.serialport = new SerialPort( this.portname, { baudRate: this.baudRate, autoOpen: false } );
this.serialport.on( 'open', this.onOpen.bind(this) ); // provides error object
this.serialport.on( 'close', this.onClose.bind(this) ); // if disconnected, err.disconnected == true
this.serialport.on( 'error', this.onError.bind(this) ); // provides error object

this.serialport.pipe( new Delimiter( { delimiter: [ 0xff ] } ) )
.on( 'data', this.onData ); // provides a Buffer object
.on( 'data', this.onData.bind(this) ); // provides a Buffer object
this.serialport.open((err)=>{
if(err){
console.log("################### Error opening serial port "+ this.portname +":");
console.log(err);
}else{
console.log("################### " + this.portname +" successfully opened!!");
}


})

} catch ( e ) {
console.log( `Exception opening serial port '${this.portname}' for (display) ${e}\n` );
Expand All @@ -44,7 +61,11 @@ export class SerialTransport extends EventEmitter implements ViscaTransport {

onOpen() { this.started = true; this.emit( 'open' ); }
onClose( e :string ) { console.log( e ); this.started = false; this.emit( 'close' ); }
onError( e :string ) { console.log( e ); this.started = false; this.emit( 'error', e ); }
onError( e :string ) {
console.log( e );
this.started = false;
this.emit( 'error', e );
}

onData( packet:Buffer ) {
// the socket parser gives us only full visca packets
Expand Down