elso_utemes Creative Commons License 2005.03.02 0 0 11

C++ Builder 6 -ban szeretnek soros portra egy 'a' (ascii 61) karaktert kikuldeni, de nem mukodik a program.

 

Mi lehet a baj?

 


//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;

HANDLE hCom;

//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
}

//---------------------------------------------------------------------------
void __fastcall TForm1::BitBtn1Click(TObject *Sender)
{
BYTE Byte=61;
DWORD dwError,
      dwNumBytesWritten;

WriteFile (hCom,              // Port handle
           &Byte,              // Pointer to the data to write
           1,                  // Number of bytes to write
           &dwNumBytesWritten, // Pointer to the number of bytes
                               // written
           NULL                // Must be NULL for Windows CE
 );
}
//---------------------------------------------------------------------------

void __fastcall TForm1::FormCreate(TObject *Sender)
{
        DCB dcb;
        DWORD dwError;
        BOOL fSuccess;

        hCom = CreateFile("COM1",
          GENERIC_READ | GENERIC_WRITE,
          0,    /* comm devices must be opened w/exclusive-access */
          NULL, /* no security attrs */
          OPEN_EXISTING, /* comm devices must use OPEN_EXISTING */
          0,    /* not overlapped I/O */
          NULL  /* hTemplate must be NULL for comm devices */
         );

         dcb.BaudRate = 9600;
         dcb.ByteSize = 8;
         dcb.Parity = NOPARITY;
         dcb.StopBits = ONESTOPBIT;

         SetCommState(hCom, &dcb);
}
//---------------------------------------------------------------------------