Good day,
how can i work with comm port in PPL. Send ATcommands and read answer, etc.
Thanks.
how can i work with comm port in PPL. Send ATcommands and read answer, etc.
Thanks.
A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.
#include "comm.ppl"
// Open port
p$ = CreateFile("COM1", GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
// Input and Output buffer size
SetupComm(p$, 128, 128);
// Setup port
struct(dcb$, DCB);
GetCommState(p$, &dcb;$);
dcb.BaudRate$ = 9600;
dcb.ByteSize$ = 8;
dcb.Parity$ = NOPARITY;
dcb.StopBits$ = ONESTOPBIT;
dcb.fAbortOnError$ = TRUE;
SetCommState(p$, &dcb;$);
struct(CommTimeouts$, COMMTIMEOUTS);
GetCommTimeouts (p$, &CommTimeouts;$);
CommTimeouts.ReadIntervalTimeout$ = 50;
CommTimeouts.ReadTotalTimeoutConstant$ = 50;
CommTimeouts.ReadTotalTimeoutMultiplier$ = 10;
CommTimeouts.WriteTotalTimeoutConstant$ = 50;
CommTimeouts.WriteTotalTimeoutMultiplier$ = 10;
SetCommTimeouts (p$, &CommTimeouts;$);
// Write something to port
new(iBytesWritten$, TInt);
WriteFile(p$, "ATZ", 3, &iBytesWritten;$, NULL);
SetCommMask (p$, EV_RXCHAR | EV_CTS | EV_DSR | EV_RING);
// Wait for characters from port
new(event$, TInt);
WaitCommEvent(p$, &event;$, NULL);
SetCommMask (p$, EV_RXCHAR | EV_CTS | EV_DSR | EV_RING);
if (event$ & EV_RXCHAR)
s$ = "";
// Read from port
new(iBytesRead$, TInt);
new(Buffer$, TByte);
repeat
ReadFile(p$, &Buffer;$, 1, &iBytesRead;$, NULL);
s$ = s$ % Buffer$;
until (BytesRead$ == 0)
ShowMessage(s$);
end;
CloseHandle(p$);