473,585 Members | 2,552 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:0x800A1 F45

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....
*************** *************** ************cod e************** **********
SerialPort is the name of my AxMscomm control

SerialPort.Comm Port=1;
if(SerialPort.P ortOpen)
SerialPort.Port Open=false;

SerialPort.RThr eshold=1;
SerialPort.Sett ings="9600,n,8, 1";
SerialPort.DTRE nable=true;
SerialPort.RTSE nable=true;
SerialPort.Hand shaking=MSCommL ib.HandshakeCon stants.comNone;
SerialPort.Inpu tMode=MSCommLib .InputModeConst ants.comInputMo deText;
SerialPort.Inpu tLen=0;
SerialPort.Null Discard=false;


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

SerialPort.Port Open=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.OnCo mm +=new EventHandler(Se rialPort_OnComm );

try
{
timer1.Stop();


if(SerialPort.I nBufferCount>0)
{
Thread.Sleep(10 00);

ProcessSerialpo rtdata((string) SerialPort.Inpu t);

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


private void ProcessSerialpo rtdata(string input)
{ richTextBox1.Te xt="";
richTextBox1.Ap pendText(input+ "\n");
r


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

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


}


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


timer1.Stop();
string cmdsend="AT+CMG S="+"xxxxxxxxxx "+Convert.ToCha r(13);

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

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



Thread.Sleep(10 00);

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 4486

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

Similar topics

1
8816
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 to do: I want to connect only one button to my com port. If the button is pressed,
11
7070
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 realise it in c or c++? Thanks
3
3141
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 Base Class Library for Serial Device Communication" but I'm new with VC# and need some basic rules because I have a lot of compilation errors....
4
4729
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 functions frequently in my C++ code. I came to know how to import the windows functions into Visual C#.NET. But what is the method to import windows...
6
2852
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 the first seconds the communication is ok, later i receive read/write error. I?ve been in MSDN site and there i discover that the read/write error...
5
1362
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 where to begin looking for info, libraries, etc. The applications will basically query serial devices for whatever info they contain, clear it, etc......
4
11181
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. What I would like to do is make the serial port accessible via a web service. The web service and the legacy application would be running on the...
0
1984
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 for toll.. here, there have a device name TFI (Toll Fare Indicator)..This device has to display 3 things (vehicle class, fare, and message).. now,...
0
4552
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. public partial class SMS : Form { //create an Serial Port object SerialPort sp = new SerialPort(); public SMS()...
0
2896
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 port between two computers using HYper terminal on both the machines. Both these computers are connected on serial port using DB9(f) null modem...
0
7836
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8199
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8336
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7950
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6606
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3835
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2343
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 we have to send another system
1
1447
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1175
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.