Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added TwoPortRead example #16

Merged
merged 1 commit into from Jul 20, 2022
Merged

added TwoPortRead example #16

merged 1 commit into from Jul 20, 2022

Conversation

tigoe
Copy link
Contributor

@tigoe tigoe commented Oct 21, 2015

Added a test to see if two ports can be opened at the same time. This is an occasional use case (I see t a couple times a year). It works, but the incoming data’s not consistent. Have only tested quickly, but I suspect there might be an issue with readStringUntil().

@vanevery
Copy link
Member

It only appears to work. The second port isn't actually opened. The server only supports one port at at time and assumes second "open" calls to be requesting the same port. The server should be changed to generate an error in this case so it doesn't appear to work.

@vanevery
Copy link
Member

The way to do this that would work at the moment is to run the server on two different ports and connect to it explicitly in the constructor. I should add a port argument in the command line version of the server.

var serial1 = new p5.SerialPort("localhost", 8081);
var serial2 = new p5.SerialPort("localhost", 8082);

serial1.open("/dev/blah blah");
serial2.open("/dev/halb halb");

@tigoe
Copy link
Contributor Author

tigoe commented Oct 21, 2015

Good to know, thanks. Coincidentally it came up in my afternoon class.

I wonder if it's worthwhile to do a Friday a bit like synthesis day (except
optional) to introduce node? I bet a handful might find it useful for
finals.

Meanwhile I'm also going to try p5.serialport without the server too. Your
refactoring might make it work with any web socket server, no?

T.

sent on the go. please excuse brevity and mistaken auto corrections
On Oct 21, 2015 9:51 AM, "Shawn Van Every" notifications@github.com wrote:

The way to do this that would work at the moment is to run the server on
two different ports and connect to it explicitly in the constructor. I
should add a port argument in the command line version of the server.

var serial1 = new p5.SerialPort("localhost", 8081);
var serial2 = new p5.SerialPort("localhost", 8082);

serial1.open("/dev/blah blah");
serial2.open("/dev/halb halb");


Reply to this email directly or view it on GitHub
#16 (comment)
.

@vanevery
Copy link
Member

Yeah, the p5.serialport code is pretty agnostic to the socket server. It sends and expects the data in a certain format but nothing all that unique about it.

The main code for receiving data from the server is on line 118:
this.socket.onmessage
with the real work being done on starting on line 132 with a message coming through that looks like:
{method: "data", data: bytes of data}

The sending portion is in the "emit" method on line 195.
Sending messages such as:
{method: 'write', data: bytes of data to write}

@montoyamoraga
Copy link
Member

i am accepting this pull request, and adding it to the examples list, and will test it to check it works with the current versions of p5.serialport.js and p5.js :)

@montoyamoraga montoyamoraga merged commit 0076886 into p5-serial:main Jul 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants