Scratch-vm: How can I make a extenstion that support serialport devices to scratch?

Created on 19 Dec 2018  路  9Comments  路  Source: LLK/scratch-vm

Expected Behavior

If I want to use scratch for my own Harware devices which has serialport on it ,How could I write a javascript extention that support it?

Actual Behavior

Actually I try to use npm install serialport ,and I write a .js file that opens a serialpor, But I can just run this file in node.js.
How could I add this to scratch-vm or scratch-gui?

Steps to Reproduce

If you want to try this , you can run :
sudo npm install -g serialport
write a file : serialport.js
const SerialPort = require('serialport')

Operating System and Browser

Ubuntu 16.04 Google Chorm 71.0.3578.98

help wanted question

All 9 comments

@wwj718 https://scratch3-adapter-docs.just4fun.site/

Thanks for your reply. I'm not farmilar with how to use your python files into Scratch3.0 .

@XueYuSky The document is here(chinese), I just replied to your mail :)

I chose to use node.js (serialport) and redirect the data received from the serial on a websocket connection. It works very well!

@cotestatnt Thanks a lot . At first,I also use node.js(serialport) and can read and write data on a serialport by standalone main.js. But the problem is I can't redirect the data received from the serial on a websocket connection. I am learning websocket and will update this method after I do that.
If you have good examples to show how to do this, welecom to post your method.

@XueYuSky , here you can find my actually implementation. Please take in mind, I'm not an expert programmer (especially with Javascript), I'm sure there's a better method!
For example, doing all the jobs in the same extension script 'index.js' so that it is not necessary to start the wsServer.js script manually.

https://github.com/cotestatnt/arduino-plus-scratch3

@XueYuSky , here you can find my actually implementation. Please take in mind, I'm not an expert programmer (especially with Javascript), I'm sure there's a better method!
For example, doing all the jobs in the same extension script 'index.js' so that it is not necessary to start the wsServer.js script manually.

https://github.com/cotestatnt/arduino-plus-scratch3

Thank you so much , I finally make it after I change some code from you. Because the hardware is not arduino. I designed it by myself with special protocol. Your answer really helped me!

scrarachserial1
I write a serial extension recently,it can open a serial port ,send messages,receive messages. But it still has some bugs to fix.

scrarachserial1
I write a serial extension recently,it can open a serial port ,send messages,receive messages. But it still has some bugs to fix.

Would you mind sharing the link please? Thanks in advance.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jwzimmer picture jwzimmer  路  4Comments

Micircle picture Micircle  路  5Comments

griffpatch picture griffpatch  路  6Comments

cwillisf picture cwillisf  路  4Comments

kchadha picture kchadha  路  6Comments