Comments (11)
Some initial work was done in the stream_fix branch, but is not sufficient.
from arduino.
Wouldn't it be sufficient to just declare FirmataSerial as public member of Firmata?
from arduino.
The stream_fix branch I had created worked fine when using hardware serial, but did not work with softSerial (which implements Stream) so there was something else that needed to be done. I have not looked into it further.
Julian has done some work in his fork. I think he has working implementation that can use Ethernet and Wi-Fi. The solution may exist in his code.
Also it's worth noting that it is likely not possible to support multiple types of connections (ethernet, wi-fi, etc) in StandardFirmata and we may need separate versions for each connection type (as Julian has done except using Stream to abstract the connection). The first step is to update Firmata.cpp / Firmata.h.
from arduino.
I did review Julians FirmataEthernet and wifi-client code and I can't find anything in there that justifies to wrap the Stream used in FirmataClass just to export Streams methods to the XXXFirmata.ino code that cannot access the FirmataSerial member just because it's declared private.
Declaring FirmataSerial as public and use Firmata.FirmataSerial.write(..) instead of Serial.write() would work as well.
from arduino.
Rather than setting FirmataSerial to public, we can add this to Firmata.cpp:
// expose the write method
size_t FirmataClass::write(uint8_t c)
{
FirmataSerial.write(c);
}
and this to the public interface in Firmata.h:
size_t write(uint8_t);
I think this will work fine and accomplishes the same thing you are talking about.
The issue I was having was that at the end of Firmata.cpp a new instance of FirmataClass is declared passing the hardware Serial FirmataClass Firmata(Serial)
. This locks you into hardware serial. You are supposed to be able to change the Stream by passing a new stream into Firmata.begin(newStreamInstance)
but for some reason I was never able to verify that was working.
Julian gets around this issue by creating a new instance of FirmataClass FirmataClass FirmataEthernet(client)
in StandardFirmata passing a reference to the Ethernet stream (however I would think this would create 2 instances of FirmataClass in memory?). If there is no memory issue, then that's a valid solution.
from arduino.
the reason for lock to hardware serial as stream is, that the stream class has no virtual copy constructor. And as normal in arduino the stream is handled as a reference not as a pointer - so cpp has no chance to copy another serial stream to the compile time generated class.
See this pull request on arduino
After this change you are able to beginn(stream& serialstream)
Cheers tim
Jeff Hoefs [email protected] schrieb:
Rather than setting FirmataSerial to public, we can add this to Firmata.cpp:
// expose the write method size_t FirmataClass::write(uint8_t c) { FirmataSerial.write(c); }
and this to the public interface in Firmata.h:
size_t write(uint8_t);
I think this will work fine and accomplishes the same thing you are talking about.
The issue I was having was that at the end of Firmata.cpp a new instance of FirmataClass is declared passing the hardware Serial
FirmataClass Firmata(Serial)
. This locks you into hardware serial. You are supposed to be able to change the Stream by passing a new stream intoFirmata.begin(newStreamInstance)
but for some reason I was never able to verify that was working.Julian gets around this issue by creating a new instance of FirmataClass
FirmataClass FirmataEthernet(client)
in StandardFirmata passing a reference to the Ethernet stream (however I would think this would create 2 instances of FirmataClass in memory?). If there is no memory issue, then that's a valid solution.
Reply to this email directly or view it on GitHub:
#13 (comment)
from arduino.
in cpp it's illegal to reseat an initialized reference, so there's no way to replace FirmataSerial being a reference to Stream after it's been assigned in the constructor. Declaring FirmataSerial as pointer to Stream works fine though.
Since FirmataSerial is private anyway should be no issues with backwards-compatibility.
from arduino.
Wouldnt It bei better Titel use Thema virtual copy constructructor?
Sent from Huawei Mobile
Norbert Truchsess [email protected] schrieb:
in cpp it's illegal to reseat an initialized reference, so there's no way to replace FirmataSerial being a reference to Stream after it's been assigned in the constructor. Declaring FirmataSerial as pointer to Stream works fine though.
Since FirmataSerial is private anyway should be no issues with backwards-compatibility.
Reply to this email directly or view it on GitHub:
#13 (comment)
from arduino.
I didn't verify whether this virtual copy constructor thing actually works, but I would wan't to rely on a 4 month pull request to arduino core if I allready have a working solution that changes Firmata-code only:
Passing the reference in begin(&Stream) isn't the problem, it's the assignment to the allready initialized reference-member (which you cannot leave unititialized during construction of the Firmata-object). And actually I don't know whether it really is a good idea to clone an instance of an object that is meant to be a Singleton (since it represents a single pice of hardware). So from my point of view using a pointer as private member is the correct solution here.
Regarding this 'properly implement Stream' issue here: I don't know wether it's actually worth to implement all Stream-methods as long the only thing we actually need in Firmata-feature-classes seems to be 'write'. The code that is subclass-specific is also the code calling Firmata.begin(&Stream), so it has access to the instance of Stream anyway.
from arduino.
ntruchsess code has been merged into the dev branch. I'm opening it up for review and further testing on the firmata dev list. If there are no objections I'll merge this into master on Feb 11th.
from arduino.
Tested successfully with Serial1 on Mega and Leonardo and also with SoftwareSerial.
from arduino.
Related Issues (20)
- Analog pin as digital. HOT 3
- Analog Pins on Constant Voltage HOT 1
- Additional Firmata Java library
- Inconsistent state for additional analog pins (A6 - A11) on Arduino Leonardo HOT 1
- Pyfirmata and arduino leonardo mouse and keyboard abilities HOT 2
- T HOT 1
- Error compiling for board Arduino Uno. HOT 1
- Error compiling Firmata for board Arduino Nano Every HOT 8
- Error when compiling StandardFirmata 2.5.8 for Ardbox Analog HF + Wifi from Industrialshields HOT 2
- broken link in readme.md
- Last released version is from 2018 despite a lot of new work being merged HOT 10
- How to change TX RX pin for Nano HOT 3
- To drive a Servo what Capabilities do i need from a board? HOT 2
- Ethernet server mode versus client mode HOT 1
- Arduino HOT 1
- Arduino Nano Every doesn't report A6 and A7 on StandardFirmata HOT 3
- add Arduino UNO R4 MINIMA to boards.h please HOT 11
- [Question] How to add support for Jolly-dev to StandardFirmataWiFi HOT 9
- Firmata for Raspberry Pi Pico HOT 1
- Problem compiling firmata for Giga R1 Wifi board HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from arduino.