Posts Tagged ‘visual studio’
26
mar

Hi all,
as my first experiment, an arduino connected to COM9 to recognize incoming mails from google mail (gmail)!!
Very easy to do!!!





As experiment I connected Arduino board to a breadboard with a GREEN LED and a PIEZO SPEACKER in this way:


Arduino Gmail Notifier

Rif: albertopasca.it

I connected the LED to Arduino pin 13 and speacker to arduino pin 12.

The code sended to Arduino ATMEGA328 chip was this:
-It was programmed to read serial port data (sended from server by C# app)-

Arduino CODE (C):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/* green led*/
const int ledPin = 13;

/* piezo */
const int beepPin = 12;

/* check gmail mails :D */
int mail = LOW;
int val;

void setup()
{
  /* setup pin iniziale */
  pinMode(ledPin, OUTPUT);      
  pinMode(beepPin, OUTPUT);
 
  Serial.begin(9600);
 
  mail = HIGH;
}

void loop()
{
  /* loop gmail check mails */
  val = Serial.read();
  Serial.println(val, BYTE);

  if (val == 110) { // "n" = 110 in dec from ascii
    mail = HIGH;
  } else if (val == 109) { //109 = "m" in dec from ascii
    mail = LOW;

    /* accendo il led*/
    digitalWrite(ledPin, HIGH);

    /* fischio avviso mail
        tipo fischio di fine
        partita di calcio */

    digitalWrite(beepPin, HIGH);
    delay(500);
    digitalWrite(beepPin, LOW);
    delay(200);
    digitalWrite(beepPin, HIGH);
    delay(500);
    digitalWrite(beepPin, LOW);
    delay(200);
    digitalWrite(beepPin, HIGH);
    delay(3000);

    /* rimetto tutto a posto */
    digitalWrite(beepPin, LOW);
    digitalWrite(ledPin, LOW);
  }  
}

After that Arduino code was uploaded to chip and programmed successfully, I make a C# app that loop on “while true” to check google mails every 10 seconds.
If there is a new incoming mail, it send to serial port (COM9, 9600) a char, “m” for new mail and “n” for NO mail that are interpreted from arduino respectly to 109 and 110 in DEC format.
Arduino CODE recognize the DEC (ascii code, m||n) and executed code relatively condition.
If there was a “m” code, it send an HIGH signal (1) to GREEN LED and an HIGH to speacker (temporized).
Until you don’t read your message, it beeps every 10 seconds!!




To do all of this tricks, you need to create a C# Windows || Console app and run on COM9 listening arduino.

This is C# code (VS2010 – C#4.0):

/* SEND / READ SERIAL PORT COM9 DATA */

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
try {
  SerialPort port = new SerialPort( "COM9", 9600, Parity.None, 8, StopBits.One );
  port.Open();

  string Unreadz = "0";
  while ( true ) {
    Unreadz = CheckMail();
    Console.WriteLine( "Unread Mails: " + Unreadz );

    if ( !Unreadz.Equals( "0" ) ) port.Write( "m" );
    else port.Write( "n" );

    Thread.Sleep( 10000 );
  }
} catch ( Exception ee ) { Console.WriteLine( ee.Message ); }

This ones check mails:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
private string CheckMail() {
    string result = "0";

    try {
      var url = @"https://gmail.google.com/gmail/feed/atom";
      var USER = "your.user.name";
      var PASS = "youRp@ssw0rd";

      var encoded = TextToBase64( USER + ":" + PASS );

      var myWebRequest = HttpWebRequest.Create( url );
      myWebRequest.Method = "POST";
      myWebRequest.ContentLength = 0;
      myWebRequest.Headers.Add( "Authorization", "Basic " + encoded );

      var response = myWebRequest.GetResponse();
      var stream = response.GetResponseStream();

      XmlReader reader = XmlReader.Create( stream );
      while ( reader.Read() )
        if ( reader.NodeType == XmlNodeType.Element )
          if ( reader.Name == "fullcount" ) {
            result = reader.ReadElementContentAsString();
            return result;
          }
    } catch ( Exception ee ) { Console.WriteLine( ee.Message ); }
    return result;
  }
}

…and last one, text convertion:

1
2
3
4
5
public static string TextToBase64( string sAscii ) {
  System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
  byte[] bytes = encoding.GetBytes( sAscii );
  return System.Convert.ToBase64String( bytes, 0, bytes.Length );
}

Now, upload code to arduino, press PLAY to C# project… and send you a mail to your gmail address!!!

enjoy beeping!

Rif: albertopasca.it





FacebookTwitterDeliciousLinkedInGoogle BookmarksNetlogGoogle GmailMySpaceGoogle ReaderShare

, , , , , , , , , ,

23
lug

Prima di iniziare bisogna configurare l’ambiente!

1) Scaricate Oracle Client se non lo avete già….
2) In Visual Studio 2005, importare nel progetto la libreria System.Data.Oracle
3) Aprite il file “\Oracle\product\11.1.0\client_1\network\admin\TNSNAMES.ORA” e riempitelo con la vostra configurazione.

1
2
3
4
5
6
7
8
9
NAME =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.38.67)(PORT = 1521))
    )
    (CONNECT_DATA =
     (SERVICE_NAME = service.name.com)
    )
  )

Utilizzare una connection string tipo questa, con i vostri parametri:

1
"Data Source=DBNAME;Password=PWD;User ID=USER;Unicode=True";

Iniziamo con il codice C#…

Apertura e chiusura database:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
    private string m_oraConnString;
    private OracleConnection m_oraConnection;
    private OracleCommand m_oraCommand;
    private OracleDataReader m_oraDataReader;
    private string m_oraDbConnection;

    /*** apre la connessione al db ***/
    private void openDb(bool isProcedure) {
      try {
        m_oraConnection = new OracleConnection(m_oraConnString);
        m_oraDbConnection = m_oraConnection.DataSource;
        m_oraCommand = new OracleCommand();

        /* TRUE se è necessario chiamare una procedura anzichè una query */
        if (!isProcedure)
            m_oraCommand.CommandType = CommandType.Text;
        else
            m_oraCommand.CommandType = CommandType.StoredProcedure;

        m_oraCommand.Connection = m_oraConnection;
        m_oraConnection.Open();
      } catch { }
    }

    /*** chiude la connessione ***/
    private void closeDb() {
      try {
        m_oraConnection.Close();
        m_oraConnection = null;
      } catch { }
    }

In caso di chiamata ad una procedura Oracle, è possibile passare o ricevere parametri.

Esempio:
Continue reading “[C#] Connessione ORACLE” »

FacebookTwitterDeliciousLinkedInGoogle BookmarksNetlogGoogle GmailMySpaceGoogle ReaderShare

, , , , ,

Switch to our mobile site