You are on page 1of 17

using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.

IO; #region Start using EurekaRs232; #endregion namespace SpeachRecog { /// <summary> /// Summary description for Form1. /// </summary> public class Form1 : System.Windows.Forms.Form { private System.Windows.Forms.Label label1; public System.Windows.Forms.Label Detect; private AxHSRLib.AxVcommand VoiceCmd; public System.Windows.Forms.Timer Timer1; private System.ComponentModel.IContainer components; private Rs232 SerComm = new Rs232(); private System.Windows.Forms.TextBox txtVoiceData; private System.Windows.Forms.Label label2; private System.Windows.Forms.GroupBox groupBox2; private System.Windows.Forms.ComboBox c2; private System.Windows.Forms.ComboBox c1; private System.Windows.Forms.Label label4; private System.Windows.Forms.Label label5; private System.Windows.Forms.Button button4; private PictureBox pictureBox1; private PictureBox pictureBox2; private Button button1; private Button button2; private TextBox txtTextdataTX; private Label label3; private Button button3; private TextBox txtRecivedText; private Label label6; private Button button5; private RadioButton r1; private RadioButton r2; private RadioButton r3; private Timer tmrRead; private AxACTIVEVOICEPROJECTLib.AxDirectSS tts; private Button button6; private Button button7; private TextBox tt; private Button button8; private Button button9; private Button button10; private int My_menu; public Form1() { //

// Required for Windows Form Designer support // InitializeComponent(); // // TODO: Add any constructor code after InitializeComponent call // } /// <summary> /// Clean up any resources being used. /// </summary> protected override void Dispose( bool disposing ) { if( disposing ) { if (components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region Windows Form Designer generated code /// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { this.components = new System.ComponentModel.Container(); System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1)); this.label1 = new System.Windows.Forms.Label(); this.Detect = new System.Windows.Forms.Label(); this.VoiceCmd = new AxHSRLib.AxVcommand(); this.Timer1 = new System.Windows.Forms.Timer(this.components); this.txtVoiceData = new System.Windows.Forms.TextBox(); this.label2 = new System.Windows.Forms.Label(); this.groupBox2 = new System.Windows.Forms.GroupBox(); this.c2 = new System.Windows.Forms.ComboBox(); this.label4 = new System.Windows.Forms.Label(); this.label5 = new System.Windows.Forms.Label(); this.button4 = new System.Windows.Forms.Button(); this.c1 = new System.Windows.Forms.ComboBox(); this.pictureBox1 = new System.Windows.Forms.PictureBox(); this.pictureBox2 = new System.Windows.Forms.PictureBox(); this.button1 = new System.Windows.Forms.Button(); this.button2 = new System.Windows.Forms.Button(); this.txtTextdataTX = new System.Windows.Forms.TextBox(); this.label3 = new System.Windows.Forms.Label(); this.button3 = new System.Windows.Forms.Button(); this.txtRecivedText = new System.Windows.Forms.TextBox(); this.label6 = new System.Windows.Forms.Label(); this.button5 = new System.Windows.Forms.Button();

this.r1 = new System.Windows.Forms.RadioButton(); this.r2 = new System.Windows.Forms.RadioButton(); this.r3 = new System.Windows.Forms.RadioButton(); this.tmrRead = new System.Windows.Forms.Timer(this.components); this.tts = new AxACTIVEVOICEPROJECTLib.AxDirectSS(); this.button6 = new System.Windows.Forms.Button(); this.button7 = new System.Windows.Forms.Button(); this.tt = new System.Windows.Forms.TextBox(); this.button8 = new System.Windows.Forms.Button(); this.button9 = new System.Windows.Forms.Button(); this.button10 = new System.Windows.Forms.Button(); ((System.ComponentModel.ISupportInitialize)(this.VoiceCmd)).BeginInit(); this.groupBox2.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox2)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.tts)).BeginInit(); this.SuspendLayout(); // // label1 // this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.label1.ForeColor = System.Drawing.Color.Blue; this.label1.Location = new System.Drawing.Point(66, 160); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(144, 23); this.label1.TabIndex = 1; this.label1.Text = " Heard Command"; // // Detect // this.Detect.BackColor = System.Drawing.SystemColors.Control; this.Detect.Cursor = System.Windows.Forms.Cursors.Default; this.Detect.Font = new System.Drawing.Font("Arial", 8F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.Detect.ForeColor = System.Drawing.Color.Red; this.Detect.Location = new System.Drawing.Point(240, 160); this.Detect.Name = "Detect"; this.Detect.RightToLeft = System.Windows.Forms.RightToLeft.No; this.Detect.Size = new System.Drawing.Size(136, 17); this.Detect.TabIndex = 4; this.Detect.Text = "<Nothing>"; // // VoiceCmd // this.VoiceCmd.Enabled = true; this.VoiceCmd.Location = new System.Drawing.Point(8, 8); this.VoiceCmd.Name = "VoiceCmd"; this.VoiceCmd.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("VoiceCmd.OcxState"))); this.VoiceCmd.Size = new System.Drawing.Size(32, 32); this.VoiceCmd.TabIndex = 6; this.VoiceCmd.Visible = false; this.VoiceCmd.CommandRecognize += new AxHSRLib._VcommandEvents_CommandRecognizeEventHandler(this.VoiceCmd_CommandRecognize);

this.VoiceCmd.CommandOther += new AxHSRLib._VcommandEvents_CommandOtherEventHandler(this.VoiceCmd_CommandOther); // // Timer1 // this.Timer1.Enabled = true; this.Timer1.Interval = 1000; this.Timer1.Tick += new System.EventHandler(this.Timer1_Tick); // // txtVoiceData // this.txtVoiceData.Location = new System.Drawing.Point(87, 189); this.txtVoiceData.Multiline = true; this.txtVoiceData.Name = "txtVoiceData"; this.txtVoiceData.Size = new System.Drawing.Size(440, 61); this.txtVoiceData.TabIndex = 7; // // label2 // this.label2.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.label2.ForeColor = System.Drawing.Color.Blue; this.label2.Location = new System.Drawing.Point(5, 192); this.label2.Name = "label2"; this.label2.Size = new System.Drawing.Size(76, 23); this.label2.TabIndex = 8; this.label2.Text = "Voice Data"; // // groupBox2 // this.groupBox2.Controls.Add(this.c2); this.groupBox2.Controls.Add(this.label4); this.groupBox2.Controls.Add(this.label5); this.groupBox2.Controls.Add(this.button4); this.groupBox2.Controls.Add(this.c1); this.groupBox2.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.groupBox2.ForeColor = System.Drawing.Color.Red; this.groupBox2.Location = new System.Drawing.Point(87, 8); this.groupBox2.Name = "groupBox2"; this.groupBox2.Size = new System.Drawing.Size(463, 128); this.groupBox2.TabIndex = 9; this.groupBox2.TabStop = false; this.groupBox2.Text = "Port Setting"; // // c2 // this.c2.Items.AddRange(new object[] { "1200", "2400", "4800", "9600"}); this.c2.Location = new System.Drawing.Point(120, 72); this.c2.Name = "c2"; this.c2.Size = new System.Drawing.Size(121, 24); this.c2.TabIndex = 14;

// // label4 // this.label4.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.label4.ForeColor = System.Drawing.SystemColors.ActiveCaption; this.label4.Location = new System.Drawing.Point(16, 72); this.label4.Name = "label4"; this.label4.Size = new System.Drawing.Size(96, 23); this.label4.TabIndex = 9; this.label4.Text = "Baud Rate"; // // label5 // this.label5.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.label5.ForeColor = System.Drawing.SystemColors.ActiveCaption; this.label5.Location = new System.Drawing.Point(16, 32); this.label5.Name = "label5"; this.label5.Size = new System.Drawing.Size(96, 23); this.label5.TabIndex = 8; this.label5.Text = "Comm Port"; // // button4 // this.button4.Location = new System.Drawing.Point(248, 72); this.button4.Name = "button4"; this.button4.Size = new System.Drawing.Size(105, 23); this.button4.TabIndex = 4; this.button4.Text = "Connect"; this.button4.Click += new System.EventHandler(this.button4_Click); // // c1 // this.c1.Location = new System.Drawing.Point(120, 24); this.c1.Name = "c1"; this.c1.Size = new System.Drawing.Size(121, 24); this.c1.TabIndex = 13; this.c1.SelectedIndexChanged += new System.EventHandler(this.c1_SelectedIndexChanged); // // pictureBox1 // this.pictureBox1.Image = global::SpeachRecog.Properties.Resources.untitled; this.pictureBox1.Location = new System.Drawing.Point(556, 26); this.pictureBox1.Name = "pictureBox1"; this.pictureBox1.Size = new System.Drawing.Size(131, 128); this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage; this.pictureBox1.TabIndex = 10; this.pictureBox1.TabStop = false; // // pictureBox2 // this.pictureBox2.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.pictureBox2.Location = new System.Drawing.Point(858, 26); this.pictureBox2.Name = "pictureBox2"; this.pictureBox2.Size = new System.Drawing.Size(131, 128);

this.pictureBox2.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage; this.pictureBox2.TabIndex = 11; this.pictureBox2.TabStop = false; // // button1 // this.button1.Location = new System.Drawing.Point(533, 227); this.button1.Name = "button1"; this.button1.Size = new System.Drawing.Size(105, 23); this.button1.TabIndex = 12; this.button1.Text = "Send"; this.button1.Click += new System.EventHandler(this.button1_Click_1); // // button2 // this.button2.Location = new System.Drawing.Point(701, 32); this.button2.Name = "button2"; this.button2.Size = new System.Drawing.Size(13, 10); this.button2.TabIndex = 13; this.button2.Text = "Browse"; this.button2.Click += new System.EventHandler(this.button2_Click); // // txtTextdataTX // this.txtTextdataTX.Location = new System.Drawing.Point(87, 285); this.txtTextdataTX.Multiline = true; this.txtTextdataTX.Name = "txtTextdataTX"; this.txtTextdataTX.Size = new System.Drawing.Size(440, 61); this.txtTextdataTX.TabIndex = 14; // // label3 // this.label3.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.label3.ForeColor = System.Drawing.Color.Blue; this.label3.Location = new System.Drawing.Point(5, 288); this.label3.Name = "label3"; this.label3.Size = new System.Drawing.Size(76, 23); this.label3.TabIndex = 15; this.label3.Text = "Text Data"; // // button3 // this.button3.Location = new System.Drawing.Point(533, 323); this.button3.Name = "button3"; this.button3.Size = new System.Drawing.Size(105, 23); this.button3.TabIndex = 16; this.button3.Text = "Send"; this.button3.Click += new System.EventHandler(this.button3_Click); // // txtRecivedText // this.txtRecivedText.Location = new System.Drawing.Point(87, 370); this.txtRecivedText.Multiline = true; this.txtRecivedText.Name = "txtRecivedText"; this.txtRecivedText.Size = new System.Drawing.Size(440, 61);

this.txtRecivedText.TabIndex = 17; // // label6 // this.label6.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.label6.ForeColor = System.Drawing.Color.Blue; this.label6.Location = new System.Drawing.Point(5, 370); this.label6.Name = "label6"; this.label6.Size = new System.Drawing.Size(76, 23); this.label6.TabIndex = 18; this.label6.Text = "RX"; // // button5 // this.button5.Location = new System.Drawing.Point(727, 131); this.button5.Name = "button5"; this.button5.Size = new System.Drawing.Size(105, 23); this.button5.TabIndex = 19; this.button5.Text = "Send"; this.button5.Click += new System.EventHandler(this.button5_Click); // // r1 // this.r1.AutoSize = true; this.r1.Checked = true; this.r1.Location = new System.Drawing.Point(668, 227); this.r1.Name = "r1"; this.r1.Size = new System.Drawing.Size(52, 17); this.r1.TabIndex = 20; this.r1.TabStop = true; this.r1.Text = "Audio"; this.r1.UseVisualStyleBackColor = true; this.r1.CheckedChanged += new System.EventHandler(this.r1_CheckedChanged); // // r2 // this.r2.AutoSize = true; this.r2.Location = new System.Drawing.Point(668, 279); this.r2.Name = "r2"; this.r2.Size = new System.Drawing.Size(54, 17); this.r2.TabIndex = 21; this.r2.Text = "Image"; this.r2.UseVisualStyleBackColor = true; this.r2.CheckedChanged += new System.EventHandler(this.r2_CheckedChanged); // // r3 // this.r3.AutoSize = true; this.r3.Location = new System.Drawing.Point(668, 329); this.r3.Name = "r3"; this.r3.Size = new System.Drawing.Size(46, 17); this.r3.TabIndex = 22; this.r3.Text = "Text"; this.r3.UseVisualStyleBackColor = true; this.r3.CheckedChanged += new System.EventHandler(this.r3_CheckedChanged);

// // tmrRead // this.tmrRead.Tick += new System.EventHandler(this.tmrRead_Tick); // // tts // this.tts.Enabled = true; this.tts.Location = new System.Drawing.Point(837, 198); this.tts.Name = "tts"; this.tts.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("tts.OcxState"))); this.tts.Size = new System.Drawing.Size(152, 205); this.tts.TabIndex = 23; // // button6 // this.button6.Location = new System.Drawing.Point(882, 163); this.button6.Name = "button6"; this.button6.Size = new System.Drawing.Size(105, 23); this.button6.TabIndex = 24; this.button6.Text = "SAVE"; this.button6.Click += new System.EventHandler(this.button6_Click); // // button7 // this.button7.Location = new System.Drawing.Point(726, 165); this.button7.Name = "button7"; this.button7.Size = new System.Drawing.Size(105, 23); this.button7.TabIndex = 25; this.button7.Text = "Ready"; this.button7.Click += new System.EventHandler(this.button7_Click); // // tt // this.tt.Location = new System.Drawing.Point(533, 370); this.tt.Multiline = true; this.tt.Name = "tt"; this.tt.Size = new System.Drawing.Size(440, 61); this.tt.TabIndex = 26; // // button8 // this.button8.Location = new System.Drawing.Point(726, 226); this.button8.Name = "button8"; this.button8.Size = new System.Drawing.Size(105, 23); this.button8.TabIndex = 27; this.button8.Text = "Audio"; this.button8.Click += new System.EventHandler(this.button8_Click); // // button9 // this.button9.Location = new System.Drawing.Point(726, 279); this.button9.Name = "button9"; this.button9.Size = new System.Drawing.Size(105, 23); this.button9.TabIndex = 28; this.button9.Text = "Image";

this.button9.Click += new System.EventHandler(this.button9_Click); // // button10 // this.button10.Location = new System.Drawing.Point(726, 326); this.button10.Name = "button10"; this.button10.Size = new System.Drawing.Size(105, 23); this.button10.TabIndex = 29; this.button10.Text = "Text"; this.button10.Click += new System.EventHandler(this.button10_Click); // // Form1 // this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); this.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(192)))), ((int)(((byte)(192)))), ((int)(((byte)(255))))); this.ClientSize = new System.Drawing.Size(1202, 443); this.Controls.Add(this.button10); this.Controls.Add(this.button9); this.Controls.Add(this.button8); this.Controls.Add(this.tt); this.Controls.Add(this.button7); this.Controls.Add(this.button6); this.Controls.Add(this.tts); this.Controls.Add(this.r3); this.Controls.Add(this.r2); this.Controls.Add(this.r1); this.Controls.Add(this.button5); this.Controls.Add(this.label6); this.Controls.Add(this.txtRecivedText); this.Controls.Add(this.button3); this.Controls.Add(this.label3); this.Controls.Add(this.txtTextdataTX); this.Controls.Add(this.button2); this.Controls.Add(this.button1); this.Controls.Add(this.pictureBox2); this.Controls.Add(this.pictureBox1); this.Controls.Add(this.groupBox2); this.Controls.Add(this.label2); this.Controls.Add(this.txtVoiceData); this.Controls.Add(this.VoiceCmd); this.Controls.Add(this.Detect); this.Controls.Add(this.label1); this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); this.Name = "Form1"; this.Text = "Zig B Protocol"; this.Load += new System.EventHandler(this.Form1_Load); ((System.ComponentModel.ISupportInitialize)(this.VoiceCmd)).EndInit(); this.groupBox2.ResumeLayout(false); ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox2)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.tts)).EndInit(); this.ResumeLayout(false); this.PerformLayout(); }

#endregion /// <summary> /// The main entry point for the application. /// </summary> [STAThread] static void Main() { Application.Run(new Form1()); } byte[] bt2 = new byte[20000]; bool flg = false; int i = 0; string voicedata = string.Empty; string TextData = string.Empty; bool voiceFlg = false; bool TextFlg = false; bool ImageFlg = false;

private void Form1_Load(object sender, System.EventArgs e) { for(int i=1 ; i<=255;i++) c1.Items.Add(i.ToString()); c1.SelectedIndex =0; c2.SelectedIndex =0; //SerComm.Open(1, 1200, 8, Rs232.DataParity.Parity_None, Rs232.DataStopBit.StopBit_1, 4096); VoiceCmd.Initialized = 1; My_menu = VoiceCmd.get_MenuCreate("My Commands", "commands State", 4); VoiceCmd.CtlEnabled = 1; VoiceCmd.SuppressExceptions = 1; VoiceCmd.AddCommand(My_menu, 0, "Hi", "For moving the object", "voice", 0, ""); VoiceCmd.AddCommand(My_menu, 1, "Hello", "back", "voice", 0, ""); VoiceCmd.AddCommand(My_menu, 2, "ok", "right", "voice", 0, ""); VoiceCmd.AddCommand(My_menu, 3, "bye", "left", "voice", 0, ""); VoiceCmd.AddCommand(My_menu, 4, "I", "stop", "voice", 0, ""); VoiceCmd.AddCommand(My_menu, 5, "am", "stop", "voice", 0, ""); VoiceCmd.AddCommand(My_menu, 6, "fine", "rite", "voice", 0, ""); VoiceCmd.AddCommand(My_menu, 8, "lef", "ri", "voice", 0, ""); VoiceCmd.AddCommand(My_menu, 9, "let", "ri", "voice", 0, ""); VoiceCmd.Activate(My_menu); } private void Timer1_Tick(object sender, System.EventArgs e) { Detect.Text = "<Nothing>"; }

private void VoiceCmd_CommandOther(object sender, AxHSRLib._VcommandEvents_CommandOtherEvent e) { Timer1.Enabled = false; Detect.Text = e.command; txtVoiceData.Text = Detect.Text; //if(Detect.Text=="back") // { // textBox1.Text= "b"; // SerComm.Write(textBox1.Text); // } // else if(Detect.Text=="move") // { // //Detect.Text="move"; // textBox1.Text= "k"; // SerComm.Write(textBox1.Text); // } // else if(Detect.Text==""||Detect.Text=="stop") // { // Detect.Text="stop"; // textBox1.Text = "s"; // SerComm.Write(textBox1.Text); // } // else if(Detect.Text=="left"||Detect.Text=="lef" ||Detect.Text=="let" ) // { // // Detect.Text= "left"; // textBox1.Text = "l"; // SerComm.Write(textBox1.Text); // } // else if(Detect.Text=="right") // { // // Detect.Text="right" ; // textBox1.Text = "r"; // SerComm.Write(textBox1.Text); // } Timer1.Enabled =true; Timer1.Interval =1300; } private void VoiceCmd_CommandRecognize(object sender, AxHSRLib._VcommandEvents_CommandRecognizeEvent e) { Timer1.Enabled = false; Detect.Text = e.command; txtVoiceData.Text = Detect.Text; //if (Detect.Text == "back") //{ // textBox1.Text = "b"; // SerComm.Write(textBox1.Text);

//} //else if (Detect.Text == "move") //{ // //Detect.Text="move"; // textBox1.Text = "f"; // SerComm.Write(textBox1.Text); //} //else if (Detect.Text == "" || Detect.Text == "stop") //{ // Detect.Text = "stop"; // textBox1.Text = "s"; // SerComm.Write(textBox1.Text); //} //else if (Detect.Text == "left" || Detect.Text == "lef" || Detect.Text == "lef") //{ // textBox1.Text = "l"; // SerComm.Write(textBox1.Text); //} //else if (Detect.Text == "right") //{ // textBox1.Text = "r"; // SerComm.Write(textBox1.Text); //} Timer1.Enabled = true; Timer1.Interval = 1300; }

private void button4_Click(object sender, System.EventArgs e) { if(SerComm.IsOpen) { SerComm.Close(); } try { SerComm.Open(Convert.ToInt32(c1.Text) , Convert.ToInt32(c2.Text), 8, Rs232.DataParity.Parity_None, Rs232.DataStopBit.StopBit_1, 4096); tmrRead.Enabled = true; MessageBox.Show("You have Successfully connected With Comm Port " +c1.Text);

} catch(Exception err) {

MessageBox.Show(err.Message); } } private void c1_SelectedIndexChanged(object sender, EventArgs e) { } private void button1_Click(object sender, EventArgs e) { } private void button5_Click(object sender, EventArgs e) { Image Img = pictureBox1.Image; byte[] bt = imageToByteArray(Img); foreach (byte b in bt) { byte[] n = new byte[1]; n[0] = byte.Parse(b.ToString()); SerComm.Write(n); } byte[] n1 = new byte[1]; n1[0] = byte.Parse("255"); SerComm.Write(n1); } public byte[] imageToByteArray(System.Drawing.Image imageIn) { MemoryStream ms = new MemoryStream(); imageIn.Save(ms, System.Drawing.Imaging.ImageFormat.Gif);

return ms.ToArray(); } public Image byteArrayToImage(byte[] byteArrayIn) { MemoryStream ms = new MemoryStream(byteArrayIn); Image returnImage = Image.FromStream(ms); return returnImage; }

private void button2_Click(object sender, EventArgs e) { // Create new SaveFileDialog object OpenFileDialog DialogSave = new OpenFileDialog(); // Default file extension //DialogSave.DefaultExt = "txt";

// Available file extensions // DialogSave.Filter = "Text file (*.txt)|*.txt|XML file (*.xml)|*.xml|All files (*.*)|*.*"; DialogSave.Filter = "(All files (*.*)|*.*";

// Adds a extension if the user does not DialogSave.AddExtension = true; // Restores the selected directory, next time DialogSave.RestoreDirectory = true; // Dialog title DialogSave.Title = "Where do you want to save the file?"; // Startup directory DialogSave.InitialDirectory = @"C:/"; // Show the dialog and process the result if (DialogSave.ShowDialog() == DialogResult.OK) { MessageBox.Show("You selected the file: " + DialogSave.FileName); Bitmap bmp = new Bitmap(DialogSave.FileName); pictureBox1.Image = bmp; } else { MessageBox.Show("You hit cancel or closed the dialog."); } DialogSave.Dispose(); DialogSave = null; } private void r1_CheckedChanged(object sender, EventArgs e) { } private void r2_CheckedChanged(object sender, EventArgs e) { } private void r3_CheckedChanged(object sender, EventArgs e) {

} private void tmrRead_Tick(object sender, EventArgs e) { try {

while (SerComm.Read(1) != -1) { //if (i >= 3) //{ // //txtData.Text = Getdata[8]; // //i = 0; // //int Dta = Convert.ToInt32(txtData.Text); //} string dt = SerComm.InputStream[0].ToString(); //Getdata[i++] = dt; //tt.Text = tt.Text + dt.ToString(); if (dt == "253" && ImageFlg == false) {

tts.Speak(voicedata); txtRecivedText.Text = voicedata; voiceFlg = false; } if (dt == "254" && ImageFlg == false) { TextFlg = false; } if (dt == "255"&&i>=2284) { ImageFlg = false; Image im2 = byteArrayToImage(bt2); pictureBox2.Image = im2; }

if (dt == "250" && ImageFlg == false ) { voiceFlg = true; voicedata = ""; TextFlg = false; ImageFlg = false; } else if (dt == "252" && ImageFlg == false) { voiceFlg = false ; ImageFlg = false; TextFlg = true; txtRecivedText.Text = ""; } else if (dt == "251") { ImageFlg = true ; voiceFlg = false; TextFlg = false; //i = 0;

} else if (voiceFlg == true && ImageFlg == false) { voicedata = voicedata + Convert.ToChar(SerComm.InputStream[0]); } else if (TextFlg == true && ImageFlg == false) { txtRecivedText.Text = txtRecivedText.Text + Convert.ToChar(SerComm.InputStream[0]); } else if (ImageFlg == true) { // if(Convert.ToInt32(dt) ==0 ||Convert.ToInt32(dt) ==1) bt2[i++] = Convert.ToByte(SerComm.InputStream[0]); }

} } catch (Exception exc) { // An exception is raised when there is no information to read. // Don't do anything here, just let the exception go. } } private void button1_Click_1(object sender, EventArgs e) { char[] t1 = txtVoiceData.Text.ToCharArray(); foreach (char c in t1) SerComm.Write(c.ToString()); byte[] n1 = new byte[1]; n1[0] = byte.Parse("253"); SerComm.Write(n1); } private void button3_Click(object sender, EventArgs e) { char[] t1 = txtTextdataTX.Text.ToCharArray(); foreach (char c in t1) SerComm.Write(c.ToString()); byte[] n1 = new byte[1]; n1[0] = byte.Parse("254"); SerComm.Write(n1);

} private void button6_Click(object sender, EventArgs e) { pictureBox2.Image.Save("C:\\RecvImg.jpg"); MessageBox.Show("Image Has been saved"); } private void button7_Click(object sender, EventArgs e) { tts.Speak("hello"); } private void button8_Click(object sender, EventArgs e) { r1.Checked = true; byte[] n1 = new byte[1]; n1[0] = byte.Parse("250"); SerComm.Write(n1); } private void button9_Click(object sender, EventArgs e) { r2.Checked = true; byte[] n1 = new byte[1]; n1[0] = byte.Parse("251"); SerComm.Write(n1); } private void button10_Click(object sender, EventArgs e) { r3.Checked = true; byte[] n1 = new byte[1]; n1[0] = byte.Parse("252"); SerComm.Write(n1); }

} }

You might also like