0
votes

I have an AllSky-340 CCD camera, which communicates using a serial port.

I use a PL2303 USB converter to connect it to my laptop.

dmesg:

[14223.043367] usb 1-2: new full-speed USB device number 12 using xhci_hcd
[14223.172348] usb 1-2: New USB device found, idVendor=067b, idProduct=2303
[14223.172352] usb 1-2: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[14223.172353] usb 1-2: Product: USB-Serial Controller
[14223.172355] usb 1-2: Manufacturer: Prolific Technology Inc.
[14223.172763] pl2303 1-2:1.0: pl2303 converter detected
[14223.173356] usb 1-2: pl2303 converter now attached to ttyUSB0

A python code called pyallsky allows to control the AllSky340 camera under linux. It works.

I have translated this code in javascript to be used with node.

Here is a part of the code code ("E:" is a test command):

var serialport = require("serialport");                                                                                                         
var sp = new serialport(portName);                                                                                                              

sp.on('open',  showPortOpen);                                                                                                                   
sp.on('close', showPortClose);                                                                                                                  
sp.on('disconnect', showPortDisconnect);                                                                                                        
sp.on('error', showError);                                                                                                                      
sp.on('data',  sendSerialData);                                                                                                                 

function showPortOpen(error) {                                                                                                                  

    if (error) {                                                                                                                                
        console.log('Error while opening the port ' + error);                                                                                   
    } else {                                                                                                                                    
        console.log('port open. Data rate: ' + sp.options.baudRate);                                                                            
        var buffer = "E:"                                                                                                                       
        sp.write(buffer, function (err, result) {                                                                                               
            console.log("writing buffer: "+buffer)                                                                                              
            if (err) {                                                                                                                          
                console.log('Error while sending message : ' + err);                                                                            
            }                                                                                                                                   
            if (result) {                                                                                                                       
                console.log('Response received after sending message : ' + result);                                                             
            }                                                                                                                                   
        });                                                                                                                                     

    }                                                                                                                                           
}                                                                                                                                               

function sendSerialData(data) {                                                                                                                 
    console.log('sendserial data says: '+data);                                                                                                 
}                                                                                                                                               

function showPortClose() {                                                                                                                      
    console.log('port closed.');                                                                                                                
}                                                                                                                                               

function showPortDisconnect() {                                                                                                                 
    console.log('port disconnected.');                                                                                                          
}                                                                                                                                               

function showError(error) {                                                                                                                     
    console.log('Serial port error: ' + error);                                                                                                 
}                                                                                                                                               

But it does not work: running the script, the log is

port open. Data rate: 9600
writing buffer: E:

and nothing from the camera is recieved.

I do know that the data listener works, because if I run the pyallsky python script at the same time, my listener intercepts data (before pyallsky complains multiple accesses to the port).

Shutting down the camera does not have any effect on close and disconnect listener.

Only unplugging the PL2303 cable causes the script to log

port disconnected.
port closed.

My idea is that js code communicates only with the PL2303 cable and not with the camera. Is that possible? How can I solve it?

1

1 Answers

0
votes

It turned out I had to force the baudrate to 115200 in order to make it work.

   /// Opens the serial connection with the camera                                                                                              
   var sp = new serialport("/dev/ttyUSB0",                                                                               
                            {baudRate: 115200,                                                    
                             autoOpen:false},                                                                                                   
                            err => err!== null ? 
        console.log('serialport instance error: ', err.message) : true                                  
                           );