Hej alle
Er der nogle der kan hjælpe mig at få vist nogle data fra en mikroprocessor AVR 128.
Jeg ønsker at få vist nogle bestemte data i textBox2.
Koden herunder viser alle data (get 27 bytes of MS runtime) i textbox 1 som hentes men jeg ønsker kun at se et bit i hver textbox.
Tak Peter
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Threading;
using System.Windows.Forms;
namespace TestMegasquirt
{
public partial class Form1 : Form
{
byte[] buffer = new byte[1000];
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
ClosePort();
}
void ReadPort()
{
}
void OpenPort()
{
SerialPort1.PortName = "COM1";
SerialPort1.Open();
SerialPort1.ReadTimeout = 400;
}
void ClosePort()
{
if (SerialPort1.IsOpen) {
SerialPort1.Close();
}
}
private void bnRead_Click(object sender, EventArgs e)
{
if (SerialPort1.IsOpen) {
timer1.Enabled = true;
}
else {
OpenPort();
timer1.Enabled = true;
}
}
private void bnStop_Click(object sender, EventArgs e)
{
timer1.Enabled = false;
ClosePort();
}
char[] sbuf = new char[5];
int bytes = 0;
int bytesRead = 0;
void readConst()
{
// get 128 bytes of standard MS constants
bytes = 128;
bytesRead = 0;
sbuf[0] = 'V';
SerialPort1.DiscardInBuffer();
SerialPort1.Write(sbuf, 0, 1);
Thread.Sleep(150);
try {
bytesRead = SerialPort1.Read(buffer, 0, bytes);
}
catch (Exception) {
}
}
void readRuntime()
{
// get 27 bytes of MS runtime
bytes = 27;
bytesRead = 0;
sbuf[0] = 'A';
SerialPort1.DiscardInBuffer();
SerialPort1.Write(sbuf, 0, 1);
Thread.Sleep(150);
try {
bytesRead = SerialPort1.Read(buffer, 0, bytes);
}
catch (Exception) {
}
}
private void timer1_Tick(object sender, EventArgs e)
{
readRuntime();
//readConst();
Display();
}
private void Display()
{
textBox1.Clear();
string s = "";
for (int i = 0; i < bytesRead; i++) {
s += buffer[i].ToString();
s += "\\r\\n";
}
textBox1.Text = s;
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
private void textBox2_TextChanged(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
Form2 xx = new Form2();
xx.ShowDialog();
}
}
}