RS232 Bitübertragung

BlackSunrise

Grünschnabel
Hallo, ich hoffe ihr könnt mir weiter helfen.
Ich hab schon längere Zeit bei google.de und auch hier gesucht, auch einige Sachen zur initialisierung der Schnittstelle etc. gefunden.
Mein Problem ist jedoch folgendes. Ich muss keine Direkten Daten/Dateien übertragen, sondern jediglich einzelne Bitmuster.
Das ganze soll dann von einem Microprozessor (m16c) ausgewertet werden.
Folgende Seiten habe ich bis jetzt als Referenz genommen:
- Serial1 (funktioniert soweit, jedoch zu aufwendig anzupassen)

- Serial2 (kann nicht erzeugt werden, fehler beim external linken :( (Hello World programm)

Zurück zum Problem:

Ich muss also zB. ein Bitmuster '0000 0001' an Com 2 übertragen.

Den ablauf, würde ich am liebsten an diesen Quellcode (MS) oder an den vom zweiten Link oben anknüpfen (sollte das Problem mit dem linken behoben werden können :()

/* A sample program to illustrate setting up a serial port. */

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

int main(int argc, char *argv[])
{
DCB dcb;
HANDLE hCom;
BOOL fSuccess;
char *pcCommPort = "COM1";

hCom = 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 (hCom == INVALID_HANDLE_VALUE)
{
// Handle the error.
printf ("CreateFile failed with error %d.\n", GetLastError());
getch();
return (1);
}

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

fSuccess = GetCommState(hCom, &dcb);

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

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

dcb.BaudRate = CBR_57600; // 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(hCom, &dcb);

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

printf ("Serial port %s successfully reconfigured.\n", pcCommPort);
getch();
return (0);

}

//edit: Das ganze müsste noch Software Handshaking haben :(


Ich hoffe das der Post nicht allzu verwirrend erscheint :rolleyes:
Jedoch muss ich dieses Problem schnellst möglichst lösen, auch wenn ich nicht viel ahnung von c/c++ habe :confused:



Danke an Alle, die mir helfen können, egal welcher Art. :)
 
Zuletzt bearbeitet:

Neue Beiträge

Zurück