Comments (13)
Using Standard Firmata with an Arduino Due, I had no luck at all using 'GetPinState' to work on either analog or digital pins - does anyone have more luck or more info on this?
But I've been successfully using the ReportMode mechanism, wherein you subscribe to changes in analog state, e.g.
m_ArduinoSession.SetAnalogReportMode(chan, state);
m_AnalogStateMonitor = m_ArduinoSession.CreateAnalogStateMonitor();
var unsubscriber = m_AnalogStateMonitor.Subscribe(this));
and an event handler like this:
// Implementation of: IObserver<AnalogState>.OnNext.
public void OnNext(AnalogState state)
{
// The new analog value is in 'state'Level'.
}
Sorry I haven't got time to do a complete example, but maybe you can piece it together from the above?
HTH,
Jim
from arduino.
It is late here, but I will take a closer look at this in the morning. It looks promising, and I do appreciate you taking the time to share this information.
Again, Thank You.
Best Regards,
Rhett
from arduino.
Hi Jim,
I looked at the snippet you posted. I was not able to get it to work. I am sure it is good code, but I should have mentioned in my original post that I am entry level in programming. My original goal was just to have a ProgressBar control display the analog input (A0) value (I.e. myProgressBar.Value = myArduinoAnalogInputPin's value). I think this should be easy to do, but after many hours of trying to get this to happen, I have been unsuccessful at getting my head wrapped around what is and what should be happening here. Everything in this solidsoils library has a tutorial for using with C# out there with one exception... anything analog.
I was having trouble with subscribing and the event handler. I could not get the .OnNext to show up in the intellisense and the "this" keyword threw errors on converting between form and AnalogState.
I wish I knew more about this to give better information.
If you could give a brief description of the sequence of events that should take place for this, that would be greatly appreciated. If you do not have time to mess with it, I understand also.
Thank You Sir.
Rhett
from arduino.
@ Angelusvetus
Hi Rhett,
Just a quickie for now re. the 'OnNext' and 'this' problems. You need to also add the relevant interfaces to the class definition (the class where you have the 'OnNext' method), e,.g.
public class YourFirmataDevice : YourDevice, IObserver<DigitalPortState>, IObserver<AnalogState>
{
I'm assuming that your class derives from another class of yours called 'YourDevice',, otherwise it's just:
public class YourFirmataDevice : IObserver<DigitalPortState>, IObserver<AnalogState>
{
Hope this helps a bit!
Jim
from arduino.
Hi Jim,
That did help tremendously!
I was able to get the state of one analog input to be displayed in a ProgressBar on my form. It is stable and responsive. Now, I will try to add the other five analog inputs and five more ProgressBars to reflect the states of all the analog inputs on my Arduino board onto my form displayed on my PC. I am not sure how to differentiate the inputs/channels with only one .OnNext(AnalogState state). That is my next mountain to climb.
I very much appreciate the help you have provided Sir.
Best Regards,
Rhett
from arduino.
That's great.
Check out: state.Channel !
And data in state.Level.
from arduino.
Hi Jim,
You are a Genius!
I am almost ashamed to admit how many hours/days I spent with no real success.
The pieces of information you provided paved the way to success!
More importantly, I now have a much better understanding of how the software works with the hardware.
I do appreciate and thank you for the information and help you provided.
Again Thank You Sir!
Best Regards,
Rhett
from arduino.
My pleasure!
I wish I was a genius...
If you're in that 'OnNext' method in Visual Studio, you can just type 'state.' and a list of state's members should popup (Intellisense).
Best,
Jim
from arduino.
Using Standard Firmata with an Arduino Due, I had no luck at all using 'GetPinState' to work on either analog or digital pins - does anyone have more luck or more info on this?
But I've been successfully using the ReportMode mechanism, wherein you subscribe to changes in analog state, e.g.
m_ArduinoSession.SetAnalogReportMode(chan, state); m_AnalogStateMonitor = m_ArduinoSession.CreateAnalogStateMonitor(); var unsubscriber = m_AnalogStateMonitor.Subscribe(this));
and an event handler like this:
// Implementation of: IObserver<AnalogState>.OnNext. public void OnNext(AnalogState state) { // The new analog value is in 'state'Level'. }
Sorry I haven't got time to do a complete example, but maybe you can piece it together from the above?
HTH, Jim
How hard can it be to spend 20 minutes and provide a working example?
from arduino.
Everyone here is way too polite to people who don't finish the job they've started.
If you post an answer, just post full files, and not "add this line" and a couple of pagedowns later "add this line too".
from arduino.
So many "geniuses" and two years later after the initial response, there is no code example. I hate open-source projects.
from arduino.
Hi @zoopyserg, the discussion above is about a solution built on Observable properties. It is a concept belonging to MVVM (Model View Viewmodel) as it is used in Windows Presentation Foundation. When you are not familiar with MVVM you may be better off by using the good old events.
You can request an Arduino board to send pin state updates by issueing an IFirmata.SetDigitalReportMode(int portNumber, bool enable)
command. The board's response messages can then be read by attaching an event handler to event IFirmata.DigitalStateReceived
.
from arduino.
This file from the SolidSolis repo contains a full working example of both Analog and Digital signal processing:
https://github.com/SolidSoils/Arduino/blob/master/Solid.Arduino.Run/Program.cs
Everything that starts with this:
static void SimpelTest
And until the end of the file.
But out of the box, it is also incomplete (sets up the callbacks, but starts listening for only digital pins).
To get it to work for analog pins, people need to toss in this line somewhere inside static void SimpelTest
:
firmata.SetAnalogReportMode(5, true);
Which then makes that code magically trigger the callback private void Session_OnAnalogStateReceived
which contains the correct recording of an analog pin.
After that I need to solve the problems with parallel threads and busy open Arduino connections which is still work in progress.
This is the answer I was looking for.
I'm a hero here.
from arduino.
Related Issues (20)
- Documentation unsupported error HOT 7
- DigitalPortState holds wrong port HOT 1
- IServiceLocator not referenced in Solid.Arduino.Monitor HOT 5
- io exception in site test example HOT 3
- EnhancedSerialConnection.Find(); Results In Timeout When Arduino Is Connected HOT 2
- Initialize Connection To Specific COM Port HOT 1
- Severe performance impact of Debug.Write in SerialDataReceived HOT 3
- .net core 3.0 support for Raspberry Pi HOT 3
- stepper motors support HOT 1
- System.NotImplementedException: 'Commandbyte 8D is not implemented.' HOT 5
- Reading analog input value from Arduino HOT 1
- Migrate to netstandard2.0 HOT 4
- Arduino Leonardo Requests DTR to be high HOT 1
- Sysex Command HOT 5
- Event OnDigitalStateReceived don't work in Winforms HOT 9
- Not working on ESP8266
- EnhancedSerialConnection.Find() does not find the connected Arduino Nano Every. HOT 1
- Different behavior on Ubuntu than Windows
- .NETframework does not implement .NETstandard2.1 HOT 1
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.