elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.
 
Inicio Ayuda Ingresar Registrarse
30 Agosto 2008, 09:52  



+  Foro de elhacker.net
|-+  Seguridad Informática
| |-+  Hacking Avanzado
| | |-+  Hacking Mobile
| | | |-+  RAW C/C++ para programar Puertos Seriales
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Imprimir
Autor Tema: RAW C/C++ para programar Puertos Seriales  (Leído 275 veces)
hoofmen

Desconectado Desconectado

Mensajes: 12


Ver Perfil
RAW C/C++ para programar Puertos Seriales
« en: 02 Mayo 2006, 05:08 »

Saludos,
  Despues de varios intentos fallidos de hacer aplicaciones managed que ocupen puertos seriales (para usar Bluetooth), me meti de lleno en C++( que es un lenguaje que me cuesta).
Logre hacer esta aplicacion consola:

#include <stdio.h>
#include <windows.h>

HANDLE fileHandle;
HWND wForm = NULL;

int OpenSerialPort();
int CloseSerialPort();
int SendMsg();

int OpenSerialPort()
{
    WCHAR comPort[30];
   
    wsprintf(comPort,L"COM%d",7);

    if (fileHandle == NULL){                                     
        fileHandle = CreateFile(comPort, GENERIC_WRITE ,0,NULL,OPEN_EXISTING,0,0);
        if (fileHandle == INVALID_HANDLE_VALUE){
            MessageBox(NULL,L"No se pudo crear el COM 7",L"Aviso",MB_OK);
            fileHandle = NULL;
            return 0;
        }
    }
    return 1;
}

int CloseSerialPort()
{
    if (fileHandle != NULL){
        CloseHandle(fileHandle);
        fileHandle = NULL;
      MessageBox(NULL,L"COM cerrado",L"Aviso",MB_OK);
      return 1;
    }
   return 0;
}

int SendMsg()
{   
    DWORD dwSize = 0, dwWritten = 0;   
    const int key = 13;

    WriteFile(fileHandle, &key, sizeof(key), &dwWritten, NULL);
    printf("Mensaje enviado\n");   
    MessageBox(NULL,L"Mensaje Enviado",L"Aviso",MB_OK);
   return 1;
}

int main (int argc, char** argv)
{
    if (!OpenSerialPort())
        return -1;

    SendMsg();
   
    if (!CloseSerialPort())
        return -1;

    system("pause");
    return 1;
}


lo unico que me interesa es mandar el numero 13 por el serial port, esta aplicacion desde el PC me funciona sin problemas, pero cuando la trato en la PPC, no me deja, en la PPC y PC tengo com 8 entrada, com 7 salida, estoy haciendo algo mal? todo mal??

saludos y gracias
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.5 | SMF © 2006-2008, Simple Machines LLC