Bonescript: write to serial port fails although port is open - serial-port

Here is bonescript for testing serial connection in BeagleBone black by exchanging and incrementing characters
var b = require('bonescript');
var port1='/dev/ttyO1';
var port2='/dev/ttyO2';
var options={
baudrate: 9600,
parity: 'even',
parser: b.serialParsers.readline("\n")
};
console.log(b.serialOpen(port1, options, onSerial1));// open port 1
console.log(b.serialOpen(port2, options, onSerial2));//open port 2
b.serialWrite(port1,'A');//start letter bouncing
function onSerial1(x){
if (x.event == 'data') {
console.log(x.data);
var char =x.data;//get letter
if(char=='Z')
char='A';// reset or incremet
else
char++;
b.serialWrite(port2,char);
}
}
function onSerial2(x){
if (x.event == 'data') {
console.log(x.data);
var char =x.data;
if(char=='Z')
char='A';
else
char+=1;
b.serialWrite(port1,char);
}
}
Here is output in cloud9:
^
debugger listening on port 15454
true
true
events.js:72
throw er; // Unhandled 'error' event
^
Error: Serialport not open.
at SerialPort.write (/usr/local/lib/node_modules/bonescript/node_modules/serialport/serialport.js:246:17)
at Object.exports.wrapCall.newFunction [as serialWrite] (/usr/local/lib/node_modules/bonescript/my.js:198:41)
at Object.<anonymous> (/var/lib/cloud9/serial/myserial.js:12:3)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.runMain [as _onTimeout] (module.js:497:10)
at Timer.listOnTimeout [as ontimeout] (timers.js:110:15)
As you may see serialOpen successfully opens the ports (returns true) but initial write fails. I can.t think of a reason.

It is possible that port2 is not yet opened when port1 sends it the letter A at the first time.
Try to make some delay between the 2 lines
console.log(b.serialOpen(port2, options, onSerial2));//open port 2
b.serialWrite(port1,'A');//start letter bouncing
You may try using setTimeOut(b.serialWrite(port1,'A'), 2000);
or write on port1 when the event at port2 is opened.

Related

Elephant io Undefined index : upgrades

Trying to reach ly node server with elephant io
But I fail with that error :
In Version1X.php line 194: Notice: Undefined index: upgrades
I added the dependency to my composer and the wissembly/elephant-io is well present in my vendor.
composer
"wisembly/elephant.io": "~3.0"
action
$client = new Client(new Version1X('http://localhost:1299/map'));
// open connection
$client->initialize();
$output->writeln("update des offres");
$offers = $this->em->getRepository('AppRefactoredBundle:app_Offer')->findAll();
foreach($offers as $offer){
if($offer->getUpdatedAt() < new DateTime('-2 hours')){
$offer->setCurrentStatus(2);
// send for server (listen) the any array
$client->emit('timeout', ['idUser' => $offer->getProfile()]);
}
}
Here is the doc: https://github.com/mairesweb/socket.io-elephant.io/blob/master/client.php
I don't require the autoload cause I can't find it, may be this is why...but I don't know how to do that.
Thanks for help.

When using Sqlite3 on Electron app , streams are undefined - Node's set-blocking module

We are working on a universal app, that must execute on mobile (ios, android), desktop (windows, mac, linux) adn in any browser.
For client database management, we want to use sqlite3 - for desktop- , in this case the app will be packaged using Electron (Atom shell) . The module bundler we are using is webpack, as the app is developed with Ionic 2 and Angular2.
We have installed sqlite3 well, as a project dependency, with node-pre-gyp generating the binary for the platform (in this case we are testing with Windows 7 64 bits)
We have a provider for Sqlite3, this is the code:
import * as sqlite3 from 'sqlite3';
import { IDatabaseProvider } from './database.provider';
export class Sqlite3DatabaseProvider implements IDatabaseProvider {
private _storage;
constructor() {
console.log('Initializing Sqlite3 Database Provider');
}
openDatabase() {
this._storage = new sqlite3.Database('v2App_sqlite3.db');
}
}
As you can notice, the line the creates a database is commented, as the app works OK like that. If I uncomment that line , we have this error:
Runtime Error
Cannot read property '_handle' of undefined
TypeError: Cannot read property '_handle' of undefined
at http://localhost:8100/build/main.js:210758:15
at Array.forEach (native)
at module.exports (http://localhost:8100/build/main.js:210757:36)
at Object.<anonymous> (http://localhost:8100/build/main.js:12580:1)
at Object.<anonymous> (http://localhost:8100/build/main.js:12873:30)
at __webpack_require__ (http://localhost:8100/build/main.js:20:30)
at Object.<anonymous> (http://localhost:8100/build/main.js:69457:11)
at Object.<anonymous> (http://localhost:8100/build/main.js:69638:30)
at __webpack_require__ (http://localhost:8100/build/main.js:20:30)
at Object.<anonymous> (http://localhost:8100/build/main.js:211548:72)
The curious of this, is that it's failing here, in the code of the set-blocking npm module:
module.exports = function (blocking) {
[process.stdout, process.stderr].forEach(function (stream) {
if (stream._handle && stream.isTTY && typeof stream._handle.setBlocking === 'function') {
stream._handle.setBlocking(blocking)
}
})
}
As stream is coming undefined ,when getting the _handle property gives the error.
But this code is only executed if I add the line that creates the sqlite3 database:
this._storage = new sqlite3.Database('v2App_sqlite3.db');
What is the relation between this module (set-blocking ) and sqlite3 ?, Why the streams are undefined when trying to create the sqlite3 database ?
Maybe as generates a file - the database - , using Node's outputStream, and still could not have been created that object - stream.
Any help?
Thanks in advance

JSON will not insert into Meteor Collection (even with Fiber or bindEnvironment)

I realize that similar topics have been discussed, I have browsed through them all and tried to mimic solutions for about 4 hours but none of them seem to solve the problem. I would not have posted this with having exhausted any potential solution I could find.
I am trying to convert a large csv to JSON and then insert it into my Meteor collection following the conversion.
Here is my code using the Meteor.bindElement approach:
if Meteor.isServer
#Fiber = Meteor.npmRequire("fibers")
Meteor.startup ->
#Converter Class
if Data.find().count() is 0
Converter = Meteor.npmRequire('csvtojson').core.Converter
fs = Meteor.npmRequire('fs')
csvFileName = '/Path/To/My/File.csv'
fileStream = fs.createReadStream(csvFileName)
#new converter instance
csvConverter = new Converter(constructResult: true)
#end_parsed will be emitted once parsing finished
csvConverter.on "end_parsed", (jsonObj) ->
console.log jsonObj
boundFunction = Meteor.bindEnvironment(->
Data.insert jsonObj
return
, (e) ->
throw e
return
)
insertToDB boundFunction
#read from file
fileStream.pipe csvConverter
return
After parsing I am able to log the JSON just fine but when I try to add it to the collection like this:
csvConverter.on "end_parsed", (jsonObj) ->
console.log jsonObj
Data.insert jsonObj
I get the error:
throw new Error("Meteor code must always run within a Fiber. " +
W20141112-20:08:44.306(-8)? (STDERR) ^
W20141112-20:08:44.306(-8)? (STDERR) Error: Meteor code must always run within a Fiber. Try wrapping callbacks that you pass to non-Meteor libraries with Meteor.bindEnvironment.
W20141112-20:08:44.306(-8)? (STDERR) at Object.Meteor._nodeCodeMustBeInFiber (packages/meteor/dynamics_nodejs.js:9)
W20141112-20:08:44.306(-8)? (STDERR) at _.extend.get (packages/meteor/dynamics_nodejs.js:21)
W20141112-20:08:44.306(-8)? (STDERR) at Object.DDP.randomStream (packages/ddp/random_stream.js:69)
W20141112-20:08:44.306(-8)? (STDERR) at self._makeNewID (packages/mongo/collection.js:72)
W20141112-20:08:44.306(-8)? (STDERR) at Mongo.Collection.(anonymous function) [as insert] (packages/mongo/collection.js:485)
W20141112-20:08:44.307(-8)? (STDERR) at csvAdv.<anonymous> (server/startup.coffee:16:13)
W20141112-20:08:44.307(-8)? (STDERR) at csvAdv.emit (events.js:95:17)
W20141112-20:08:44.307(-8)? (STDERR) at csvAdv.<anonymous> (/Users/samuel_chordas/CurrentClasses/CSCI477a/JPL/JataTwo/packages/npm-container/.build.npm-container/npm/node_modules/csvtojson/libs/core/init_onend.js:9:10)
W20141112-20:08:44.307(-8)? (STDERR) at csvAdv.emit (events.js:117:20)
W20141112-20:08:44.307(-8)? (STDERR) at _stream_readable.js:929:16
=> Exited with code: 8
Which I was able to get rid of by wrapping the function in a fiber with the following code but it DOES NOT write to my collection:
if Meteor.isServer
#Fiber = Meteor.npmRequire("fibers")
Meteor.startup ->
#Converter Class
if Data.find().count() is 0
Converter = Meteor.npmRequire('csvtojson').core.Converter
fs = Meteor.npmRequire('fs')
csvFileName = '/Path/To/My/File.csv'
fileStream = fs.createReadStream(csvFileName)
#new converter instance
csvConverter = new Converter(constructResult: true)
#end_parsed will be emitted once parsing finished
csvConverter.on "end_parsed", (jsonObj) ->
Fiber ->
Data.insert jsonObj
return
fileStream.pipe csvConverter
return
So I tried resorting to using the bindEnvironment as shown in the first block of code which results in the same "Error("Meteor code must always run within a Fiber" error.
Here is my collection in my /lib folder:
#Data = new Mongo.Collection 'data'
I am pretty new to Meteor Javascript and Coffescript so any feedback would be appreciated.
Also I would like to add that I can't get .run() to work on Fiber.
Try moving the definition of boundFunction outside of the end_parsed event handler.
boundFunction = Meteor.bindEnvironment((jsonObj) ->
Data.insert jsonObj
return
, (e) ->
throw e
)
csvConverter.on "end_parsed", (jsonObj) ->
console.log jsonObj
boundFunction jsonObj
return
I suspect the "Meteor code must always run within a Fiber." error is not coming from Data.insert but from Meteor.bindEnvironment itself. Meteor.bindEnvironment
is called from inside a "Meteor context"
takes a function
binds that function to the same "Meteor context" that bindEnvironment was called from
In your implementation, by the time you call bindEnvironment, the "Meteor context" has already been lost, so bindEnvironment can't do anything to help.

gracenote sdk for music id not working on iOS 7 device

here is what we have done:
we added the framework to our project and
have the following in one of our classes:
GCSearchViewController.h
#interface GCSearchViewController : UIViewController<UISearchBarDelegate, GNSearchResultReady, GNAudioSourceDelegate>
GCSearchViewController.m
// - As per the web tutorial
#import <GracenoteMusicID/GNConfig.h>
#import <GracenoteMusicID/GNOperations.h>
#import <GracenoteMusicID/GNSearchResponse.h>
#import <GracenoteMusicID/GNSearchResult.h>
// - As per what we saw in the demo app
#import <GracenoteMusicID/GNRecognizeStream.h>
#import <GracenoteMusicID/GNAudioConfig.h>
#import <GracenoteMusicID/GNAudioSourceMic.h>
#import <AVFoundation/AVAudioSession.h>
…
#pragma mark - Gracenote Delegate
-(void) identifySong {
[[AVAudioSession sharedInstance] requestRecordPermission:^(BOOL response){
NSLog(#"Allow microphone use response: %d", response);
if (response) {
[GNOperations recognizeMIDStreamFromMic:self config:self.config];
}
}];
}
- (void) GNResultReady:(GNSearchResult *) result
{
GNSearchResponse *best = [result bestResponse];
if (![result isFailure] && (best.artist!=nil)) {
NSLog(#"Artist %#", best.artist);
NSLog(#"Song name %#", best.trackTitle);
} else {
NSLog(#"No Match");
}
}
- (void) audioBufferDidBecomeReady:(GNAudioSource*)audioSource samples:(NSData*)samples {
NSError *err;
err = [self.recognizeFromPCM writeBytes:samples];
if (err) {
NSLog(#"ERROR: %#",[err localizedDescription]);
}
}
this code works ok in the simulator, but whenever we run it on the device (ipod touch 5th or iphone 5) the app breaks with the following error:
2013-11-16 22:00:40.402 GC[1758:60b] 22:00:40.401 ERROR: [0x3c29f18c] >aurioc> 783: failed: -10851 (enable 1, outf< 2 ch, 0 Hz, Float32, non-inter> inf< 1 ch, 44100 Hz, Int16>)
Error: 0xffffd59d2013-11-16 22:00:52.904 Leaf[1758:60b] Allow microphone use response: 1
2013-11-16 22:00:52.925 GC[1758:60b] 22:00:52.925 ERROR: [0x3c29f18c] >aurioc> 783: failed: -10851 (enable 1, outf< 2 ch, 0 Hz, Float32, non-inter> inf< 1 ch, 44100 Hz, Int16>)
Error: 0xffffd59d2013-11-16 22:00:52.927 GC[1758:60b] *** Assertion failure in -[GNFingerprinterQueue startupTimerFired], /home/mobile/z-15003-ecma-3.2/cddb-clients/mmid/iOSMobileSDK/3.2/Classes/Private/GNFingerprinterQueue.m:291
2013-11-16 22:00:52.930 GC[1758:60b] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'audioSource is nil'
*** First throw call stack:
(0x2fb66f4b 0x39e7b6af 0x2fb66e25 0x3050efe3 0x151849 0x1520e5 0x3054ae9b 0x2fb32183 0x2fb31653 0x2fb2fe47 0x2fa9ac27 0x2fa9aa0b 0x3478a283 0x3233e049 0x7b621 0x3a383ab7)
libc++abi.dylib: terminating with uncaught exception of type NSException
our app is targeting iOS7... appreciate any pointers on how to make it work
This is an error with acquiring the Microphone hardware. The error log:
2013-11-16 22:00:40.402 GC[1758:60b] 22:00:40.401 ERROR: [0x3c29f18c] >aurioc> 783: failed: -10851 (enable 1, outf< 2 ch, 0 Hz, Float32, non-inter> inf< 1 ch, 44100 Hz, Int16>)
Above error happens in two cases:
Microphone Hardware was not configured correctly OR
RemoteIO was unable to acquire hardware.
This is typically happens with Simulator but can happen on the device if the microphone is inaccessible. The error can also happen if AVAudioSession is not correctly configured or is messed up. Check AVAudioSession configuration and Try deleting the iOS app, re-installing it and doing a clean build.

node.js install error require(‘http’);

I'm installing node.js on Ubuntu as per these instructions (
http://nodenode.com/post/1197688151/installing-node-js-on-ubuntu-screencast-tutorial )
and I'm recieving the following errors on the final step
I type node hello_node.js
my terminal replies
/home/joe/tmp/hello_node/hello_node.js:1
require(‘http’);
^
node.js:201
throw e; // process.nextTick error, or 'error' event on first tick
^
SyntaxError: Unexpected token ILLEGAL
at Module._compile (module.js:427:25)
at Object..js (module.js:450:10)
at Module.load (module.js:351:31)
at Function._load (module.js:310:12)
at Array.0 (module.js:470:10)
at EventEmitter._tickCallback (node.js:192:40)
So, it seems I 'require' http. Am I doing something wrong... or worse, stupid?
You're not using normal single quotes. You have:
require(‘http’);
It should be:
require('http');

Resources