johnjameson
Junior Member level 3
- Joined
- Jan 30, 2012
- Messages
- 31
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,286
- Activity points
- 1,516
Data sample rate is low,its like 1 sample a second.you should have no problem if the data rate is low, e.g. 10's of samples/second
are you plotting in response to an event which will trigger the start of plotting or are you plotting a continuous signal (e.g. like an oscilloscope) ?
I have used the Chart component at some time in the past couple of years but having trouble finding the project. Plenty of plotting using the Form Paint() method though
below is a plot of Temperature control using a Bytronic Control System Trainer (again data via USB)
**broken link removed**
View attachment 108781
note that outputing to a TextBox (as temperature values shown above screen shot) can slow the display of information (and hence graph plotting) significantly as the TextBox scrolls
Ok good.at one sample per second you should have no problems
found an example using the Chart component using the Bytronic Mechatronics trainer using proportional control of heater temperature
View attachment 108810
if you do a web search for Visual C++ Chart example you will find plenty of linksOk good.
Do you have a link to a chart component example?
chart1->Series["current temperature"]->Points->AddXY(plottime[index], plotTemperature[index]);
chart1.Series["Age"].Points.AddXY("Max",25);
// data received from serial port
private: System::Void serialPort1_DataReceived(System::Object^ sender, System::IO::Ports::SerialDataReceivedEventArgs^ e) {
static int time=0;
int data;
while(serialPort1->BytesToRead)
{
int data=serialPort1->ReadByte();
cout << "data " << data << endl;
chart1.Series["Age"].Points.AddXY(time++, data);
}
}
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.IO.Ports;
using System.IO;
//using System.Windows.Forms.DataVisualization.Charting;
namespace Serial_receive
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string[] ports = SerialPort.GetPortNames();
foreach (string port in ports)
{
comboBox1.Items.Add(port);
}
}
//
string t;
private void button2_Click(object sender, EventArgs e)
{
t = comboBox1.Text.ToString();
sErial(t);
}
//method
SerialPort sp;
void sErial(string Port_name)
{
sp = new SerialPort(Port_name, 9600, Parity.None, 8, StopBits.One);
sp.DataReceived += new SerialDataReceivedEventHandler(DataReceivedHandler);
sp.Open();
}
//
void DataReceivedHandler(object sender,SerialDataReceivedEventArgs e)
{
SerialPort sp = (SerialPort)sender;
string w = sp.ReadLine();
string FolderName = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); //set destination as your desktop
using (StreamWriter SW = new StreamWriter(FolderName + "\\test.txt", true)) //true makes it append to the file instead of overwrite
{
SW.WriteLine(w);
SW.Close();
}
//string msg = sp.ReadExisting();
if (w != String.Empty)
{
Invoke(new Action(() => richTextBox1.AppendText(w)));
}
}
}
}
Invoke(new Action(() => richTextBox1.AppendText(w)));
string w = sp.ReadLine();
Int32 number;
bool result = Int32::TryParse(w, number);
chart1.Series["Age"].Points.AddXY(time++, number);
string w = sp.ReadLine();
Int32 number;
bool result = Int32::TryParse(w, number);
chart1.Series["Age"].Points.AddXY(time++, number);
string w = sp.ReadLine();
int time=0;
Int32 number;
bool result = Int32.TryParse(w, out number);
chart1.Series["Age"].Points.AddXY(time++, number);
using System.Windows.Forms.DataVisualization.Charting;
this.chart1.SaveImage("C:\\Users\\johnjames\\Desktop\\mychart.png", ChartImageFormat.Png);
I have a button on the Formmy code is C++ I guess you are using C# hence the difference
good to hear graph is working!
no idea about image - I have never tried saving a chart as an image - will give it a go
are you trying to save the image in the serialport event handler?
private: System::Void chartButton_Click(System::Object^ sender, System::EventArgs^ e) {
chart1->SaveImage("C:\\temp\\mychart.png", ChartImageFormat::Png);
}
Ya I did the same except its also closes the serial port as wellI have a button on the Form
View attachment 108898
and when I click the button it saves the image - the event handler is
Code:private: System::Void chartButton_Click(System::Object^ sender, System::EventArgs^ e) { chart1->SaveImage("C:\\temp\\mychart.png", ChartImageFormat::Png); }
private void button3_Click(object sender, EventArgs e)
{
sp.Close();
this.chart1.SaveImage("C:\\temp\\mychart.png", ChartImageFormat.Png);
}
#include <REG51.H> /* special function register declarations */
#include <stdio.h> /* prototype declarations for I/O functions */
void serial_init(void);
//-------------------------------------------------
//Setup the serial port for 9600 baud at 11.0592MHz.
//-------------------------------------------------
void serial_init(void)
{
SCON = 0x50; /* SCON: mode 1, 8-bit UART, enable rcvr */
TMOD |= 0x20; /* TMOD: timer 1, mode 2, 8-bit reload */
TH1 = 0xFD; /* TH1: reload value for 9600 baud @ 11.0592MHz*/
TR1 = 1; /* TR1: timer 1 run */
TI = 1; /* TI: set TI to send first char of UART */
}
unsigned char sec,sec100;
unsigned int bt,tick,r,bpm;
void msdelay(unsigned int);
void extrint (void) interrupt 0 // external Interrupt to detect the heart pulse
{
bt=tick; // number of ticks are picked
tick=0; // reset for next counting
}
void timer0 (void) interrupt 1 using 1 // Timer 0 for one second time
{
TH0 = 0xdc; //The value is taken for Ssc/100 at crystal 11.0592MHz
sec100++; // It is incremented every Ssc/100 at crystal 11.0592MHz
tick++; // This variable counts the time period of incoming pulse in Sec/100
if(tick>=3500){tick=0;} // tick are limited to less trhan 255 for valid calculation
if(sec100 >=100) // 1 sec = sec100 * 100
{
sec++;
sec100=0;
}
}
void main()
{
serial_init();
P0=0xff;
P1=0xff;
P2=0xff;
P3=0xff;
EA = 1;
TMOD = 0x21;
IT0 = 1;
EX0 = 1;
ET0 = 1;
TR0 = 1;
msdelay(1000);
msdelay(1000);
printf("Heart beat ");
msdelay(1500);
msdelay(500);
//delay(15000);
bpm=0;bt=0;
while(1)
{
if(sec >=1)
{
sec=0;
/*
The sampling time is fixed 1 sec.
A variable "tick" is incremented with one tick per 100mSc in the timer 0 interrupt routine.
Each on occurring of external interrupt the value in the "tick" is picked up
and it is set to zero for recounting.
The process continues till next external interrupt.
Formula for calculating beats per minutes (microcontroller based heartbeat monitor ) is
as tick is the time period in Sec/100. so extract the frequency of pulses at external interrupt
Frequency = (1/tick)* 100 i.e pulses /sec
Then
bpm = frequency * 60 for one minutes i.e pulses per minute
in short we can do it as
bpm = 6000/ bt
*/
if(bt >=7){
bpm = 6000/bt; // for valid output bt is limited so that it should be greater than 6
msdelay(500);
//printf("Pulse. ");
r=bpm%100;
//printf("bpm: %d\r\n", bpm);
printf(" %d\r\n", bpm);
}
else {
printf("out of range");} // otherwise bpm will be shown zero
}
}
}
void msdelay(unsigned int i)
{
//unsigned int i;
while(i --);
}
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?