Filipecarvas@hotmail.com Posted March 12, 2013 at 05:11 PM Report #498903 Posted March 12, 2013 at 05:11 PM (edited) Boa tarde. Estou a desenvolver uma Windows App em que comunica com um telefone enviando-lhe comandos AT e apresento o resulado do comando enviado numa textbox. Parece uma coisa simples mas não estou a conseguir ler o resultado do comando AT. Alguém me sabe dizer o que está mal no código? Tenho um botao que procura as portas disponiveis, outro para abrir a conexao, outro para fechar a conexao e mais um para enviar o comando AT. Tenho uma textbox vazia em que quando envio o comando AT vai apresentar o resultado nessa textbox. Desde já um muito obrigado. public partial class Form1 : Form { SerialPort sp; public Form1() { InitializeComponent(); } private void btSeacrh_Click(object sender, EventArgs e) { string[] ports = SerialPort.GetPortNames(); foreach (string port in ports) { comboBoxPorts.Items.Add(port); } } private void btSend_Click(object sender, System.EventArgs e) { sp.DataReceived += new SerialDataReceivedEventHandler(DataReceivedHandler); string data = tbEnviarDados.Text.ToString(); sp.Write(data); } private void DataReceivedHandler(object sender, SerialDataReceivedEventArgs e) { SerialPort sp = (SerialPort)sender; string dados = sp.ReadExisting(); tbDadosRecebidos.Text = dados; } private void btAbrirConexao_Click(object sender, System.EventArgs e) { string PortName = comboBoxPorts.Text.ToString(); sp = new SerialPort(PortName, 115200, Parity.None, 8, StopBits.One); sp.Open(); } private void btFecharConexao_Click(object sender, System.EventArgs e) { sp.Close(); } } Edited March 12, 2013 at 06:17 PM by Caça GeSHi
bmaster26 Posted November 28, 2013 at 12:28 PM Report #535437 Posted November 28, 2013 at 12:28 PM Conseguiste resolver esta situação?
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now