PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

Comm port and PPL

Good day,
how can i work with comm port in PPL. Send ATcommands and read answer, etc.
Thanks.
Look into the Comm.ppl library file. It's located in the Lib\ folder in your installed PPL folder.

Look here also:

http://msdn.microsoft.com/library/defau ... upcomm.asp

Code:
#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$);


This is very simple stupid piece of code I wrote. You can turn this into a full blown library if you want. I might do it someday, maybe someone would be interested in doing it and wouldn't mind sharing it for the PPL main distribution?

This gives you an idea how it works in PPL, pretty much the same as in C.

EDIT: I'm not sure it works, I didn't try it myself.