Ich hab ein ganz ähnliches Problem.
Mein Programm soll erstmal nur aus einer File Datenauslesen, und an eine
Schnittstelle schicken. Das Gerät an diser Schnittstelle intzerpretiert
die Daten, und schickt antworten zurück. Es gibt zwar keine Fehler, aber
beim Debuggen passt was nicht, das macht er nicht gescheit.... Aber sehr
selbst:
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
HANDLE hComm;
int open_com1(void)
{
int ret_val = 1;
// open com1 port
hComm = CreateFile( "COM1",
GENERIC_READ | GENERIC_WRITE,
0,
0,
OPEN_EXISTING,
FILE_FLAG_OVERLAPPED,
0);
if (hComm == INVALID_HANDLE_VALUE) {
// error opening port; abort
printf("error in open_com1");
ret_val = 0;
}
else {
// configure com1 port
DCB dcb;
FillMemory(&dcb, sizeof(dcb), 0);
if (!GetCommState(hComm, &dcb)) { // get current DCB
// Error in GetCommState
ret_val = 0;
}
else {
// Update DCB rate.
dcb.BaudRate = CBR_57600 ;
// Set new state.
if (!SetCommState(hComm, &dcb)) {
// Error in SetCommState. Possibly a problem with the
communications
// port handle or a problem with the DCB structure itself.
ret_val = 0;
}
}
}
return ret_val;
}
int read_com1(char *p_buf, int number)
{
int ret_val = 0;
long number_bytes_written = 0;
ReadFile (hComm, // Port handle
p_buf, // Pointer to the data to read
number, // Number of bytes to read
&number_bytes_written, // Pointer to the number of bytes read
NULL
);
return ret_val;
}
int write_com1(char *p_buf, int number)
{
int ret_val = 0;
long number_bytes_written = 0;
WriteFile (hComm, // Port handle
p_buf, // Pointer to the data to write
number, // Number of bytes to write
&number_bytes_written, // Pointer to the number of bytes
written
NULL
);
return ret_val;
}
int close_com1()
{
int ret_val = 0;
CloseHandle(hComm);
return ret_val;
}
int main()
{
FILE *fp_input;
int ret_val = 0;
char input_buffer[30];
char output_buffer[30];
if(open_com1() == 1) {
if((fp_input= fopen("text.txt", "r")) != NULL) {
do {
// send command to AVR32 application
write_com1("send 25", 7);
// read data from input file
fread(input_buffer, sizeof( char ), 25,fp_input);
// write data via COM1 to AVR32 application
write_com1(input_buffer, 25);
// send command to AVR32 application
write_com1("buffer", 6);
// read data from COM1
read_com1(output_buffer, 25);
}while(!feof(fp_input));
}
fclose(fp_input);
fp_input=NULL; //Macht den Pointer ungültig
}
else {
printf("\nCouldn't open COM1");
}
close_com1();
return ret_val;
}
Die Fehlermeldung beim debuggen:
"ntdll.dll" wurde geladen. Es wurden keine entsprechenden
Symbolinformationen gefunden.
"C:\WINDOWS\system32\kernel32.dll" wurde geladen. Es wurden keine
entsprechenden Symbolinformationen gefunden.
Thread 0xD4 wurde mit Code 0 (0x0) beendet.
Das Programm "C:\Dokumente und Einstellungen\gefische\Eigene
Dateien\Debug\Cpp1.exe" wurde mit Code 0 (0x0) beendet.