Click here to Skip to main content
15,881,413 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hello

i am trying to receive and display data from serial port
i am getting message of open port but not getting txt what i am sending from my mobile . I have dongle connected to pc and sending sms from mobile

thanks in advance


C#
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.IO.Ports;
using System.IO;
using System.Windows.Forms;
using System.Globalization;
using System.Threading;
using System.Resources;


namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        
        public Form1()
        {
           
            InitializeComponent();
            if (!mySerialport.IsOpen)
            {
                mySerialport.Open();
                tbRX.Text = "port opened   :)";
            }
            else {
                tbRX.Text = "port busy :(";           
                       
            }
        }
        private string rxstring;
   
        private void Form1_Load(object sender, EventArgs e)
        {
        
        }
       

        private void mySerialport_DataReceived(object sender, SerialDataReceivedEventArgs e)
        {
            rxstring = mySerialport.ReadExisting();
            this.Invoke(new EventHandler(dsiplayTEXT));
        }
        private void dsiplayTEXT(object o, EventArgs e)
        {
            tbRX.AppendText(rxstring);        
        
        }
    }
}
Posted
Updated 10-Aug-15 22:27pm
v6

Please refer methods for reading and writing text in serial port here: https://msdn.microsoft.com/en-us/library/system.io.ports.serialport_methods(v=vs.110).aspx[^]
 
Share this answer
 
Comments
Member 8893861 17-Aug-15 6:07am    
could you provide me any good tutorial where i can find solution to my problem .
My gsm modem is connected to pc via serial port converter
i can see that port is opened
but i dont know what to do further

thank you
sreeyush sudhakaran 17-Aug-15 6:41am    
https://www.youtube.com/watch?v=pdUZJUv7vgM
You can't just open the serial port and expect to receive messages!
You have to use the right AT Commands to tell the mobile what to do: Introduction to AT commands and its uses[^]

And you don't just append text to a text box in the DataReceived event either - it happens on a different thread, so you will get a cross threading exception is you try. You need to Invoke the control to set it's text property.
 
Share this answer
 
Comments
Member 8893861 17-Aug-15 6:08am    
could you provide me any good tutorial where i can find solution to my problem .
My gsm modem is connected to pc via serial port converter
i can see that port is opened
but i dont know what to do further

thank you
OriginalGriff 17-Aug-15 6:14am    
Start with Google - or just follow the link I gave you last week?
Your question is 2 completely unrelated questions:
- Communicate with your device on serial port.
- display something.

For your device on serial port, you need to understand what is the device and how to communicate with it.
 
Share this answer
 
Comments
Member 8893861 17-Aug-15 6:06am    
could you provide me any good tutorial where i can find solution to my problem .
My gsm modem is connected to pc via serial port converter
i can see that port is opened
but i dont know what to do further

thank you
Patrice T 17-Aug-15 14:14pm    
Start by exploring links of solutions 1 and 2.
Most modems respond to the AT standard.
As OriginalGriff said, use google to find tutos and examples.
C# is not my specialty :( so I can't really help you further.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900