Kuinka saan kirjoitettua sarjaporttiin Heksalukuja esim 45H, 38H, 30H jne.
Heksa lukuja on 1-n kappaletta ja viesti on muotoa ALOITUS, DATA, LOPETUS.
täytyisikö luvut kerätä joihinkin muuttujiin jotka sitten yhdistetään????
Alla olevalla koodilla ekstit kuten "Hello Ford!" ym menee että ropina käy joten mitenkäs koodia muuttaisin.
HANDLE hCom = CreateFile("COM1",
GENERIC_READ | GENERIC_WRITE,
0,
NULL,
OPEN_EXISTING,
0,
NULL );
if(hCom)
{
DCB dcb;
ZeroMemory(&dcb, sizeof(dcb));
dcb.DCBlength = sizeof(dcb);
dcb.BaudRate = 9600;
dcb.ByteSize = 8;
dcb.Parity = NOPARITY; // NOPARITY and friends are
dcb.StopBits = ONESTOPBIT; // #defined in windows.h
// Set the port properties and write the string out the port.
if(SetCommState(hCom,&dcb))
{
DWORD ByteCount;
const char *msg = "Hello world!";
WriteFile(hCom,msg, strlen(msg),&ByteCount,NULL);
}
CloseHandle(hCom);
}
Heksa lukuja on 1-n kappaletta ja viesti on muotoa ALOITUS, DATA, LOPETUS.
täytyisikö luvut kerätä joihinkin muuttujiin jotka sitten yhdistetään????
Alla olevalla koodilla ekstit kuten "Hello Ford!" ym menee että ropina käy joten mitenkäs koodia muuttaisin.
HANDLE hCom = CreateFile("COM1",
GENERIC_READ | GENERIC_WRITE,
0,
NULL,
OPEN_EXISTING,
0,
NULL );
if(hCom)
{
DCB dcb;
ZeroMemory(&dcb, sizeof(dcb));
dcb.DCBlength = sizeof(dcb);
dcb.BaudRate = 9600;
dcb.ByteSize = 8;
dcb.Parity = NOPARITY; // NOPARITY and friends are
dcb.StopBits = ONESTOPBIT; // #defined in windows.h
// Set the port properties and write the string out the port.
if(SetCommState(hCom,&dcb))
{
DWORD ByteCount;
const char *msg = "Hello world!";
WriteFile(hCom,msg, strlen(msg),&ByteCount,NULL);
}
CloseHandle(hCom);
}
Vastaukset 2
Vanhimmat
Eikös noi kirjaimet ole samoja tavuja kuin ne "heksaluvutkin"?
Esim. merkkijono "\x41\x4C\x4F\x49\x54\x55\x53" on sama kuin "ALOITUS".
Etsinkin.
Toksia!