Hvala, Aleks
Kako citas uopce?
Ja sam korstio ovo za WinXP:
http://www.logix4u.net/inpout32.htm
--
Milan Mimica
http://sparklet.sf.net
Tako nekako, sasvim trivijalno. Sad ovaj char c treba na serijski bacit.
Hvala na odgovoru, al ovo mi ne pomaze jer je radjeno za paralelni port, a s
njim ne mogu bas komunicirat sa mikrokontrolerom.
OK, mislio sam da znas citat s porta a ne znas pisat sto bi bilo cudno.
> Tako nekako, sasvim trivijalno. Sad ovaj char c treba na serijski bacit.
> Hvala na odgovoru, al ovo mi ne pomaze jer je radjeno za paralelni port, a s
> njim ne mogu bas komunicirat sa mikrokontrolerom.
Ah, da, jednom sam koristio paralelni port za serijsku komunikaciju
pa me to zbunilo. Nista korisnog od mene :-/
Ako je rijec o win platformo, otvoris com port sa CreateFile("COMx",
...) i dalje imas ReadFile/WriteFile standardno. Onaj x u COMx je
naravno com port koji zelis otvorit (COM1, COM2...). Jedino moras
namjestit parity, stop bits, flow control (SetCommState) i timout-e
(SetCommTimeouts)... Pogledaj u MSDN.
Goran
Zahvaljujem, evo iskopao sam ovo za pisanje ako nekom jos bude trebalo:
#include <windows.h>
#include <stdio.h>
int main(int argc, char *argv[])
{
DCB dcb;
HANDLE hCom;
BOOL fSuccess;
char *pcCommPort = "COM2";
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());
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());
return (2);
}
dcb.BaudRate = 9600; // 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());
return (3);
}
printf ("Serial port %s successfully reconfigured.\n", pcCommPort);
// return (0);
char StringA50[4] = {'A','5','0'};
char StringB85[4] = {'B','8','5'};
unsigned long zapisano;
int status = WriteFile(hCom, // Handle
&StringA50, // Address of Outgoing data
3, // Number of bytes to write
&zapisano, // Returned number of bytes written
NULL);
if ( zapisano == 3)
printf("Uspjesno poslano => %s\n",StringA50);
else
printf("Neuspjelo slanje!\n");
return (0);
}