Kommunikation mit RS232 zu pc

reto-meier

Mitglied
moin...
habe eine Frage: wie kann ich einen String per serielle schnitstelle an com1 (vom Laptop) bzw. an den damit verbundenen desktop-pc schicken?

ich habe die schnittstelle bereits initialisiert, finde jedoch nicht heraus wie ich etwas senden kann...?
Kennt jemand ein Programm, welches anzeigt was auf den com-SS anliegt?
anschliessend noch mein code...
PHP:
//RS 232-Schnittstelle (seriell)

#include <cstdlib>
#include <iostream>
#include <stdio.h>
#include <conio.h>
#include <windows.h>


using namespace std;
char meldung[50];

int main(int argc, char *argv[])
{
	unsigned int value;
	HANDLE hCom;
	DCB ComSettings;
	DWORD write,written;
	
	ZeroMemory(&ComSettings, sizeof(DCB));
	
	ComSettings.DCBlength = sizeof(DCB);
	ComSettings.BaudRate = CBR_115200;
	ComSettings.fBinary = 1;
	ComSettings.fTXContinueOnXoff = 1;
	ComSettings.ByteSize = 8;
	ComSettings.Parity = NOPARITY;
	ComSettings.StopBits = ONESTOPBIT;
	
	hCom = CreateFile( "COM1",
	    GENERIC_READ | GENERIC_WRITE,
    	0,                                                 // must be opened with exclusive-access
    	NULL,                                              // default security attributes
    	OPEN_EXISTING,                                     // must use OPEN_EXISTING
    	0,                                                 // not overlapped 1/O
    	NULL                                               // hTemplate must be NULL for comm devices
    	);
    if (hCom == INVALID_HANDLE_VALUE)
	{
		cout << "COM1 konnte nicht geoeffnet werden." << endl << endl;
	}
	else
	{
		cout << "COM1 wurde erfolgreich geoeffnet." << endl;
		if (SetCommState(hCom,&ComSettings))
		{
			cout << "COM1 wurde erfolgreich initialisiert." << endl << endl;
			
            while(1)
			{
				cout << "Textmeldung auf Terminal senden: \n";
				scanf("%s",meldung);
			    
                
                HIER KÄHME JETZT DER WRITE BEFEHL!
			    
				HIER MEIN ANSATZ:
                /*if (!WriteFile(ComPort,meldung,write,&written,NULL))
				cout << "Error" << endl;*/
			}
		}
		else
		{
			cout << "COM1 konnte nicht initialisiert werden." << endl << endl;
			cout << "LastError: " << GetLastError() << endl;
		}
	}
	system("pause");
    return EXIT_SUCCESS;
}

hoffe dass ihr mir helfen könnt....kann mein problem ansonsten noch anders erleutern...
 
Zurück