Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
am still new in C# and arduino, am failing to see the data i send from c# on serial monitor. below are my codes...:
Arduino:
Objective-C
#include <EEPROM.h>
#include <SoftwareSerial.h>
SoftwareSerial xbee(2, 3);
int incoming;
int id;
int rea;
int comp=0;
void setup() {
  Serial.begin(9600);
  xbee.begin( 9600 );
 }

void loop() {
  if(Serial.available())
   {
     Serial.print("hhhh");
     id = Serial.read();
     incoming = Serial.read();
     if(id!='New')
     {
     xbee.println(id);
     xbee.println(incoming);
     EEPROM.write(id, incoming);
     rea = EEPROM.read(id);
     Serial.print(id);
    }
    else
     {
      EEPROM.write(comp, incoming);
      rea = EEPROM.read(id);
      Serial.print(id);
      comp+=1;
     }
   }
}


C#:
C#
protected void Button7_Click(object sender, EventArgs e)
        {
            {
                SerialPort comPort = new SerialPort("COM3", 9600, Parity.None, 8, StopBits.One);
                try
                {
                    comPort.Open();
                    comPort.Write(TextBox1.Text);
                    comPort.Write("Delete");
                    comPort.Close();
                }
                catch (UnauthorizedAccessException ex)
                {
                    Response.Write("Error:" + ex.ToString());
                }
                try
                {
                    OleDbConnection conn = new OleDbConnection("Provider= Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("App_Data\\Stock.mdb"));
                    conn.Open();
                   Int32 ash = Convert.ToInt32(TextBox1.Text);
                    string deleteQuery = "delete from Instock where ID= '" + ash + "'";
                    OleDbCommand com = new OleDbCommand(deleteQuery, conn);
                    com.ExecuteNonQuery();
                    Response.Write("Item deleted successfully");
                    Response.Redirect("UpdateDB.aspx");
                    conn.Close();
                }
                catch (Exception ex)
                {
                    Response.Write("Error:" + ex.ToString());
                }
            }
        }
Posted
Updated 11-Mar-15 23:33pm
v2
Comments
Herman<T>.Instance 12-Mar-15 6:19am    
comPort.Write(TextBox1.Text);
comPort.Write("Delete");

No new line between the lines needed? You now can get 'EnterValueDelete' as result to send. in stead of 'Enter Value\r\nDelete'.

1 solution

This article provides working code. Save yourself some time.
Arduino, C#, and Serial Interface[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900