Also, ich habe jetzt diesen Code... aber irgendwie sendet er immernoch nicht..
Das Programm sagt mir zwar "Done..." aber meine RelaisPlatine macht nicht "Klick"....

Woran kann das liegen?



//#include <cstdlib>
#include <windows.h>
//#include <string.h>
//#include <stdio.h>
#include <iostream.h>
#include <conio.h>
#include <dos.h>
//#include <stdlib.h>
#include <time.h>
#include <unistd.h>
//#include <string>




int main()
{

DCB dcb;
HANDLE hComm;
BOOL fSuccess;
char *pcCommPort = "COM2";

hComm = CreateFile( pcCommPort,
GENERIC_READ | GENERIC_WRITE,
0, // must be opened with exclusive-access
NULL, // no security attributes
OPEN_EXISTING, // must use OPEN_EXISTING
0, // not overlapped I/O
NULL // hTemplate must be NULL for comm devices
);

if (hComm == INVALID_HANDLE_VALUE)
{
// Handle the error.
printf ("CreateFile failed with error %d.\n",
GetLastError());

}

// Build on the current configuration, and skip setting the size
// of the input and output buffers with SetupComm.

fSuccess = GetCommState(hComm, &dcb);

if (!fSuccess)
{
// Handle the error.
printf ("GetCommState failed with error %d.\n",
GetLastError());

}

// Fill in DCB: 57,600 bps, 8 data bits, no parity, and 1 stop bit.

dcb.BaudRate = CBR_9600; // set the baud rate
dcb.ByteSize = 8; // data size, xmit, and rcv
dcb.Parity = NOPARITY; // no parity bit
dcb.StopBits = ONESTOPBIT; // one stop bit

fSuccess = SetCommState(hComm, &dcb);

if (!fSuccess)
{
// Handle the error.
printf ("SetCommState failed with error %d.\n",
GetLastError());

}
else
{
char frame[4];
frame[0] = 1;
frame[1] = 1;
frame[2] = 0;
frame[3] = static_cast<BYTE>(frame[0] ^ frame[1] ^ frame[2]);
DWORD dwBytesWritten = 0;
WriteFile(hComm, &frame, sizeof
(frame), &dwBytesWritten, NULL);
//TransmitCommChar(hComm,frame);
frame[0] = 3;
frame[1] = 1;
frame[2] = 5;
frame[3] = static_cast<BYTE>(frame[0] ^ frame[1] ^ frame[2]);

WriteFile(hComm, &frame, sizeof
(frame), &dwBytesWritten, NULL);
BOOL bResult;


DCB dcb_alt;
SetCommState(hComm, &dcb_alt);

bResult = CloseHandle(hComm);
hComm = INVALID_HANDLE_VALUE;
}

cout << "Done...";
cout << endl ;
getch();
return 0;
}