latch "0" and save next values to array in serialport??
-
-
i send 6 + 1 (6 variables and one starting byte)data from microcontroller to c#.first character is ZERO .and it means next value is first value.another meaning zero will be starting byte.how can i latch zero than save other variables to my array?
What are these 6 variables you're talking about? Ints of 4 bytes? Ints of 2 bytes? Just bytes?
Cheers, Vıkram.
After all is said and done, much is said and little is done.
-
What are these 6 variables you're talking about? Ints of 4 bytes? Ints of 2 bytes? Just bytes?
Cheers, Vıkram.
After all is said and done, much is said and little is done.
-
OK, now how do you get this data into your application? Do you have a method that gets passed these 7 bytes as an array? Are you reading it as a stream? I'm trying to help, but you're not providing enough information. Unfortunately, I don't have access to webmail at work, so I can't see the reply notifications :(
Cheers, Vıkram.
After all is said and done, much is said and little is done.
-
OK, now how do you get this data into your application? Do you have a method that gets passed these 7 bytes as an array? Are you reading it as a stream? I'm trying to help, but you're not providing enough information. Unfortunately, I don't have access to webmail at work, so I can't see the reply notifications :(
Cheers, Vıkram.
After all is said and done, much is said and little is done.
All of my microcontroller codes : #include "C:\Documents and Settings\yasin\Desktop\yeni\deneme3.h" #include <16F877.h> #device adc=8 #use delay(clock=20000000) #fuses NOWDT,HS, NOPUT, NOPROTECT, BROWNOUT, NOLVP, NOCPD, NOWRT, NODEBUG #use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8) void main() { int8 value1,value2,value3,value4,value5,value6; int8 start; value1=1; value2=2; value3=3; value4=4; value5=5; value6=6; start=0; setup_adc_ports(NO_ANALOGS); setup_adc(ADC_OFF); setup_psp(PSP_DISABLED); setup_spi(FALSE); setup_counters(RTCC_INTERNAL,RTCC_DIV_1); setup_timer_1(T1_DISABLED); setup_timer_2(T2_DISABLED,0,1); for(;;) { delay_ms(10); putc(start); putc(value1); putc(value2); putc(value3); putc(value4); putc(value5); putc(value6); } C# codes: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.IO.Ports; namespace serial { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { serialPort1.DataReceived += new SerialDataReceivedEventHandler(this.serialPort1_DataReceived); if (serialPort1.IsOpen) serialPort1.Close(); serialPort1.ReceivedBytesThreshold = 1; serialPort1.DataBits = 8; serialPort1.Parity = System.IO.Ports.Parity.None; serialPort1.StopBits = System.IO.Ports.StopBits.One; serialPort1.BaudRate = 9600; serialPort1.PortName = "COM4"; serialPort1.Open(); } public delegate void updatetexboxes(); byte[] received ={ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; int i=0; private void serialPort1_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e) { serialPort1.Read(received, i, 1); //i dont know which codes can be written here!!!! //than i ll update my variables. this.Invoke(new updatetexboxes(this.updatetext)); } private void updatetext() { textBox1.Text = received[1].ToString(); textBox2.Text = received[2].ToString(); textBox3.Text = received[3].ToString(); textBox4.Text = received[4].ToString()
-
All of my microcontroller codes : #include "C:\Documents and Settings\yasin\Desktop\yeni\deneme3.h" #include <16F877.h> #device adc=8 #use delay(clock=20000000) #fuses NOWDT,HS, NOPUT, NOPROTECT, BROWNOUT, NOLVP, NOCPD, NOWRT, NODEBUG #use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8) void main() { int8 value1,value2,value3,value4,value5,value6; int8 start; value1=1; value2=2; value3=3; value4=4; value5=5; value6=6; start=0; setup_adc_ports(NO_ANALOGS); setup_adc(ADC_OFF); setup_psp(PSP_DISABLED); setup_spi(FALSE); setup_counters(RTCC_INTERNAL,RTCC_DIV_1); setup_timer_1(T1_DISABLED); setup_timer_2(T2_DISABLED,0,1); for(;;) { delay_ms(10); putc(start); putc(value1); putc(value2); putc(value3); putc(value4); putc(value5); putc(value6); } C# codes: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.IO.Ports; namespace serial { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { serialPort1.DataReceived += new SerialDataReceivedEventHandler(this.serialPort1_DataReceived); if (serialPort1.IsOpen) serialPort1.Close(); serialPort1.ReceivedBytesThreshold = 1; serialPort1.DataBits = 8; serialPort1.Parity = System.IO.Ports.Parity.None; serialPort1.StopBits = System.IO.Ports.StopBits.One; serialPort1.BaudRate = 9600; serialPort1.PortName = "COM4"; serialPort1.Open(); } public delegate void updatetexboxes(); byte[] received ={ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; int i=0; private void serialPort1_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e) { serialPort1.Read(received, i, 1); //i dont know which codes can be written here!!!! //than i ll update my variables. this.Invoke(new updatetexboxes(this.updatetext)); } private void updatetext() { textBox1.Text = received[1].ToString(); textBox2.Text = received[2].ToString(); textBox3.Text = received[3].ToString(); textBox4.Text = received[4].ToString()
You've only given some of the C# code. Look at a file called Form1.Designer.cs, or something similar. Here are some tips to get you started: 1. I don't see a definition for serialPort1. What type is it? 2. What does serialPort1.Read() return, if anything?
Cheers, Vıkram.
After all is said and done, much is said and little is done.
-
You've only given some of the C# code. Look at a file called Form1.Designer.cs, or something similar. Here are some tips to get you started: 1. I don't see a definition for serialPort1. What type is it? 2. What does serialPort1.Read() return, if anything?
Cheers, Vıkram.
After all is said and done, much is said and little is done.