elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.
 
Inicio Ayuda Ingresar Registrarse
16 Octubre 2008, 02:34  



+  Foro de elhacker.net
|-+  Seguridad Informática
| |-+  Hacking Avanzado
| | |-+  Hacking Mobile (Moderadores: Gospel, SirGraham)
| | | |-+  C# System.IO.Port SerialPort
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Imprimir
Autor Tema: C# System.IO.Port SerialPort  (Leído 1973 veces)
hoofmen

Desconectado Desconectado

Mensajes: 12


Ver Perfil
C# System.IO.Port SerialPort
« en: 01 Mayo 2006, 01:52 »

Estoy haciendo una mini aplicacion en C# para hacer una consola de comandos AT para enviar a mi telefono por el puerto com, pero solo e logrado conectarme al equipo. pero este no atiene los comandos que le envio, alguien ya ah hecho esto?

public partial class Form1 : Form
    {
        private SerialPort port = new SerialPort("COM7", 96000, Parity.None, 8, StopBits.One);

        public Form1()
        {
            InitializeComponent();
            port.DataReceived += new SerialDataReceivedEventHandler(port_DataReceived);
        }

        private void port_DataReceived(object sender, SerialDataReceivedEventArgs e)
        {
            this.Invoke(new EventHandler(DoUpdate));
        }

        private void DoUpdate(object s, EventArgs e)
        {
            txtLog.AppendText("----------------\n");           
            txtLog.AppendText(port.ReadExisting());
        }

        private void btnConectar_Click(object sender, EventArgs e)
        {
            if (port.IsOpen == false)
            {
                try
                {
                    port.Open();
                    txtLog.AppendText("Conectado COM7\n");
                }

                catch (Exception oex)
                {
                    MessageBox.Show(oex.ToString());
                }
            }
        }

        private void btnDesconectar_Click(object sender, EventArgs e)
        {
            if (port.IsOpen)
            {
                port.Close();
                txtLog.AppendText("Cerrada la conexion...\n");
            }
        }

        private void btnEnviar_Click(object sender, EventArgs e)
        {
            try
            {
                port.WriteLine(txtCmd.Text);

            }
            catch (Exception wex)
            {
                MessageBox.Show(wex.ToString());
            }
        }
    }
En línea
Gospel
Moderador
*****
Desconectado Desconectado

Mensajes: 1.581



Ver Perfil WWW
Re: C# System.IO.Port SerialPort
« Respuesta #1 en: 01 Mayo 2006, 10:49 »

En esta página tienes la documentación de Pocket Bluesnarfer, una herramienta para Pocket PC q hace lo mismo que tu quieres: enviar comandos AT y capturar respuestas.

http://foro.elhacker.net/index.php/topic,109187.0.html

Puedes echarle un ojo al código eVC++, q se distribuye libremente.

¿Te conectas por cable de serie, por IrD, Bluetooth...??
¿Has probado a enviar comandos AT q no requieran respuesta, por ejemplo: ATD619123456;? A lo mejor envías bien pero no capturas la respuesta adecuadamente...

Por si acaso échale un ojo a mi código de Pocket Bluesnarfer, en especial, la parte en q se recibe la respuesta y se parsean los retornos de carro.

Te adjunto algo de código:

Código:
BOOL CIrdaPort::WaitForResponse(CString& strResponse, DWORD dwTimeout) const
{
    ASSERT(IsOpen());

    BOOL bData = FALSE;
BOOL bBucle = FALSE;


unsigned char cCurrentChar  = '\0';
    unsigned char cLastChar     = '\0';
    unsigned char cLastLastChar = '\0';

    strResponse.Empty();

    DWORD dwStartTicks = GetTickCount();

    while (TRUE)
    {
        // Has the timeout occured?

if ((GetTickCount() - dwStartTicks) >= dwTimeout)
        {
      return FALSE;
        }

        // Receive the data from the serial port

        if (Read(&cCurrentChar, sizeof(cCurrentChar)) > 0)
        {
            // Reset the idle timeout since data was received

            dwStartTicks = GetTickCount();

if (isprint(cCurrentChar) && cLastLastChar == 0x0D && cLastChar == 0x0A && !bData)
{
bData = TRUE;  // Received start sequence (<CR><LF>)
}
else if (isprint(cLastLastChar) && cLastChar == 0x0D && cCurrentChar == 0x0A && bData)
{
//Tratamiento del comando LEER SMS
if (strResponse.Find(_T("CMGR")) > -1)
{
if (cLastLastChar == 0x22) //Si el último carácter es ", entonces es la cabecera.
{
//AfxMessageBox(strResponse);
}
else //Sino, entonces es el cuerpo del sms
{
break;

}

}
else //Tratamiento del resto de comandos
{
break;  // Received end sequence (<CR><LF>)
}
}


            // Add the character to the string

            if (bData && isprint(cCurrentChar))
            {
                char szANSI[2] = { cCurrentChar, '\0' };

                strResponse += CString(szANSI);
            }

            cLastLastChar = cLastChar;
cLastChar     = cCurrentChar;
        }
        else
        {
            Sleep(10);
        }

    } // while (TRUE)


    return TRUE;
}

BOOL CIrdaPort::Send(const CString& strSend, DWORD dwTimeout /*= 5000*/) const
{
    ASSERT(IsOpen());

    USES_CONVERSION; // Need for T2CA() macro

VERIFY(PurgeComm(m_hPort, PURGE_TXABORT | PURGE_RXABORT | PURGE_TXCLEAR | PURGE_RXCLEAR));

    CString str(strSend);

    str += _T("\r"); // Add <CR> at the end of the string

    return WriteWithTimeout(T2CA((LPCTSTR) str), str.GetLength(), dwTimeout);
}
En línea

hoofmen

Desconectado Desconectado

Mensajes: 12


Ver Perfil
Re: C# System.IO.Port SerialPort
« Respuesta #2 en: 02 Mayo 2006, 00:09 »

Hola, estaba examinando el SRC, de bluesnarfer pero al abrir el proyecto en el vEVc++ me dice que hubo un error al cargar el workspace ya que el IrdaMobile.rc(10)

fatal error RC1015: cannot open include file 'afxres.h'

eso me impide cargar todo el proyecto y menos compilarlo, ademas que afxres.h no lo encuentro

saludos
En línea
Gospel
Moderador
*****
Desconectado Desconectado

Mensajes: 1.581



Ver Perfil WWW
Re: C# System.IO.Port SerialPort
« Respuesta #3 en: 02 Mayo 2006, 00:50 »

Vaya, q extraño...

Tienes embedded Tools 3.0 y el SDK Windows Mobile 2002 instalado? Necesita esa configuración. Con EVC++ 4 no tira...
En línea

hoofmen

Desconectado Desconectado

Mensajes: 12


Ver Perfil
Re: C# System.IO.Port SerialPort
« Respuesta #4 en: 02 Mayo 2006, 05:02 »

Efectivamente estoy usando SDK 2003 con eVC++ 4.0 + SP3

Gracias Gospel
En línea
oacosta

Desconectado Desconectado

Mensajes: 1


Ver Perfil
Re: C# System.IO.Port SerialPort
« Respuesta #5 en: 11 Mayo 2006, 19:24 »

si es muy sencillo

lo que pasa es q cuando ejecutas comandos AT es necesario enviarle al fin de la trama un tab y enter siempre y cuando los comandos no sean +++ (colgar la llamada) o  a\ repetir comando anterior ejecutado.
Te envio un metodo que cree para este fin:

        private void WritePortSerie(string strWrite, bool blnComandoAT)
        {
            objTxModem.ExecCommandAT = blnComandoAT;
            try
            {
                if (objTxModem.ExecCommandAT == true && (strWrite.Trim().Length > 0 && RS232.IsOpen))
                {
                        /*salida*/
                        /*************************/
                        RS232.DtrEnable = true; // DTR data terminal ready
                        RS232.RtsEnable = true; // RTS request to sent
                        /*************************/
                        //ejecuta comandos at
                        if (strWrite.Trim() == "+++")
                         RS232.Write(strWrite);
                        else if (strWrite.Trim() == "A/")
                         RS232.Write(strWrite);
                        else
                         RS232.Write(strWrite + "\r" + "\n");
                        //cadena enviada
                    txtComandoEnviado.AppendText("Cadena enviada: " + strWrite.ToString().Trim() + "\n");                                       
                }
                else if ((strWrite.Trim().Length > 0 && RS232.IsOpen) && objTxModem.ExecCommandAT == false)
                {
                    RS232.DtrEnable = true; // DTR data terminal ready
                    RS232.RtsEnable = true; // RTS request to sent
                    RS232.Write(strWrite);
                }
            }
            catch (Exception ex)
            {
                txtComandoEnviado.AppendText("--- Error--- general Escribiendo en el puerto: " + ex.Message + "\n");
            }
        }
 

Cordialmente,
Omar Acosta
oeac_llll@hotmail.com
www.dyetron.com

En línea
Páginas: [1] Ir Arriba Imprimir 
Ir a:  







Consolas     La Web de Goku     MilW0rm     MundoDivx

Hispabyte     Truzone     TodoReviews     ZonaPhotoshop

hard-h2o modding    Foros de ayuda    Yashira.org    Videojuegos    indetectables.net   

Noticias Informatica    Seguridad Informática    ADSL    Foros en español    eNYe Sec

Todas las webs afiliadas están libres de publicidad engañosa.

Powered by SMF 1.1.6 | SMF © 2006-2008, Simple Machines LLC