Developing graphical user front-end application to communicate with microcontroller system [closed] - c++

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 7 years ago.
Improve this question
I am able to establish communication between my microcontroller system and computer through serial port and TCP/IP, and able to send/ receive data.
I want to develop a graphical front-end application on my PC in which i can view some values/plot some graphs based on the data sent by my microcontroller.
I have some exposure to Visual Studio and MATLAB, and know C/C++ languages.
Which development environment should i use for the front-end development ??
Any tutorials/books/links regarding the same ??

This is actually an appendix to a comment, where I bragged about a small wrapper for charts, for creating XYPlots.
create a winform, rename it to XYPlot.
add a chart, and name it plotChart
add this as code..
now you can plot easily from your code ..
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Windows.Forms.DataVisualization.Charting;
namespace Plot
{
public partial class XYPlot : Form
{
#region constructors
public string Title
{
get
{
return this.Text;
}
set
{
this.Text = "XYPlot : " + value;
}
}
//default, used for multiplots
public XYPlot()
{
InitializeComponent();
InitializeChartStyles();
}
private void InitializeChartStyles()
{
plotChart.ChartAreas["ChartArea1"].AxisX.IsMarginVisible = false;
plotChart.ChartAreas["ChartArea1"].AxisX.MajorGrid.Enabled = false;
plotChart.ChartAreas["ChartArea1"].AxisX.MinorGrid.Enabled = false;
plotChart.ChartAreas["ChartArea1"].AxisY.MajorGrid.Enabled = false;
plotChart.ChartAreas["ChartArea1"].AxisY.MinorGrid.Enabled = false;
}
//one-offs, used for simple plots of data
public XYPlot(string name, Series series)
{
InitializeComponent();
InitializeChartStyles();
this.Add(series);
this.Show();
}
public XYPlot(string name, DataPointCollection XYpoints)
{
InitializeComponent();
InitializeChartStyles();
this.Add(name, XYpoints);
this.Show();
}
public XYPlot(string name, List<Tuple<double, double>> XYpoints)
{
InitializeComponent();
InitializeChartStyles();
this.Add(name, XYpoints);
this.Show();
}
public XYPlot(string name, List<double> X, List<double> Y)
{
InitializeComponent();
InitializeChartStyles();
this.Add(name, X, Y);
this.Show();
}
public XYPlot(string name, List<double> Y, double xIncrements = 1.0, double xOffset = 0.0)
{
InitializeComponent();
InitializeChartStyles();
this.Add(name, Y, xIncrements);
this.Show();
}
private void FormPlot_Load(object sender, EventArgs e)
{
Clear();
}
#endregion
#region getNextDefault
private List<Color> usedColors = new List<Color>();
private Color getNextDefaultColor()
{
switch(usedColors.Count)
{
case 1:
return Color.Red;
case 2:
return Color.Green;
case 3:
return Color.Black;
default:
return Color.Blue;
}
}
private Series newDefaultSeries(string Name)
{
var series = new System.Windows.Forms.DataVisualization.Charting.Series
{
Name = Name,
BorderWidth = 2,
Color = getNextDefaultColor(),
IsVisibleInLegend = true,
IsXValueIndexed = false,
ChartType = SeriesChartType.Line
};
usedColors.Add(series.Color);
return series;
}
#endregion
#region public methods
public void Clear()
{
plotChart.Series.Clear();
usedColors.Clear();
}
public Series getSeries(string Name)
{
return plotChart.Series[Name];
}
#region Add
public void Add(string Name, DataPointCollection XYpoints)
{
Series series = newDefaultSeries(Name);
plotChart.Series.Add(series);
//shallow copy
foreach (DataPoint p in XYpoints)
{
series.Points.Add(p);
}
//invalidates the old surfcace, and thus requests a redraw
plotChart.Refresh();
}
public void Add(string Name, List<Tuple<double, double>> XYpoints)
{
Series series = newDefaultSeries(Name);
plotChart.Series.Add(series);
//shallow copy
foreach (Tuple<double, double> XY in XYpoints)
{
series.Points.AddXY(XY.Item1, XY.Item2);
}
//invalidates the old surfcace, and thus requests a redraw
plotChart.Refresh();
}
public void Add(string Name, List<double> X, List<double> Y)
{
Series series = newDefaultSeries(Name);
plotChart.Series.Add(series);
if (X.Count != Y.Count)
throw new Exception("X and Y vectors must be of same length, otherwise I cannot plot them in an XY plot!");
//shallow copy
for (int i = 0; i < X.Count; i++)
{
series.Points.AddXY(X[i], Y[i]);
}
//invalidates the old surfcace, and thus requests a redraw
plotChart.Refresh();
}
public void Add(string Name, List<double> Y, double xIncrements = 1.0, double xOffset = 0.0)
{
Series series = newDefaultSeries(Name);
plotChart.Series.Add(series);
//shallow copy
if (Y != null)
{
for (int i = 0; i < Y.Count; i++)
{
double x = ((double)i) * xIncrements + xOffset;
series.Points.AddXY(x, Y[i]);
}
}
//invalidates the old surface, and thus requests a redraw
plotChart.Refresh();
}
public void Add(System.Windows.Forms.DataVisualization.Charting.Series series)
{
plotChart.Series.Add(series);
plotChart.Refresh();
}
#endregion
#region updateSeries
public void updateSeries(string Name, DataPointCollection XYpoints)
{
try
{
if (plotChart.Series[Name] == null)
Add(Name, XYpoints);
}
catch
{
Add(Name, XYpoints);
}
//shallow copy
foreach (DataPoint p in XYpoints)
{
plotChart.Series[Name].Points.Add(p);
}
//invalidates the old surfcace, and thus requests a redraw
plotChart.Refresh();
}
public void updateSeries(string Name, List<Tuple<double, double>> XYpoints)
{
try
{
if (plotChart.Series[Name] == null)
Add(Name, XYpoints);
}
catch
{
Add(Name, XYpoints);
}
//shallow copy
foreach (Tuple<double, double> XY in XYpoints)
{
plotChart.Series[Name].Points.AddXY(XY.Item1, XY.Item2);
}
//invalidates the old surfcace, and thus requests a redraw
plotChart.Refresh();
}
public void updateSeries(string Name, List<double> X, List<double> Y)
{
try
{
if (plotChart.Series[Name] == null)
Add(Name, X, Y);
}
catch
{
Add(Name, X, Y);
}
plotChart.Series[Name].Points.Clear();
if (X.Count != Y.Count)
throw new Exception("X and Y vectors must be of same length, otherwise I cannot plot them in an XY plot!");
//shallow copy
for (int i = 0; i < X.Count; i++)
{
plotChart.Series[Name].Points.AddXY(X[i], Y[i]);
}
//invalidates the old surface, and thus requests a redraw
plotChart.Refresh();
}
public void updateSeries(string Name, List<double> Y, double xIncrements = 1.0, double xOffset = 0.0)
{
try
{
if (plotChart.Series[Name] == null)
Add(Name, Y, xIncrements, xOffset);
}
catch
{
Add(Name, Y, xIncrements, xOffset);
}
plotChart.Series[Name].Points.Clear();
//shallow copy
if (Y != null)
{
for (int i = 0; i < Y.Count; i++)
{
double x = ((double)i) * xIncrements + xOffset;
plotChart.Series[Name].Points.AddXY(x, Y[i]);
}
}
//invalidates the old surface, and thus requests a redraw
plotChart.Refresh();
}
public void updateSeries(System.Windows.Forms.DataVisualization.Charting.Series series)
{
try
{
if (plotChart.Series[series.Name] == null)
Add(series);
}
catch
{
Add(series);
}
plotChart.Series[series.Name] = series;
plotChart.Refresh();
}
#endregion
#endregion
}
}

As suggested by Joe, i decided to go ahead with Qt.
The following links are useful for installing and getting started with Qt on windows.
Installation:-
https://zahidhasan.wordpress.com/2014/04/29/how-to-install-qt-4-8-mingw-and-qt-creator-on-windows-8-1/
Reference:-
http://www-cs.ccny.cuny.edu/~wolberg/cs221/qt/books/C++-GUI-Programming-with-Qt-4-1st-ed.pdf
Regards,
Abhishek.

Related

C# Else confusion

so i keep gettin an error on (else) and im not to sure what i did wrong, i cant seem to find the problem, please help, im pretty new to coding so heres the entire code i have so far
{
public float speed;
private Rigidbody2D myRigidbody;
private Vector3 change;
private Animator animator;
// Start is called before the first frame update
void Start()
{
animator = GetComponent<Animator>();
myRigidbody = GetComponent<Rigidbody2D>();
}
// Update is called once per frame
void Update()
{
change = Vector3.zero;
change.x = Input.GetAxisRaw("Horizontal") * Time.deltaTime * speed;
change.y = Input.GetAxisRaw("Vertical") * Time.deltaTime * speed;
if (change != Vector3.zero)
transform.Translate(new Vector3(change.x, change.y));
MoveCharacter();
UpdateAnimationAndMove();
}
void UpdateAnimationAndMove()
{
{
animator.SetFloat("moveX", change.x);
animator.SetFloat("moveY", change.y);
animator.SetBool("moving", true);
} else {
animator.SetBool("moving", false);
}
}
void MoveCharacter()
{
myRigidbody.MovePosition(transform.position + change.normalized * speed * Time.deltaTime);
}
}
You can't use else, without a corresponding if before it.
if(condition)
{
// IF condition is true, this gets executed
}
else
{
// ELSE this gets executed
}

Android: Alarms and IntentServices

After lots of research on implementing IntentServices and Alarms together, I've come up with this. I don't know exactly what happens with this code so I need help in knowing exactly what is going on.
public class MainActivity{
//....
public void onNewItemAdded(String[] _entry){
//...
Intent intent = new Intent(MainActivity.this, UpdateService.class);
startService(intent);
}
//....
}
public class AlarmReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
Intent startIntent = new Intent(context, UpdateService.class);
context.startService(startIntent);
}
public static final String ACTION_REFRESH_ALARM = "com.a.b.ACTION_REFRESH_ALARM";
}
public class UpdateService extends IntentService{
//...
#Override
public void onCreate() {
super.onCreate();
alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
String ALARM_ACTION = AlarmReceiver.ACTION_REFRESH_ALARM;
Intent intentToFire = new Intent(ALARM_ACTION);
alarmIntent = PendingIntent.getBroadcast(this, 0, intentToFire, 0);
}
#Override
protected void onHandleIntent(Intent intent) {
Context context = getApplicationContext();
SharedPreferences prefs = PreferenceManager
.getDefaultSharedPreferences(context);
int updateFreq = Integer.parseInt(prefs.getString(
PreferencesActivity.PREF_UPDATE_FREQ, "60"));
boolean autoUpdateChecked = prefs.getBoolean(
PreferencesActivity.PREF_AUTO_UPDATE, false);
if (autoUpdateChecked) {
int alarmType = AlarmManager.ELAPSED_REALTIME_WAKEUP;
long timeToRefresh = SystemClock.elapsedRealtime() + updateFreq
* 60 * 1000;
alarmManager.setInexactRepeating(alarmType, timeToRefresh,
updateFreq * 60 * 1000, alarmIntent);
}
else {
alarmManager.cancel(alarmIntent);
}
refreshKeywords();
}
}
My aim is to get the refreshKeywords() method to be called every minute. Also, what happens if the onNewItemAdded() method is called more than once?
Sorry if this question is stupid, I'm a beginner.
If you wish you to call refreshKeywords()method to be called every minutes why do you use AlarmManager like this,
private void ServiceRunningBackground() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT)
{
final int restartAlarmInterval = 6000;
final int resetAlarmTimer = 2*1000;
final Intent restartIntent = new Intent(this, MyService.class);
restartIntent.putExtra("ALARM_RESTART_SERVICE_DIED", true);
final AlarmManager alarmMgr = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
Handler restartServiceHandler = new Handler()
{
#Override
public void handleMessage(Message msg) {
PendingIntent pintent = PendingIntent.getService(getApplicationContext(), 0, restartIntent, 0);
alarmMgr.set(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime() + restartAlarmInterval, pintent);
sendEmptyMessageDelayed(0, resetAlarmTimer);
}
};
restartServiceHandler.sendEmptyMessageDelayed(0, 0);
}
}
Just call this method where ever you want and set the time accordingly

Can't increment integer in Cocos2d-x V 3.0

I need to increment an integer.I have this code here :
Utils.h :
class Utils{
static HUD* hudLayer();
static Layer* layerWithTag(int tag);
};
Utils.cpp :
HUD* Utils::hudLayer(){
return (HUD*)Utils::layerWithTag(TAG_HUD);
}
Layer* Utils::layerWithTag(int tag)
{
Scene *sc = Director::getInstance()->getRunningScene();
if (sc->getTag() == TAG_GAME_SCENE) {
Layer *layer = (Layer *)sc->getChildByTag(tag);
return layer;
}
return NULL;
}
HUD.h
class HUD : public Layer{
public:
int score1;
Label* scoreLabel1;
virtual bool init();
void didScore();
CREATE_FUNC(HUD);
};
HUD.cpp :
bool HUD::init(){
if(!Layer::init()){return false;}
score1 = 0;
scoreLabel1 = Label::createWithSystemFont(CCString::createWithFormat("Score : %d",score1)->getCString(), “Arial“, 64);
scoreLabel1->setAnchorPoint(Point(0.0f, 1.0f));
scoreLabel1->setPosition(Point(20, Utils::s().height-10));
this->addChild(scoreLabel1);
return true;
}
void HUD::didScore(){
score1+=10; // Error HERE after coming from onTouchBegan (says parentis null)
scoreLabel1->setString(CCString::createWithFormat("Score : %d",score1)->getCString());
}
In GameScene.h now i have this in onTouchBegan method :
bool GameScene::onTouchBegan(cocos2d::Touch *touch, cocos2d::Event *unused_event)
{
Point location = touch->getLocationInView();
location = Director::getInstance()->convertToGL(location);
if(location.x < 300.0f){
Utils::hudLayer()->didScore();
}
return true;
}
What am i doing wrong here ?
I can increment an integer in V 2.x the same way but not in V 3.0 . WHY ?
In cocos2d-x v3 is a new listener system for events (touches, accelerometr etc.), you need to create listener for getting touches. In GameScene::init you should put something like that
auto listener1 = EventListenerTouchOneByOne::create();
listener1->setSwallowTouches(true);
listener1->onTouchBegan = CC_CALLBACK_2(GameScene::onTouchBegan, this);
this->getEventDispatcher()->addEventListenerWithSceneGraphPriority(listener1, this);
Look at:
http://www.cocos2d-x.org/wiki/EventDispatcher_Mechanism

Adding Scaletempo to a playbin with Vala

I'm having trouble trying to use scaletempo with a playbin in Vala. I've created the playbin, and then created a bin to store the additional plugins swapping out the default audio sink. The example below I grabbed from pyTranscribe and converted to Vala but the Element.link_many is causing an error and I'm not quite sure why.
Am I going about this the right way? Does anybody have any other suggestions?
/* SoundPlayerBackend.vala */
/* Modified code from Damien Radtke's site. http://damienradtke.org/ */
using Gst;
public class SoundPlayerBackend {
//Constants
const double PLAYBACK_RATE_MODIFIER = 2.0;
const int SEEK_SECONDS = 10;
// Method delegates for notifying SoundPlayer about certain events
protected delegate void NotifyEos();
protected delegate void NotifyError(string message);
// Pointer to our EOS delegate
protected NotifyEos on_eos;
// Pointer to our Error delegate
protected NotifyError on_error;
public static void main(string[] args){
var soundplayer = new SoundPlayerBackend();
Gst.init(ref args);
soundplayer.setUri("file:///home/codenomad/Desktop/player-project/hurricane.mp3");
soundplayer.play();
string stop = stdin.read_line ();
while (stop != "stop") {
if (stop == "pause") { soundplayer.pause(); }
else if (stop == "play") { soundplayer.play(); }
stop = stdin.read_line ();
}
}
// Read-only reference to the current sound object
public dynamic Element sound { get; private set; }
// Read-only "is playing" property
public bool is_playing { get; private set; default = false; }
// Read-only "rate" property
public double rate { get; private set; default = 1; }
public void setUri(string uri) {
// Make sure any existing allocated resources are freed
if (sound != null)
sound.set_state(Gst.State.NULL);
sound = ElementFactory.make("playbin2", "playbin");
sound.uri = uri;
var audiobin = new Bin("audioline");
var scaletempo = ElementFactory.make("scaletempo", "scaletempo");
var convert = ElementFactory.make("audioconvert", "convert");
var resample = ElementFactory.make("audioresample", "resample");
var audiosink = ElementFactory.make("autoaudiosink", "audiosink");
audiobin.add_many(scaletempo, convert, resample, audiosink);
//edited based on comment below
//Element.link_many(scaletempo, convert, resample, audiosink);
scaletempo.link_many(convert, resample, audiosink);
var pad = scaletempo.get_pad("sink");
audiobin.add_pad(new GhostPad("sink", pad));
sound.set_property("audio-sink", audiobin);
sound.get_bus().add_watch(on_event);
}
// Play the sound
public void play() {
sound.set_state(State.PLAYING);
print("Playing\n");
is_playing = true;
}
// Pause it
public void pause() {
sound.set_state(State.PAUSED);
is_playing = false;
print("Paused\n");
}
// Event bus, listens for events and responds accordingly
protected bool on_event(Gst.Bus bus, Message message) {
switch (message.type) {
case MessageType.ERROR:
GLib.Error err;
string debug;
sound.set_state(Gst.State.NULL);
is_playing = false;
message.parse_error(out err, out debug);
on_error(err.message);
break;
case MessageType.EOS:
sound.set_state(Gst.State.READY);
is_playing = false;
on_eos();
break;
default:
break;
}
return true;
}
}
I tried using the same code making everything static and received the same outcome/error below:
SoundPlayerBackend.vala:121.9-121.67: error: Access to instance member `Gst.Element.link_many' denied
Element.link_many(scaletempo, convert, resample, audiosink);
Thanks in advance!
That line should read
scaletempo.link_many(convert, resample, audiosink);

BlackBerry ObjectListField

I am developing a BlackBerry project under JDE 4.6.1. The problem is that when adding an item to the list, a NullPointerException is thrown from method measureListRow
NPE callstack:
CustomerListField(ObjectListField).measureListRow(ListField, int, int)
CustomerListField(ListField).layout(int, int)
CustomerListField(ObjectListField).layout(int, int)
VList(Manager).layoutChild(Field, int, int)
Notes:
db_.getDataAccess() - database
getListCount - getting the number of items in the list
CustomerListItem - the structure of a list item
And the relevant code:
public class CustomerListField extends ObjectListField implements ListFieldCallback, ChangeListener {
private PagedDataFetcher dataFetcher = new CustomerListPagedDataFetcher();
…
public CustomerListField() {
try {
super.set(new Object[db_.getDataAccess().getListCount()]);
} catch (Throwable e) {
}
}
public void drawListRow(ListField listField, Graphics g, int index, int y,
int width) {
CustomerListItem currentRow = (CustomerListItem) get(listField, index);
…
}
public Object get(ListField list, int index) {
try {
return dataFetcher.getRowAtIndex(index);
} catch (Throwable e) {
return null;
}
}
// To obtain the data
public class CustomerListPagedDataFetcher extends PagedDataFetcher {
protected Vector get(int from, int to) throws Exception {
return DataAccess.getDataAccess().getLists(from, to);
}
}
/**
* layout for list
*/
final class VList extends VerticalFieldManager {
private final ObjectListField list;
int maxHeight = Display.getHeight() - getFont().getHeight() * 2 - 5;
VList(ObjectListField list) {
super(Manager.VERTICAL_SCROLLBAR | Manager.VERTICAL_SCROLL);
this.list = list;
}
public int getPreferredHeight() {
return 45 * list.getSize();
}
protected void sublayout(int width, int height) {
super.sublayout(width, height);
setExtent(width, maxHeight);
}
}
If you're getting a NullPointerException in measureRowList, the first place I'd look is the source of that method to see what null value is being dereferenced. It looks like you didn't include the source for that method though.