|
i am developing an sms gateway application. I have a configuration text file which i have to read from the application and configure the connected modems according to it. After configuring the modems i have to save the configured modem as an object to an array/arraylist. So next time whenver i want the modem to do something i call the object from the array.
using System;
using System.Collections.Generic;
using System.Collections;
using System.Text;
using System.IO;
using System.Windows.Forms;
using System.IO.Ports;
using System.Threading;
using System.ComponentModel;
using System.Data;
using System.Drawing;
namespace SMSTest
{
class SMSModem
{
public ArrayList PortNameContainer = new ArrayList();
public ArrayList BaudRateContainer = new ArrayList();
public ArrayList DataBitContainer = new ArrayList();
public ArrayList PhoneNumberContainer = new ArrayList();
public ArrayList SMSCetreNoContainer = new ArrayList();
SerialPort serialPort1 = new SerialPort();
private string config_file = "C:/config.txt";
private string ServiceCentreNo;
public int NumberOfLines = 0;
public bool ModemConfig()
{
try
{
string line;
TextReader tr = new StreamReader(config_file);
System.IO.StreamReader objReader;
objReader = new System.IO.StreamReader(config_file);
while ((line = tr.ReadLine()) != null)
{
NumberOfLines++;
}
string[] ListLines = new string[NumberOfLines];
for (int i = 0; i < NumberOfLines; i++)
{
ListLines[i] = objReader.ReadLine();
string[] values = ListLines[i].Split(new char[] { '$', '#' });
string[] PortSplit = values[0].Split(new char[] { ':', '#' });
string PortName = PortSplit[1];
string[] BaudSplit = values[1].Split(new char[] { ':', '#' });
int BaudRate = Convert.ToInt32(BaudSplit[1]);
string[] BitsSplit = values[2].Split(new char[] { ':', '#' });
int DataBits = Convert.ToInt32(BitsSplit[1]);
string[] NumberSplit = values[3].Split(new char[] { ':', '#' });
string PhoneNumber = NumberSplit[1];
string[] SerNumberSplit = values[4].Split(new char[] { ':', '#' });
ServiceCentreNo = SerNumberSplit[1];
serialPort1.PortName = PortName;
serialPort1.BaudRate = BaudRate;
serialPort1.DataBits = DataBits;
serialPort1.Handshake = Handshake.RequestToSend;
serialPort1.Parity = Parity.None;
serialPort1.StopBits = StopBits.One;
serialPort1.DtrEnable = true;
serialPort1.Open();
serialPort1.Write("AT \r\n");
Thread.Sleep(5);
serialPort1.Write("AT+CMGF=1 \r\n");
Thread.Sleep(5);
serialPort1.Write("AT+CNMI=1,2,0,0,0 \r\n");
Thread.Sleep(5);
serialPort1.Write("AT+CMEE=0 \r\n");
Thread.Sleep(5);
serialPort1.Close();
PortNameContainer.Add(Convert.ToString(PortName));
BaudRateContainer.Add(BaudRate);
DataBitContainer.Add(DataBits);
PhoneNumberContainer.Add(PhoneNumber);
SMSCetreNoContainer.Add(ServiceCentreNo);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
return false;
}
return true;
}
}
}
the below codes shows an exaple for sending out an sms. So whenever i need to send an sms i take the modem phone number, receiver Phone number and sms text using a method SendSMS(string MPN, string RPN, string text). Checks the modem phone number in the arraylist called "PhoneNumberContainer" and get the corresponding values from the other array list and configure the modem for sending. see th code:
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.IO.Ports;
using System.Windows.Forms;
using System.Threading;
namespace SMSTest
{
class SMSManager
{
private SMSModem mdm = new SMSModem();
private SerialPort serialPort1 = new SerialPort();
private int index;
private string result;
private void PortInitialise()
{
serialPort1.PortName = Convert.ToString(mdm.PortNameContainer[index]);
serialPort1.BaudRate = Convert.ToInt32(mdm.BaudRateContainer[index]);
serialPort1.DataBits = Convert.ToInt32(mdm.DataBitContainer[index]);
serialPort1.Handshake = Handshake.RequestToSend;
serialPort1.Parity = Parity.None;
serialPort1.StopBits = StopBits.One;
serialPort1.DtrEnable = true;
}
public string SendSMS(string MPN, string RPN, string text)
{
try
{
mdm.ModemConfig();
if (mdm.PhoneNumberContainer.Contains(MPN))
{
index = mdm.PhoneNumberContainer.IndexOf(MPN);
PortInitialise();
serialPort1.Open();
string ServiceCentre = Convert.ToString(mdm.SMSCetreNoContainer[index]);
serialPort1.WriteLine("AT+CMGF=1;+CSCA=\"" + ServiceCentre + "\";+CMGS=\"+65" + RPN + "\"\r\n");
System.Threading.Thread.Sleep(40);
serialPort1.Write(text);
char[] arr = new char[1];
arr[0] = (char)26;
serialPort1.Write(arr, 0, 1);
System.Threading.Thread.Sleep(3000);
string data = serialPort1.ReadExisting();
result = "Message Sent";
serialPort1.Close();
}
}
catch(Exception e)
{
result = "Message sending failed :" + e.Message;
}
return result;
}
}
}
Below is a sample method that is within a button click event:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace SMSTest
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
SMSManager sm = new SMSManager();
string msg = sm.SendSMS("+6581563840", "82083412", "test");
MessageBox.Show(msg);
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
}
Now i want to do it in the other way to support parrallel sending. I.e i want to create an array of modem objects, these modem objects will be pre-configured using the values from text file. And every time i want to send out an sms i just call the modem object and send the message directly.
Pls help me... i am stuck and the project had to deliver soon!
|
|
|
|
|
Your post is broken and hard to read. Please edit it and make it readable.
Aghosh Babu wrote: i want to create an array of modem objects
Create a class, say Modem with all required properties and put it in a List<Modem> other than arraylist.
|
|
|
|
|
+5 for the attempt to read. WTF you going to audit 300 lines of someone else's code???
|
|
|
|
|
|
|
pls tell me how to create an array of objects in general? and how to call the objects later??
|
|
|
|
|
Aghosh Babu wrote: pls tell me how to create an array of objects
object[] objArray = {new object(),new object()}; You access it with an indexer. Like
object obj1 = objArray[0] . These all are basics and looks like you need a C# book.
|
|
|
|
|
I am not an expert.. this is my univ project!
|
|
|
|
|
Aghosh Babu wrote: this is my univ project!
Then you've learnt nothing, choose another career path.
|
|
|
|
|
thanks for the advice! unfortunately i havn't born as a programmer
|
|
|
|
|
<pre>
i am developing an sms gateway application</pre>
If ur not programmer then how you develop that gateway.
But Here is the Solution
ArrayList arrObj = new ArrayList();
arrObj.Add(YourObject);
foreach(object o in arrObj)
{
if(o is YourObjectClass)
{
}
}
WANTED wasim khan(Killed 50 Innocent Buggs, Distroyed 200 Exception, make 5 Project Hostage) any Compnay Hire him will pay 30,000. Best place where u can get him is Sorcim Technologies Murre Road RWP
|
|
|
|
|
If I handed in my University project that composed (mainly) of an array of generic objects I don't think I would have passed.
|
|
|
|
|
Hi there.
I am newbie so please bear with me..Big Grin
I found a universal remote control application for PDA on this site itself.
The link to the application in C# is below
http://www.codeproject.com/KB/miscctrl/UniversalRemoteControlPDA.aspx[^]
I tried posting comments on the application page but since no one replied for over a month i tried putting my questions here.
1: Is this a "real" universal remote control for all ir devices or just for Phillips ir devices?.
2: How do i run this application? I downloaded the source code and "deployed the solution" using pocket pc 2003 emulator on visual studio 2005 but could not find the application on the emulator....
Please help...
Thanks in advance
|
|
|
|
|
gauravxxx wrote: I tried posting comments on the application page but since no one replied for over a month
You haven't posted in over a month, you haven't been registered for a month. Try the mobile development forum, it will be your best bet.
|
|
|
|
|
ok i might have exagerated the month part...:P
But am a member since more than 4 month...Check on my profile...
Anyways no one can help my with this application...Its kinda tough for me since am i never used c# before
|
|
|
|
|
gauravxxx wrote: ok i might have exagerated the month part...:P ... you exaggerated by the entire amount of time, you posted on January 1st, today is January 3rd, that's 2 days, plus you posted this last night so all you waited was one day?! Don't you think you can be a little more patient???
gauravxxx wrote: Anyways no one can help my with this application...Its kinda tough for me since am i never used c# before
People can help you, so can google. In fact, google can help you pretty damned fast if you used it enough. Read a couple of books if you want to brush up on your C# and don't take on projects that you can't handle if you are new to this sort of thing. Start small and work your way up.
For future reference, cross posting and lack of patience will get you scorned around here.
|
|
|
|
|
My first post was on Jan 25th dude...do crosschek before just posting dude...
We already the 3rd FEb...makes kinda a week...besides u r not of any help so y bother replying....:S:S:S
Btw i fink we r already in Feb not Jan as u keep repeating in your previous post
+ I tried google but found nothing like a universal remote control software in c# or c++ except for codeproject. Thats why i joined it 4 month ago....
SO if u cannot be of any help why you keep replyin dude?...:S:S:S
|
|
|
|
|
Ok, let's tackle this one slowly. Relax with the text speak, it's not cool, it's just stupid. Secondly, I said your first post about THIS topic in the FORUMS was on Febuary 1st.
gauravxxx Profile:
Universal Remote Control for PDA [^]
by gauravxxx at 10:01 1 Feb '09
C# (Forum)
Universal Remote Control for PDA [^]
by gauravxxx at 10:00 1 Feb '09
Mobile Development (Forum) <-- FIRST OCCURANCE
AND you made 3 seperate threads about this in 2 days, we are the third TODAY, you made them all within two (2) days.
|
|
|
|
|
|
Sir I am not clear about one thing please describe this. When I connect to internet I get ip www.whatismyip.com shows it. But my LAN ip is some thing else like 192.168.1.5. So when posting on some website this 192.168.1.5 has some effect. Example if I make a posting keeping my ip (LAN) as 192.168.1.5 and then make another using ip 192.168.1.34 and so on. Does my postings will be considered as from different systems or from the same system. As in LAN we use a single ip but we have different LAN ips different users are using different computers having the same proxy.
My question is this changing my computer (LAN) ip makes some effect on my identification on internet or not.
Thank You
|
|
|
|
|
Changing LAN IP does not change your external IP, sorry.
|
|
|
|
|
Waheed Ur Rehman wrote: My question is this changing my computer (LAN) ip makes some effect on my identification on internet or not.
No. If your ISP has provided you a static IP, your IP will always remain same. Dynamic IP is granted when you connect each time and this may change each time.
BTW, what this has to do with C#?
|
|
|
|
|
Dear Sir,
Is it possible to change the dynamic ip using C# without connecting disconnecting.
Thank You
|
|
|
|
|
|
it is possible. Simply create a WebProxy object and set webrequest.Proxy=proxy; Then your real ip will change for the request.
Thank You
|
|
|
|