Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. latch "0" and save next values to array in serialport??

latch "0" and save next values to array in serialport??

Scheduled Pinned Locked Moved C#
questioncsharphardwaredata-structures
7 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Mir_As
    wrote on last edited by
    #1

    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?

    V 1 Reply Last reply
    0
    • M Mir_As

      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?

      V Offline
      V Offline
      Vikram A Punathambekar
      wrote on last edited by
      #2

      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.

      M 1 Reply Last reply
      0
      • V Vikram A Punathambekar

        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.

        M Offline
        M Offline
        Mir_As
        wrote on last edited by
        #3

        each of data is just one byte.(between 0-255)

        V 1 Reply Last reply
        0
        • M Mir_As

          each of data is just one byte.(between 0-255)

          V Offline
          V Offline
          Vikram A Punathambekar
          wrote on last edited by
          #4

          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.

          M 1 Reply Last reply
          0
          • V Vikram A Punathambekar

            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.

            M Offline
            M Offline
            Mir_As
            wrote on last edited by
            #5

            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()

            V 1 Reply Last reply
            0
            • M Mir_As

              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()

              V Offline
              V Offline
              Vikram A Punathambekar
              wrote on last edited by
              #6

              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.

              M 1 Reply Last reply
              0
              • V Vikram A Punathambekar

                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.

                M Offline
                M Offline
                Mir_As
                wrote on last edited by
                #7

                i use serialport component from toolbox.i get datas.cause i use breakpoints so i see my variables content.

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups