I'm trying to show Myo datas on a chart using c#. I receive the data from Myo and sends it to chart but it won't show anything. Examples on the net hasn't helped me! this is the code (I think i have thread but don't know much, producer class receives the raw emg data from myo and Form1 is supposed to show it):
using MyoSharp.Communication;
using MyoSharp.Device;
using MyoSharp.Exceptions;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Windows.Forms.DataVisualization.Charting;
namespace MyoThings
{
public partial class Form1 : Form
{
int i = 0;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Producer producer = new Producer();
producer.StartConnection();
}
public void receiveData(int data)
{
Console.WriteLine(data);
chart1.Series[0].Points.Add(i++, data); // won't add anything -
chart1.Invalidate();
}
}
class Producer
{
Chart chart = new Chart();
public void StartConnection()
{
using (var channel = Channel.Create(ChannelDriver.Create(ChannelBridge.Create(),
MyoErrorHandlerDriver.Create(MyoErrorHandlerBridge.Create()))))
{
using (var hub = Hub.Create(channel))
{
hub.MyoConnected += (sender, e) =>
{
Console.WriteLine($"Myo Connected, handle: {e.Myo.Handle}");
e.Myo.Vibrate(VibrationType.Short);
e.Myo.EmgDataAcquired += Myo_EmgDataAcquired;
e.Myo.SetEmgStreaming(true);
};
channel.StartListening();
//int i = 0;
while (true)
{
}
}
}
}
private static void Myo_EmgDataAcquired(object sender, EmgDataEventArgs e)
{
//Console.WriteLine(e.EmgData.GetDataForSensor(1));
Producer producer = new Producer();
Form1 form = new Form1();
//sends data of myo to chart
form.receiveData(e.EmgData.GetDataForSensor(1));
}
}
}