-
-
Neuer Benutzer
Öfters hier
hmm.. also neues problem..
Wie oben funktioniert das Programm..
Aber wenn ich jetzt da ne AuswahlMöglichkeit reinbau, funktionierts nichtmehr..
(die fett gedruckten Teile sind neu. mit denen funktioniert es nichtmehr)
#include <windows.h>
#include <iostream.h>
#include <conio.h>
#include <dos.h>
#include <time.h>
#include <unistd.h>
int main()
{
int relais;
cout<<"\nBitte wählen sie das Relais aus: "
cin>>relais;
DCB dcb;
HANDLE hComm;
BOOL fSuccess;
char *pcCommPort = "COM3";
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_19200; // 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, (BYTE)frame, &dwBytesWritten, NULL);
//TransmitCommChar(hComm,frame);
frame[0] = 3;
frame[1] = 1;
frame[2] = relais;
frame[3] = static_cast<BYTE>(frame[0] ^ frame[1] ^ frame[2]);
WriteFile(hComm, &frame, (BYTE)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;
}
Berechtigungen
- Neue Themen erstellen: Nein
- Themen beantworten: Nein
- Anhänge hochladen: Nein
- Beiträge bearbeiten: Nein
-
Foren-Regeln
Lesezeichen