monami-ya-mrb / mruby-serialport Goto Github PK
View Code? Open in Web Editor NEWA mrbgem for Serial port support.
A mrbgem for Serial port support.
I am pretty new to mruby. I want to run a serialport program from my raspberry pi to a ARM Cortex M4, which has been programmed to perform some tasks upon some instructions. I want to provide the instructions from a mruby program. My build_config.rb looks like this.
############################
# Start of your build_config
MRuby::Build.new do |conf|
toolchain :gcc
conf.bins = %w(mrbc)
# mruby's Core GEMs
conf.gem 'mrbgems/mruby-bin-mirb'
conf.gem 'mrbgems/mruby-bin-mruby'
conf.gem 'mrbgems/mruby-array-ext'
conf.gem 'mrbgems/mruby-enum-ext'
conf.gem 'mrbgems/mruby-eval'
conf.gem 'mrbgems/mruby-exit'
conf.gem 'mrbgems/mruby-fiber'
conf.gem 'mrbgems/mruby-hash-ext'
conf.gem 'mrbgems/mruby-math'
conf.gem 'mrbgems/mruby-numeric-ext'
conf.gem 'mrbgems/mruby-object-ext'
conf.gem 'mrbgems/mruby-objectspace'
conf.gem 'mrbgems/mruby-print'
conf.gem 'mrbgems/mruby-proc-ext'
conf.gem 'mrbgems/mruby-random'
conf.gem 'mrbgems/mruby-range-ext'
conf.gem 'mrbgems/mruby-sprintf'
conf.gem 'mrbgems/mruby-string-ext'
# conf.gem 'mrbgems/mruby-string-utf8'
conf.gem 'mrbgems/mruby-struct'
conf.gem 'mrbgems/mruby-symbol-ext'
conf.gem 'mrbgems/mruby-time'
conf.gem 'mrbgems/mruby-toplevel-ext'
# user-defined GEMs
conf.gem :git => 'https://github.com/monami-ya-mrb/mruby-serialport.git'
end
# End of your build_config
############################
Then I aaded unistd.h and string.h in serport-impl-posix.c in mruby/build/mrbgems/mruby-serialport/src to avoid some errors of undefined function declarations. Then I did this
sudo rake
And it was successfully built.
Now I see a serialport.rb file in the test directory of the gem which is similar to what I write in ruby for serialport programming. Hence, I changed it a bit to write some characters to the serialport where my ARM Controller has been connected. My serialport.rb looks like this.
assert("serial") do
sp = SerialPort.new("/dev/ttyACM0", 115200, 8, 1, 0)
sp.read_timeout=1000
wait_time = 4
sp.puts "foobarbaz"
sp.gets == "foobarbaz\n"
list = ["f", "l", "r", "b", "s"]
list.each do |l|
sp.write(l)
sleep wait_time
end
end
After this when I read about the five ways to run a mruby program and tried the first one with mruby compiler for running pure ruby code like "mruby serialport.rb" , I get the error like this
[0] ../test/serialport.rb:1
../test/serialport.rb:1: undefined method 'assert' for main (NoMethodError)
I have been following so many forums for this. If anybody please explain me how can I achieve this, I will be obliged. ๐
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.