c# threading and getting COM port of attached phone
Posted
by I__
on Stack Overflow
See other posts from Stack Overflow
or by I__
Published on 2010-06-13T17:40:31Z
Indexed on
2010/06/13
17:42 UTC
Read the original article
Hit count: 214
c#
i have the following code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public class ThreadWork
{
public static void DoWork()
{
}
}
private void Form1_Load(object sender, EventArgs e)
{
ThreadStart myThreadDelegate = new ThreadStart(ThreadWork.DoWork);
Thread myThread = new Thread(myThreadDelegate);
myThread.Start();
// Begin communications
serialPort1.Open();
serialPort1.Write("AT+CMGF=1\r\n");
//Thread.Sleep(500);
serialPort1.Write("AT+CNMI=2,2\r\n");
//Thread.Sleep(500);
serialPort1.Write("AT+CSCA=\"+4790002100\"\r\n");
//Thread.Sleep(500);
}
private void serialPort1_DataReceived_1(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
{
string response = serialPort1.ReadLine();
this.BeginInvoke(new MethodInvoker(() => textBox1.AppendText(response + "\r\n")));
}
}
}
what i am trying to do is send AT COMMANDS to my phone which is attached to the computer through USB
how do i know how to configure the properties of the serial port? (like which COM is the phone on [it's attached through USB], what about baudrate and databits?)
when i run the program nothing really happens, i would like to send AT COMMANDS to my phone and the textbox is there to receive the response from my phone
this is my first time using threads. am i using them correctly? what is the purpose of it in the current example? is it to just have a delay between send a response?
what am i doing wrong?
© Stack Overflow or respective owner