-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
125 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
#ifdef CEUMAKER_ARDUINO | ||
|
||
#include "arduino/arduino.ceu" | ||
|
||
native/pre do | ||
//##define CEU_ARDUINO_SERIAL_SPEED 9600 | ||
end | ||
|
||
input byte SERIAL; | ||
output bool PIN_13; | ||
|
||
loop do | ||
var byte a = _; | ||
var byte b = _; | ||
var byte c = _; | ||
|
||
a = await SERIAL; | ||
|
||
emit PIN_13(true); | ||
b = await SERIAL; | ||
|
||
do | ||
spawn do | ||
loop do | ||
await 2s; | ||
emit PIN_13(true); | ||
await 2s; | ||
emit PIN_13(false); | ||
end | ||
end | ||
c = await SERIAL; | ||
end | ||
|
||
spawn do | ||
loop do | ||
await 250ms; | ||
emit PIN_13(true); | ||
await 250ms; | ||
emit PIN_13(false); | ||
end | ||
end | ||
|
||
_Serial.write(a); | ||
_Serial.write(b); | ||
_Serial.write(c); | ||
|
||
await FOREVER; | ||
end | ||
|
||
#elif defined CEUMAKER_PICO | ||
|
||
native/pre do | ||
##include <windows.h> | ||
end | ||
|
||
{ | ||
// OPEN | ||
|
||
HANDLE hSerial = CreateFile("COM3", | ||
GENERIC_READ | GENERIC_WRITE, | ||
0, | ||
NULL, | ||
OPEN_EXISTING, | ||
FILE_ATTRIBUTE_NORMAL, | ||
NULL); | ||
ceu_dbg_assert(hSerial != INVALID_HANDLE_VALUE); | ||
|
||
DCB dcbSerialParams = {0}; | ||
ceu_dbg_assert(GetCommState(hSerial,&dcbSerialParams)); | ||
|
||
dcbSerialParams.BaudRate = CBR_9600; | ||
dcbSerialParams.ByteSize = 8; | ||
dcbSerialParams.StopBits = ONESTOPBIT; | ||
dcbSerialParams.Parity = NOPARITY; | ||
dcbSerialParams.fDtrControl = DTR_CONTROL_ENABLE; | ||
ceu_dbg_assert(SetCommState(hSerial, &dcbSerialParams)); | ||
|
||
PurgeComm(hSerial, PURGE_RXCLEAR | PURGE_TXCLEAR); | ||
Sleep(2000); | ||
|
||
// WRITE | ||
{ | ||
const char* buffer = "ola"; | ||
int nbChar = 3; | ||
DWORD bytesSend; | ||
|
||
ceu_dbg_assert(WriteFile(hSerial, (void*)buffer, nbChar, &bytesSend, 0)); | ||
ceu_dbg_assert(bytesSend == nbChar); | ||
printf(">>> sent\n"); | ||
|
||
//COMSTAT status; | ||
//DWORD errors; | ||
//ClearCommError(this->hSerial, &this->errors, &this->status); | ||
} | ||
|
||
// READ | ||
{ | ||
char buffer[10]; | ||
DWORD bytesRead; | ||
|
||
while (1) { | ||
COMSTAT status; | ||
DWORD errors; | ||
ClearCommError(hSerial, &errors, &status); | ||
if (status.cbInQue == 3) { | ||
break; | ||
} | ||
} | ||
ceu_dbg_assert(ReadFile(hSerial, buffer, 3, &bytesRead, NULL)); | ||
ceu_dbg_assert(bytesRead == 3); | ||
|
||
buffer[3] = '\0'; | ||
printf(">>> %s\n", buffer); | ||
} | ||
|
||
// CLOSE | ||
|
||
CloseHandle(hSerial); | ||
} | ||
|
||
await FOREVER; | ||
|
||
#endif |