Sers Leute, ich beschäftige mich mit der V24 Schnittstelle des PCs. Ich verwende Windows und möchte über ein C-Programm auf die serielle Schnittstelle zugreifen. Nachdem ich nun stundenlang auf der Microsoft Support-Page die Artikel durchgelesen habe, gelingt es mir immerhin schon mit TransmitCommChar() einen Charakter rauszugeben.Wie schreibe und lese ich ? Was ich eigentlich möchte, ist Lesen und Schreiben im Polling-Modus. Hier kommt gleich das nächste Problem: Wie generiere ich einen Timer in C. Ich hoffe jemand von euch hat eine Idee. Vielen Dank schon im voraus. Gruß Chris
ein paar antworten... CreateFile,ReadFile,WriteFile <--- damit zugreiffen.. aus der msdn lib.. -----snip---- Communications Resources The CreateFile function can create a handle to a communications resource, such as the serial port COM1. For communications resources, the dwCreationDisposition parameter must be OPEN_EXISTING, and the hTemplate parameter must be NULL. Read, write, or read-write access can be specified, and the handle can be opened for overlapped I/O. For more information about communications, see Communications. Disk Devices Windows NT: You can use the CreateFile function to open a disk drive or a partition on a disk drive. The function returns a handle to the disk device; that handle can be used with the DeviceIOControl function. The following requirements must be met in order for such a call to succeed: The caller must have administrative privileges for the operation to succeed on a hard disk drive. The lpFileName string should be of the form \\.\PHYSICALDRIVEx to open the hard disk x. Hard disk numbers start at zero. For example: String Meaning \\.\PHYSICALDRIVE2 Obtains a handle to the third physical drive on the user's computer. The lpFileName string should be \\.\x: to open a floppy drive x or a partition x on a hard disk. For example: String Meaning \\.\A: Obtains a handle to drive A on the user's computer. \\.\C: Obtains a handle to drive C on the user's computer. -----snip und noch ein bisserl mehr infos ;) ---- snip If the name of the port is \\.\COM10, the correct way to specify the serial port in a call to CreateFile() is as follows: CreateFile( "\\\\.\\COM10", // address of name of the communications device fdwAccess, // access (read-write) mode 0, // share mode NULL, // address of security descriptor OPEN_EXISTING, // how to create 0, // file attributes NULL // handle of file with attributes to copy ); ----snip nun noch mehrere fragen... willst du c oder cpp nehmen für cpp... mfc oder anderes widgetset??? wenn mfc => CWnd => SetTimer ;) wenn du kein von cwnd abgeleitetes klässchen hast (z.b consol prog) ----snip SetTimer The SetTimer function creates a timer with the specified time-out value. UINT SetTimer( HWND hWnd, // handle of window for timer messages UINT nIDEvent, // timer identifier UINT uElapse, // time-out value TIMERPROC lpTimerFunc // address of timer procedure ); ----snip gut ich glaub das sollte reichen.... btw besser als pollen in der mainmsg-loop ist pollen in einem eigenen thread.... damit blockierst du dein programm nicht unnötig.... falls noch fragen sind.... 73
Hier gibts von MS einen sehr umfangreichen Artikel zu allen Aspekten der seriellen Schnittstelle: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnfiles/html/msdn_serial.asp
Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.