Giter VIP home page Giter VIP logo

Comments (13)

jacobussystems avatar jacobussystems commented on June 26, 2024 1

@Angelusvetus

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.

Angelusvetus avatar Angelusvetus commented on June 26, 2024

@jacobussystems

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.

Angelusvetus avatar Angelusvetus commented on June 26, 2024

@jacobussystems

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.

jacobussystems avatar jacobussystems commented on June 26, 2024

@ 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.

Angelusvetus avatar Angelusvetus commented on June 26, 2024

@jacobussystems

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.

jacobussystems avatar jacobussystems commented on June 26, 2024

That's great.

Check out: state.Channel !

And data in state.Level.

from arduino.

Angelusvetus avatar Angelusvetus commented on June 26, 2024

@jacobussystems

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.

jacobussystems avatar jacobussystems commented on June 26, 2024

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.

zoopyserg avatar zoopyserg commented on June 26, 2024

@Angelusvetus

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.

zoopyserg avatar zoopyserg commented on June 26, 2024

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.

zoopyserg avatar zoopyserg commented on June 26, 2024

So many "geniuses" and two years later after the initial response, there is no code example. I hate open-source projects.

from arduino.

SolidSoils avatar SolidSoils commented on June 26, 2024

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.

zoopyserg avatar zoopyserg commented on June 26, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.