473,511 Members | 14,951 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Serial communication Using c#

366 Contributor
Hi friends

I am working on c#.net . i am developing a windows application using c# 2003

aim of my application is sending and receiving sms using GSM modem.

for this i am using AxMscomm control which is there in VB6.0(telephone device)

by using this i am able to receive the data and able to send message .but the

problem is when i send the sms and after sending if i want to receive the data again

it throwing an exception Exception from HRESULT:0x800A1F45

I am using two different windows for receiving (reading messages from sim) and

other for sending sms.

i am unable to access the AxMscomm open and close (ie portopen and close)

property from other windows forms .when i tried to close the port from other

windows form(form other than the AxMscomm control is placed) it shows the

portopen property as false but internally the connection is not closed.

how to handle the properties of this control from overall my application

My partil code goes like this....
******************************************code**** ********************
SerialPort is the name of my AxMscomm control

SerialPort.CommPort=1;
if(SerialPort.PortOpen)
SerialPort.PortOpen=false;

SerialPort.RThreshold=1;
SerialPort.Settings="9600,n,8,1";
SerialPort.DTREnable=true;
SerialPort.RTSEnable=true;
SerialPort.Handshaking=MSCommLib.HandshakeConstant s.comNone;
SerialPort.InputMode=MSCommLib.InputModeConstants. comInputModeText;
SerialPort.InputLen=0;
SerialPort.NullDiscard=false;


opening the connection to rs232.............

SerialPort.PortOpen=true;

timer1.Start();

////i am using timer to read messages ffrom my sim contineously

and stop reading when i tried to send the sms. and autmatically start reading

with out manual interaction.

reading messages from sim in timer tick

SerialPort.OnComm +=new EventHandler(SerialPort_OnComm);

try
{
timer1.Stop();


if(SerialPort.InBufferCount>0)
{
Thread.Sleep(1000);

ProcessSerialportdata((string) SerialPort.Input);

timer1.Start();// commented
}
else
timer1.Start(); //commented
}
catch(Exception ex)
{
if(timer1.Enabled==true)
timer1.Stop();
else
timer1.Start();
}


private void ProcessSerialportdata(string input)
{ richTextBox1.Text="";
richTextBox1.AppendText(input+"\n");
r


if(richTextBox1.TextLength>60)
{
i=0;
j++;

}
else if((s.IndexOf("ERROR")!=-1))
{
j=1;
// timer1.Start();
SerialPort.InBufferCount=0;


}


Sending sms.................


timer1.Stop();
string cmdsend="AT+CMGS="+"xxxxxxxxxx"+Convert.ToChar(13) ;

SerialPort.Output=cmdsend;
Thread .Sleep (100);
string cmd=SerialPort.Input.ToString ();
cmdsend="";

if(cmd.IndexOf (">")>1)
{
//cmd="";
cmdsend=" sms to b send"+Convert.ToChar (26);
SerialPort.Output =cmdsend;
Thread.Sleep (10000);
cmd=SerialPort.Input.ToString ();
}



Thread.Sleep(1000);

timer1.Start();


this is the code i am using in my application

i am using timer control to my control process of reading and sending

separately using single rs232 port

Hope you will get the best

Thanks and regards

Nmsreddi
Jan 5 '07 #1
0 4463

Sign in to post your reply or Sign up for a free account.

Similar topics

1
8794
by: Andreas Horneff | last post by:
Hi @ all, I've got a problem with serial communication in Borland C++ Builder. I've already found a lot of stuff about serial communication in the internet, but it dosen't work. What I want...
11
7058
by: sarah | last post by:
hI, I have a project. I need to realise serial communication between PC and Altera FPGA in c or c++. The function of FPGA is working well. it can send data to uart. Does anybody know how to...
3
3130
by: carmen | last post by:
I'm working in an aplication for a Smart Device that need to "talk" with a printer continuosly through the serial port. I'm trying to use the John Hint's sample code "Use P/Invoke to develop a .NET...
4
4724
by: Vidya Bhagwath | last post by:
Hello Experts, I am porting the C++ code into the Visual C#.NET. My C++ code is mainly based on the serial communication. So I am using the windows structure such as DCB.. etc and the windows...
6
2831
by: Leandro Berti via DotNetMonster.com | last post by:
Hi All, I wrote a code to do serial communication with an equipament. When i use the code outside of threaded class it seens work properly, but when i put inside a class and execute a thread in...
5
1358
by: Jack Black | last post by:
Hi, all! Using VS.Net '03 under Win2k3 Server; clients will be XP, Win2k... I'm just beginning to look into how I would go about building serial communication apps in VB.Net, and am not sure...
4
11156
by: joe bloggs | last post by:
I am writing a mobile application to interface with a legacy system and I am planning to use web services to communicate with this system. The legacy system receives data through a serial port. ...
0
1972
by: usagimys | last post by:
Hi all, i'm very new in serial port communication.. here i got some problem in writing to the serial port.. i have done the connection successfully.. let me explain my situation.. i'm doing a system...
0
4544
by: ghjk | last post by:
I want to read sms from GSM modem using C# in serial communication. I wrote the code. But i want to do it automatically. I put my code here and please tell me how can i do it automatically. ...
0
2891
by: Dhananjay | last post by:
Hi, I am working on an VB.Net application which I want to communicate to external device using comm port (Serial Port) . So for that first I am trying to simulate the communication on serial...
0
7349
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7506
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5659
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4734
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3219
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3210
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1572
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
780
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
445
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.