Click here to Skip to main content
15,902,636 members
Home / Discussions / C#
   

C#

 
AnswerRe: Problem with Listbox and removing items... Pin
Dragonfly_Lee1-Feb-09 19:09
Dragonfly_Lee1-Feb-09 19:09 
Questionc# code to execute a particular method every 5 mints? Pin
merryjoy00031-Jan-09 23:24
merryjoy00031-Jan-09 23:24 
AnswerRe: c# code to execute a particular method every 5 mints? Pin
Giorgi Dalakishvili31-Jan-09 23:38
mentorGiorgi Dalakishvili31-Jan-09 23:38 
AnswerRe: c# code to execute a particular method every 5 mints? Pin
merryjoy00031-Jan-09 23:43
merryjoy00031-Jan-09 23:43 
GeneralRe: c# code to execute a particular method every 5 mints? Pin
ajorge20081-Feb-09 0:32
ajorge20081-Feb-09 0:32 
AnswerRe: c# code to execute a particular method every 5 mints? Pin
Giorgi Dalakishvili1-Feb-09 3:21
mentorGiorgi Dalakishvili1-Feb-09 3:21 
AnswerRe: c# code to execute a particular method every 5 mints? Pin
PIEBALDconsult2-Feb-09 4:41
mvePIEBALDconsult2-Feb-09 4:41 
QuestionHow to make Gsm Sequential calls without blocking my application Pin
ajorge200831-Jan-09 23:02
ajorge200831-Jan-09 23:02 
Hi all!

Continuing my serial port fight Smile | :) ...

This time, i'm trying to make sequential Gsm Calls to diferent Gsm numbers. I'm doing some tests, but something's wrong.

My first dial connection is working fine, but when i close it and try to make the next connection, my application turns blocked... and i can't make other dial... Someone could help me with this? The use of filesystemwatcher is only for test purposes.

The code i'm using is here:

public bool GsmConnected;
     public bool GsmConnected2;

     public Form1()
     {
         InitializeComponent();

         FileInfo finfo = new FileInfo("C:\\Users\\AJorge\\Desktop\\GsmStatus.txt");
         StreamWriter ff = finfo.CreateText();
         ff.Close();

         InitComPort();

         this.Show();

         aux_function();

     }

     private void InitComPort()
     {

         axMSComm1.CommPort = 4;

         // This port is already open, then close.
         if (axMSComm1.PortOpen)
             axMSComm1.PortOpen = false;

         // Trigger the OnComm event whenever data is received
         axMSComm1.RThreshold = 1;

         // Set the port baud, no parity bit, 8 data bits, 1 stop bit (all standard)
         axMSComm1.Settings = "115200,n,8,1";

         // Force the DTR line high, used sometimes to hang up modems
         axMSComm1.DTREnable = true;

         axMSComm1.RTSEnable = true;

         axMSComm1.CDTimeout = 10000;

         // No handshaking is used
         axMSComm1.Handshaking = MSCommLib.HandshakeConstants.comNone;

         // Use this line instead for byte array input, best for most communications

         axMSComm1.InputMode = MSCommLib.InputModeConstants.comInputModeBinary;

         // Read the entire waiting data when com.Input is used
         axMSComm1.InputLen = 0;

         // Don't discard nulls, 0x00 is a useful byte
         axMSComm1.NullDiscard = false;

         // Attach the event handler
         axMSComm1.OnComm += new System.EventHandler(this.axMSComm1_OnComm);

         try
         {

             axMSComm1.PortOpen = true;

         }
         catch (Exception e)
         {
             richTextBox1.AppendText(e.ToString());
         }
     }

     private void Form1_Load(object sender, EventArgs e)
     {

     }

     private void CheckGsmStatus(object sender, FileSystemEventArgs e)
     {
         StreamReader fileReader = new StreamReader("C:\\Users\\AJorge\\Desktop\\GsmStatus.txt");

         string ReadAll = fileReader.ReadToEnd();

         string[] ReadAll_Array = ReadAll.Split(new char[] { ' ' });

         for (int i = 0; i < ReadAll_Array.Length; i++)
         {
             if (ReadAll_Array[i] == "13" && ReadAll_Array[i + 1] == "10" && ReadAll_Array[i + 2] == "67" && ReadAll_Array[i + 3] == "79" && ReadAll_Array[i + 4] == "78" && ReadAll_Array[i + 5] == "78" && ReadAll_Array[i + 6] == "69" && ReadAll_Array[i + 7] == "67" && ReadAll_Array[i + 8] == "84" && ReadAll_Array[i + 9] == "32" && ReadAll_Array[i + 10] == "57" && ReadAll_Array[i + 11] == "54" && ReadAll_Array[i + 12] == "48" && ReadAll_Array[i + 13] == "48" && ReadAll_Array[i + 14] == "13" && ReadAll_Array[i + 15] == "10")

                 GsmConnected = true;

             else if (ReadAll_Array[i] == "13" && ReadAll_Array[i + 1] == "10" && ReadAll_Array[i + 2] == "78" && ReadAll_Array[i + 3] == "79" && ReadAll_Array[i + 4] == "32" && ReadAll_Array[i + 5] == "67" && ReadAll_Array[i + 6] == "65" && ReadAll_Array[i + 7] == "82" && ReadAll_Array[i + 8] == "82" && ReadAll_Array[i + 9] == "73" && ReadAll_Array[i + 10] == "69" && ReadAll_Array[i + 11] == "82" && ReadAll_Array[i + 12] == "13" && ReadAll_Array[i + 13] == "10")

                 this.Close();
         }

         fileReader.Close();

     }

     private void CheckGsmStatus2(object sender, FileSystemEventArgs e)
     {
         StreamReader fileReader = new StreamReader("C:\\Users\\AJorge\\Desktop\\GsmStatus.txt");

         string ReadAll = fileReader.ReadToEnd();

         string[] ReadAll_Array = ReadAll.Split(new char[] { ' ' });

         for (int i = 0; i < ReadAll_Array.Length; i++)
         {
             if (ReadAll_Array[i] == "13" && ReadAll_Array[i + 1] == "10" && ReadAll_Array[i + 2] == "67" && ReadAll_Array[i + 3] == "79" && ReadAll_Array[i + 4] == "78" && ReadAll_Array[i + 5] == "78" && ReadAll_Array[i + 6] == "69" && ReadAll_Array[i + 7] == "67" && ReadAll_Array[i + 8] == "84" && ReadAll_Array[i + 9] == "32" && ReadAll_Array[i + 10] == "57" && ReadAll_Array[i + 11] == "54" && ReadAll_Array[i + 12] == "48" && ReadAll_Array[i + 13] == "48" && ReadAll_Array[i + 14] == "13" && ReadAll_Array[i + 15] == "10")

                 GsmConnected2 = true;

             if (ReadAll_Array[i] == "13" && ReadAll_Array[i + 1] == "10" && ReadAll_Array[i + 2] == "78" && ReadAll_Array[i + 3] == "79" && ReadAll_Array[i + 4] == "32" && ReadAll_Array[i + 5] == "67" && ReadAll_Array[i + 6] == "65" && ReadAll_Array[i + 7] == "82" && ReadAll_Array[i + 8] == "82" && ReadAll_Array[i + 9] == "73" && ReadAll_Array[i + 10] == "69" && ReadAll_Array[i + 11] == "82" && ReadAll_Array[i + 12] == "13" && ReadAll_Array[i + 13] == "10")

                 this.Close();
         }

         fileReader.Close();

     }

     private void aux_function()
     {

         try
         {
             GsmConnected = false;

             if (!axMSComm1.PortOpen)

                 axMSComm1.PortOpen = true;

             axMSComm1.Output = "ATD" + "GsmNumber1" + "\r\n";

         }
         catch (Exception er7)
         {
             richTextBox1.AppendText(er7.ToString());
         }

         richTextBox1.AppendText("Dialing with " + "GsmNumber1" + "...");

         fileSystemWatcher1.Path = "C:\\Users\\AJorge\\Desktop\\";
         fileSystemWatcher1.Filter = "GsmStatus.txt";
         fileSystemWatcher1.NotifyFilter = NotifyFilters.LastWrite;
         fileSystemWatcher1.Changed += new FileSystemEventHandler(CheckGsmStatus);

         fileSystemWatcher1.EnableRaisingEvents = true;

         do
         {

             Application.DoEvents();

         } while (!GsmConnected);

         fileSystemWatcher1.EnableRaisingEvents = false;

         axMSComm1.Output = "+++\r\n";
         axMSComm1.Output = "ATH0\r\n";

         Thread.Sleep(2000);

         axMSComm1.PortOpen = false;

         Thread.Sleep(2000);

         InitComPort();

         File.Delete("C:\\Users\\AJorge\\Desktop\\GsmStatus.txt");

         FileInfo f12 = new FileInfo("C:\\Users\\AJorge\\Desktop\\GsmStatus.txt");
         StreamWriter xpto2 = f12.CreateText();
         xpto2.Close();

         DateTime Begins = DateTime.Now;
         DateTime Stops = new DateTime();

         do
         {
             Application.DoEvents();
             Stops = DateTime.Now;

         } while (Stops.Second - Begins.Second != 10);

         try
         {

             GsmConnected2 = false;

             if (!axMSComm1.PortOpen)

                 axMSComm1.PortOpen = true;

             axMSComm1.Output = "ATD" + "GsmNumber2" + "\r\n";

         }
         catch (Exception er7)
         {
             richTextBox1.AppendText(er7.ToString());
         }

         richTextBox1.AppendText("\nDialing with " + "GsmNumber2" + "...");

         fileSystemWatcher1.Path = "C:\\Users\\AJorge\\Desktop\\";
         fileSystemWatcher1.Filter = "GsmStatus.txt";
         fileSystemWatcher1.NotifyFilter = NotifyFilters.LastWrite;
         fileSystemWatcher1.Changed += new FileSystemEventHandler(CheckGsmStatus2);

         fileSystemWatcher1.EnableRaisingEvents = true;

         do
         {

             Application.DoEvents();

         } while (!GsmConnected2);

         fileSystemWatcher1.EnableRaisingEvents = false;

         axMSComm1.Output = "+++\r\n";
         axMSComm1.Output = "ATH0\r\n";



     }

     private void axMSComm1_OnComm(object sender, EventArgs e)
     {

         switch (axMSComm1.CommEvent)
         {
             case ((short)MSCommLib.OnCommConstants.comEvReceive):

                 byte[] b1 = (byte[])axMSComm1.Input;

                 FileInfo finfo = new FileInfo("C:\\Users\\AJorge\\Desktop\\GsmStatus.txt");
                 StreamWriter ff = finfo.AppendText();

                 for (int x = 0; x < b1.Length; x++)
                 {

                     richTextBox1.AppendText(b1[x].ToString());
                     ff.Write("{0} ", b1[x]);


                 }

                 ff.Close();

                 break;

             case ((short)MSCommLib.OnCommConstants.comEvCD):

                 if (!axMSComm1.CDHolding)
                 {

                     richTextBox1.Clear();
                     richTextBox1.AppendText("Hanging up...");

                     try
                     {

                         axMSComm1.Output = "+++\r\n";

                     }
                     catch (Exception e11)
                     {
                         richTextBox1.AppendText(e11.ToString());
                     }

                     try
                     {

                         axMSComm1.Output = "ATH0\r\n";

                     }
                     catch (Exception e12)
                     {
                         richTextBox1.AppendText(e12.ToString());
                     }

                     richTextBox1.AppendText("Disconnected.");

                 }

                 break;

         }

     }


Best regards.
QuestionRepost from ASP.NET forum - VBRUN : 80040154 Pin
coolestCoder31-Jan-09 21:39
coolestCoder31-Jan-09 21:39 
QuestionMp3 Spliting Pin
Learn Searcher31-Jan-09 21:18
Learn Searcher31-Jan-09 21:18 
AnswerRe: Mp3 Spliting Pin
Christian Graus31-Jan-09 22:05
protectorChristian Graus31-Jan-09 22:05 
AnswerRe: Mp3 Spliting Pin
Dragonfly_Lee1-Feb-09 20:17
Dragonfly_Lee1-Feb-09 20:17 
Questionwhen a method is called i want to get first index value from an arraylist and when the same methid is called nxt time i want to get the second index value from the same arraylist...how? Pin
merryjoy00031-Jan-09 20:30
merryjoy00031-Jan-09 20:30 
AnswerRe: when a method is called i want to get first index value from an arraylist and when the same methid is called nxt time i want to get the second index value from the same arraylist...how? Pin
Kashif Sabir31-Jan-09 21:13
Kashif Sabir31-Jan-09 21:13 
AnswerRe: when a method is called i want to get first index value from an arraylist and when the same methid is called nxt time i want to get the second index value from the same arraylist...how? Pin
Dragonfly_Lee31-Jan-09 21:18
Dragonfly_Lee31-Jan-09 21:18 
Questiontablelayoutpanel in c#.net in windows application Pin
dilipmca0431-Jan-09 20:05
dilipmca0431-Jan-09 20:05 
AnswerRe: tablelayoutpanel in c#.net in windows application Pin
dan!sh 31-Jan-09 21:53
professional dan!sh 31-Jan-09 21:53 
AnswerRe: tablelayoutpanel in c#.net in windows application Pin
Alan N31-Jan-09 21:57
Alan N31-Jan-09 21:57 
QuestionHow to call a string value from a method within another class? Pin
Aghosh Babu31-Jan-09 19:29
Aghosh Babu31-Jan-09 19:29 
AnswerRe: How to call a string value from a method within another class? Pin
Karmendra Suthar31-Jan-09 19:50
Karmendra Suthar31-Jan-09 19:50 
GeneralRe: How to call a string value from a method within another class? Pin
Aghosh Babu31-Jan-09 20:15
Aghosh Babu31-Jan-09 20:15 
GeneralRe: How to call a string value from a method within another class? Pin
Karmendra Suthar1-Feb-09 1:00
Karmendra Suthar1-Feb-09 1:00 
AnswerRe: How to call a string value from a method within another class? Pin
Dragonfly_Lee31-Jan-09 20:11
Dragonfly_Lee31-Jan-09 20:11 
QuestionProtect password file Pin
Karmendra Suthar31-Jan-09 19:27
Karmendra Suthar31-Jan-09 19:27 
AnswerRe: Protect password file Pin
Dragonfly_Lee31-Jan-09 20:02
Dragonfly_Lee31-Jan-09 20:02 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.