Arduino Com Port Kommunikation
Übersicht BlitzBasic Codearchiv
mactepBetreff: Arduino Com Port Kommunikation |
Di, Sep 25, 2012 19:24 Antworten mit Zitat |
|
---|---|---|
Hallo,
folgender Code erlaubt Seriele Kommunikation (ComPort) mit einem Arduino. "Kernel32.dll" Decls : Code: [AUSKLAPPEN] .lib "Kernel32.dll"
apiCreateFile%(lpFileName$, dwDesiredAccess, dwShareMode, lpSecurrityAttributes, dwCreationDistribution, dwFlagsAndAttributes, hTemplateFile) : "CreateFileA" apiSetupComm%(hFile, dwInQueue, dwOutQueue) : "SetupComm" apiGetCommState%(hFile, lpDCB*) : "GetCommState" apiSetCommState%(hFile, lpCDB*) : "SetCommState" apiSetCommMask%(hFile, dwEvtMask) : "SetCommMask" apiCloseHandle%(hObject) : "CloseHandle" apiEscapeCommFunction%(hFile, dwFunc) : "EscapeCommFunction" apiWriteFile%(hFile, lpBuffer*, nNumberOfBytesToWrite, lpNumberOfBytesWritten*, lpOverlapped) : "WriteFile" apiSetCommTimeouts%(hFile, lpCommTimeouts*) : "SetCommTimeouts" apiClearCommError%(hFile, lpErrors*, lpStat*) : "ClearCommError" apiReadFile%(hFile, lpBuffer, nNumberOfBytesToRead, lpNumberOfBytesRead*, lpOverlapped) : "ReadFile" Code mit Beispiel: Code: [AUSKLAPPEN] Const parityEnable = False ; flag if parity is enabled
Const protocol = 0 ; stores protocol type Const dataBits = 8 ; stores number if data bits Const parityBit = 0 ; stores type of parity bit Const stopBits = 0 ; stores number of stop bits Global timeouts = CreateBank(20) ; Bank4TimeOuts... Const INVALID_HANDLE_VALUE = -1 Const GENERIC_READ = $80000000 Const GENERIC_WRITE = $40000000 Const OPEN_EXISTING = 3 Const CBR_110 = 110 Const CBR_300 = 300 Const CBR_600 = 600 Const CBR_1200 = 1200 Const CBR_2400 = 2400 Const CBR_4800 = 4800 Const CBR_9600 = 9600 Const CBR_14400 = 14400 Const CBR_19200 = 19200 Const CBR_38400 = 38400 Const CBR_56000 = 56000 Const CBR_57600 = 57600 Const CBR_115200 = 115200 Const DTR_CONTROL_DISABLE = 0 Const DTR_CONTROL_ENABLE = 0 Const RTS_CONTROL_DISABLE = 0 Const RTS_CONTROL_ENABLE = 0 Const EV_TXEMPTY = 0 Const SETRTS = 3 Const CLRRTS = 4 hCom = openComport(3, 9600 ) If hCom <> 0 And hCOM <> INVALID_HANDLE_VALUE Then Print " Open COM3 with 9600 Baudrate ...Succesfully" Print "" Print "" Print "" Print "" Print "" SendMessage%(hCom,"Time :"+ CurrentTime()) WaitKey() ; Close Comm. closeComport(hCom) DebugLog "ComPort Geschlossen...." WaitKey : End ;Sollte der Comport nicht Gefunden werden und/oder hCom INVALID_HANDLE_VALUE Entsprechen : Else Print "Konnte Com Port nicht Öffnen!" closeComport(hCom) Print "Beliebige Taste zum Beenden..." WaitKey : End EndIf ; Close and end closeComport(hCom) WaitKey : End ; ----------------------------------------------------------------------------------- Function SendMessage%(File%, Command$) Local Buffer%, Offset%, Succes% Buffer% = CreateBank(Len(Command$)) For Offset% = 0 To Len(Command$)-1 PokeByte Buffer%, Offset%, Asc(Mid$(Command$, Offset%+1, 1)) Next Success% = writeComPort(File%, Len(COmmand$),Buffer%) FreeBank Buffer% Return Success% End Function Function openComport(comport, baudRate) Local dcbBaudRate, driverHandle, dcb If comport > 255 Or comport < 0 Then Return INVALID_HANDLE_VALUE EndIf Select baudRate Case 110 dcbBaudRate = CBR_110 Case 300 dcbBaudRate = CBR_300 Case 600 dcbBaudRate = CBR_600 Case 1200 dcbBaudRate = CBR_1200 Case 2400 dcbBaudRate = CBR_2400 Case 4800 dcbBaudRate = CBR_4800 Case 9600 dcbBaudRate = CBR_9600 Case 14400 dcbBaudRate = CBR_14400 Case 19200 dcbBaudRate = CBR_19200 Case 38400 dcbBaudRate = CBR_38400 Case 56000 dcbBaudRate = CBR_56000 Case 57600 dcbBaudRate = CBR_57600 Case 115200 dcbBaudRate = CBR_115200 Default Return INVALID_HANDLE_VALUE End Select driverHandle = apiCreateFile("COM"+comport, GENERIC_READ Or GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, 0) If driverHandle = INVALID_HANDLE_VALUE Then Return INVALID_HANDLE_VALUE Else apiSetupComm(driverHandle, 1024, 1024) dcb = CreateBank(28) PokeInt dcb, 00, 28 ; sizeof(DCB) PokeInt dcb, 04, dcbBaudRate ; current baud rate val = 1 ; Binary Mode (skip Eof check) If parityEnable = True Then val = val Or 2 ; Enable parity checking If protocol = DTR_CONTROL Then val = val Or 48 ; DTR Flow control on PokeByte dcb, 08, val val = 0 If protocol = RTS_CONTROL Then val = val Or 48 PokeByte dcb, 09, val PokeByte dcb, 18, dataBits ; number of bits/byte, 4-8 PokeByte dcb, 19, parityBit ; 0-4=no, odd, even, mark, space PokeByte dcb, 8, stopBits ; 0,1,2 = 1, 1.5, 2 apiSetCommState(driverHandle, dcb) apiSetCommMask(driverHandle, EV_TXEMPTY) EndIf FreeBank dcb Return driverHandle End Function Function closeComport(driverHandle) If driverHandle = INVALID_HANDLE_VALUE Or driverHandle = 0 Then Return False Else Return apiCloseHandle(driverHandle) EndIf End Function Function writeComport(driverHandle, numBytes, buffer) Local state, temp If driverHandle = INVALID_HANDLE_VALUE Or driverHandle = 0 Then Return False EndIf apiEscapeCommFunction(driverHandle, SETRTS) temp = CreateBank(4) state = apiWriteFile(driverHandle, buffer, numBytes, temp, 0) apiEscapeCommFunction(driverHandle, CLRRTS) FreeBank temp Return state End Function Function readComport(driverHandle, bytesRead, bufferSize, buffer, tOut) Local comErrors, comStat If driverHandle = INVALID_HANDLE_VALUE Or driverHandle = 0 Then Return False EndIf PokeInt timeouts, 00, 0 PokeInt timeouts, 04, 0 PokeInt timeouts, 08, tOut PokeInt timeouts, 12, 0 apiSetCommTimeouts(driverHandle, timeouts) comErrors = CreateBank(4) comStat = CreateBank(10) apiClearCommError(driverHandle, comErrors, comStat) apiReadFile(driverHandle, buffer, bufferSize, bytesRead, 0) FreeBank comErrors FreeBank comStat Return True End Function Als Sketch kann man folgendes Bsp. verwenden. Bei LiquidCrystal lcd(7, 8, 9, 10, 11, 12) noch die Pins Anpassen! Code: [AUSKLAPPEN] /*
LiquidCrystal Library - Serial Input Demonstrates the use a 16x2 LCD display. The LiquidCrystal library works with all LCD displays that are compatible with the Hitachi HD44780 driver. There are many of them out there, and you can usually tell them by the 16-pin interface. This sketch displays text sent over the serial port (e.g. from the Serial Monitor) on an attached LCD. The circuit: * LCD RS pin to digital pin 12 * LCD Enable pin to digital pin 11 * LCD D4 pin to digital pin 5 * LCD D5 pin to digital pin 4 * LCD D6 pin to digital pin 3 * LCD D7 pin to digital pin 2 * LCD R/W pin to ground * 10K resistor: * ends to +5V and ground * wiper to LCD VO pin (pin 3) Library originally added 18 Apr 2008 by David A. Mellis library modified 5 Jul 2009 by Limor Fried (http://www.ladyada.net) example added 9 Jul 2009 by Tom Igoe modified 22 Nov 2010 by Tom Igoe This example code is in the public domain. http://arduino.cc/en/Tutorial/LiquidCrystalSerial */ // include the library code: #include <LiquidCrystal.h> // initialize the library with the numbers of the interface pins LiquidCrystal lcd(7, 8, 9, 10, 11, 12); void setup(){ // set up the LCD's number of columns and rows: lcd.begin(16, 2); // initialize the serial communications: Serial.begin(9600); } void loop() { // when characters arrive over the serial port... if (Serial.available()) { // wait a bit for the entire message to arrive delay(100); // clear the screen lcd.clear(); // read all the available characters while (Serial.available() > 0) { // display each character to the LCD lcd.write(Serial.read()); delay(10); } } } Hoffe jemand kann damit was Anfangen. Hier noch paar Bilder : http://s1.directupload.net/fil...vv_jpg.htm http://s14.directupload.net/fi...p9_jpg.htm Viel Spaß damit LG MACTEP! |
||
count-doku |
Do, Sep 27, 2012 18:48 Antworten mit Zitat |
|
---|---|---|
Hallo
richtig genial. Brauchte gerade was um mit B3D und meinem Arduino zu kommunizieren. Könntest du vllt. noch eine Funktion ReadMessage einbauen? lg, Count-Doku |
||
mactep |
Di, Okt 02, 2012 19:39 Antworten mit Zitat |
|
---|---|---|
Hallo,
Werde ich bei Gelegenheit machen. Denk bis Ende dieser Woche ist´s fertig. Vielen dank für dein Feedback. LG Michael. |
||
count-doku |
Mi, Okt 03, 2012 21:00 Antworten mit Zitat |
|
---|---|---|
Das wäre cool, sonst kann ich dir noch das hier empfehlen.
Verwende ich momentan, funktioniert auch, scheint allerdings manchmal zu desyncen Ich nehme dann z.B. folgenden Code: BlitzBasic: [AUSKLAPPEN] Local hCom% Das DTR an,aus am Anfang setzt den Arduino zurück, damit der Port synchron ist. lg, count-doku |
||
mactep |
Do, Okt 04, 2012 19:24 Antworten mit Zitat |
|
---|---|---|
Hi ,
Also mit : Code: [AUSKLAPPEN] ; Receive
buffer = CreateBank(1024) bytes = CreateBank(4) Print "Receiving datas ..." If readComport(hCom, bytes, 1024, buffer, 10000) Then ; 10 Sekunden timeout Print " Succesfully" Print " Number of receiving bytes "+PeekInt(bytes, 0) Else Print " Error" EndIf bekommst du die Empfangenen Bytes. Code: [AUSKLAPPEN] hCom = openComport(3, 9600 ) If hCom <> 0 And hCOM <> INVALID_HANDLE_VALUE Then Print " Open COM3 with 9600 Baudrate ...Succesfully" Print "" Print "" Print "" Print "" Print "" Repeat ;SendMessage%(hCom,"0") ;Delay 2000 SendMessage%(hCom,"1") Delay 2000 ; Receive buffer = CreateBank(1024) bytes = CreateBank(4) Print "Receiving datas ..." If readComport(hCom, bytes, 1024, buffer, 1000) Then ; 10 Sekunden timeout Print " Succesfully" Print " Number of receiving bytes "+PeekInt(bytes, 0) ; *** Datas are in the bank buffer *** Else Print " Error" EndIf Forever WaitKey() ; Close Comm. closeComport(hCom) DebugLog "ComPort Geschlossen...." WaitKey : End |
||
- Zuletzt bearbeitet von mactep am Fr, Apr 19, 2013 21:28, insgesamt 2-mal bearbeitet
count-doku |
Di, Okt 16, 2012 15:51 Antworten mit Zitat |
|
---|---|---|
hmmh ja die Anzahl der ausgelesenen Bytes stimmt schonmal,
aber ich kann keinen sinnvollen Abschnitt in der Buffer Bank finden - geschweige denn die gesendeten Bytes. Naja, vllt. fällt dir ja noch irgendwas ein. lg, Count-Doku |
||
mactep |
Mo, Apr 01, 2013 0:19 Antworten mit Zitat |
|
---|---|---|
Hi,
sorry für die LANGE Wartezeit... habe hier noch eine Lösung : Decls : Code: [AUSKLAPPEN] .lib "kernel32.dll"
apiCreateFile%(FileName$, DesiredAccess%, ShareMode%, pSecurrityAttribute%, CreationDistribution%, FlagsAndAttributes%, TemplateFile%) : "CreateFileA" apiCloseHandle%(Object%) : "CloseHandle" apiWriteFile%(File%, pBuffer*, NumberOfBytesToWrite%, pNumberOfBytesWritten*, pOverlapped%) : "WriteFile" apiReadFile%(File%, pBuffer*, NumberOfBytesToRead%, pNumberOfBytesRead*, pOverlapped%) : "ReadFile" apiGetCommState%(File%, pDCB*) : "GetCommState" apiSetCommState%(File%, pDCB*) : "SetCommState" apiBuildCommDCB%(Def$, pDCB*) : "BuildCommDCBA" apiGetCommTimeouts%(File%, pCommTimeouts*) : "GetCommTimeouts" apiSetCommTimeouts%(File%, pCommTimeouts*) : "SetCommTimeouts" Arduino Code Bsp : Code: [AUSKLAPPEN] /*
Character analysis operators Examples using the character analysis operators. Send any byte and the sketch will tell you about it. created 29 Nov 2010 modified 2 Apr 2012 by Tom Igoe This example code is in the public domain. */ void setup() { // Open serial communications and wait for port to open: Serial.begin(9600); while (!Serial) { ; // wait for serial port to connect. Needed for Leonardo only } // send an intro: Serial.println("send any byte and I'll tell you everything I can about it"); Serial.println(); } void loop() { // get any incoming bytes: if (Serial.available() > 0) { int thisChar = Serial.read(); // say what was sent: Serial.print("You sent me: \'"); Serial.write(thisChar); Serial.print("\' ASCII Value: "); Serial.println(thisChar); // analyze what was sent: if(isAlphaNumeric(thisChar)) { Serial.println("it's alphanumeric"); } if(isAlpha(thisChar)) { Serial.println("it's alphabetic"); } if(isAscii(thisChar)) { Serial.println("it's ASCII"); } if(isWhitespace(thisChar)) { Serial.println("it's whitespace"); } if(isControl(thisChar)) { Serial.println("it's a control character"); } if(isDigit(thisChar)) { Serial.println("it's a numeric digit"); } if(isGraph(thisChar)) { Serial.println("it's a printable character that's not whitespace"); } if(isLowerCase(thisChar)) { Serial.println("it's lower case"); } if(isPrintable(thisChar)) { Serial.println("it's printable"); } if(isPunct(thisChar)) { Serial.println("it's punctuation"); } if(isSpace(thisChar)) { Serial.println("it's a space character"); } if(isUpperCase(thisChar)) { Serial.println("it's upper case"); } if (isHexadecimalDigit(thisChar)) { Serial.println("it's a valid hexadecimaldigit (i.e. 0 - 9, a - F, or A - F)"); } // add some space and ask for another byte: Serial.println(); Serial.println("Give me another byte:"); Serial.println(); } } BlitzCode : Code: [AUSKLAPPEN] Const GENERIC_READ = $80000000 Const GENERIC_WRITE = $40000000 Const OPEN_EXISTING = 3 Const FILE_ATTRIBUTE_NORMAL = $80 Const INVALID_HANDLE_VALUE = -1 Global Message$ File% = OpenCommPort(3) SetComm(File%, "baud=9600 parity=N data=8 stop=1") SetCommTimeouts(File%, 50, 50) Repeat Message$ = Input("Message: ") If Message$ = "end" Then Exit ElseIf Message$ = "cls" Then Message$ = "" EndIf SendMessage(File%, Message$);+Chr$(13)+Chr$(10)) Message$ = RecvMessage(File%) If Message$ <> "" Then Print "Recieved : "+Message$ Else ;Print CurrentTime()+ "| " EndIf Forever CloseCommPort(File%) End Function SendMessage%(File%, Command$) Local Buffer%, Offset%, Succes% Buffer% = CreateBank(Len(Command$)) For Offset% = 0 To Len(Command$)-1 PokeByte Buffer%, Offset%, Asc(Mid$(Command$, Offset%+1, 1)) Next Success% = WriteComm(File%, Buffer%, Len(Command$)) FreeBank Buffer% Return Success% End Function Function RecvMessage$(File%) Local Buffer%, Offset%, Count%, Message$ Buffer% = CreateBank(1024) Count% = ReadComm(File%, Buffer%, 1024) If Count% > 0 Then For Offset% = 0 To Count-1 Message$ = Message$+Chr$(PeekByte(Buffer%, Offset%)) Next Return Message$ Else FreeBank Buffer% Return "" EndIf End Function Function OpenCommPort%(Port%) Local File% If (Port < 0) Or (Port > 255) Then Return -1 ; Open CommPort File% = apiCreateFile("COM"+Port%, GENERIC_READ Or GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, 0) If File% = INVALID_HANDLE_VALUE Then Return -1 Else Return File% EndIf End Function Function CloseCommPort%(File%) Return apiCloseHandle(File%) End Function Function WriteComm%(File%, Buffer%, Size%) Local Count%, Count2% If Size% > BankSize(Buffer%) Then Return 0 Count% = CreateBank(4) If apiWriteFile(File%, Buffer%, Size%, Count%, 0) = 0 Then FreeBank Count% Return 0 Else Count2% = PeekInt(Count%, 0) FreeBank Count% Return Count2% EndIf End Function Function ReadComm%(File%, Buffer%, Size%) Local Count%, Count2% If Size% > BankSize(Buffer%) Then Return 0 Count% = CreateBank(4) If apiReadFile(File%, Buffer%, Size%, Count%, 0) = 0 Then FreeBank Count% Return 0 Else Count2% = PeekInt(Count%, 0) FreeBank Count% Return Count2% EndIf End Function Function SetComm%(File%, Settings$) Local DCB% DCB% = CreateBank(28) ; Get States If apiGetCommState(File%, DCB) = 0 Then FreeBank DCB% Return False ElseIf PeekInt(DCB%, 0) <> 28 FreeBank DCB% Return False EndIf ; Build DCB If apiBuildCommDCB(Settings$, DCB%) = 0 Then FreeBank DCB% Return False EndIf ; Set States If apiSetCommState(File%, DCB%) = 0 Then FreeBank DCB% Return False Else FreeBank DCB% Return True EndIf End Function Function SetCommTimeouts%(File%, ReadTime%, WriteTime%) Local TimeOuts% ; Get timeouts TimeOuts% = CreateBank(40) If apiGetCommTimeouts(File%, TimeOuts%) = 0 Then FreeBank TimeOuts Return False EndIf PokeInt TimeOuts%, 8, ReadTime% ; ReadTotalTimeoutConstant PokeInt TimeOuts%, 16, WriteTime% ; WriteTotalTimeoutConstant ; Set Timeouts If apiSetCommTimeouts(File%, TimeOuts%) = 0 Then FreeBank TimeOuts Return False Else FreeBank TimeOuts Return True EndIf End Function Viel Spass Damit ! Hier noch n kleines GUI Bsp [GUIde wird benötigt]: Code: [AUSKLAPPEN] ;GUIde 1.4 BlitzPlus export
Include "guideexportinclude.bb" AppTitle "Arduino COMander" Global Arduino Global btnButton0 Global btnButton1 Global btnButton3 Global teaTextArea0 Arduino=Create_CenterWindow("Arduino COMander",312,360,0,11) btnButton0=CreateButton("Activate LED",24,224,96,56,Arduino,1) SetGadgetLayout btnButton0,1,0,1,0 btnButton1=CreateButton("Dectivate LED",168,224,96,56,Arduino,1) SetGadgetLayout btnButton1,1,0,1,0 btnButton3=CreateButton("Connect to Arduino...",24,176,240,24,Arduino,1) SetGadgetLayout btnButton3,1,0,1,0 teaTextArea0=CreateTextArea(16,16,256,136,Arduino,0) SetTextAreaColor teaTextArea0,255,255,255,1 SetTextAreaColor teaTextArea0,0,0,0,0 SetGadgetLayout teaTextArea0,1,0,1,0 AddTextAreaText teaTextArea0,"Settings"+Chr(10) + Chr(13) AddTextAreaText teaTextArea0,"========"+Chr(10) + Chr(13) AddTextAreaText teaTextArea0,""+Chr(10) AddTextAreaText teaTextArea0,"COM PORT: 3"+Chr(10) AddTextAreaText teaTextArea0,"Baud=9600 |Parity=N |Data=8 |Stop=1"+Chr(10) + Chr(13) Const GENERIC_READ = $80000000 Const GENERIC_WRITE = $40000000 Const OPEN_EXISTING = 3 Const FILE_ATTRIBUTE_NORMAL = $80 Const INVALID_HANDLE_VALUE = -1 Global File% Global Succes% Global Timer = CreateTimer(30) ;-mainloop-------------------------------------------------------------- Repeat id=WaitEvent() Select id Case $401 ; interacted with gadget DoGadgetAction( EventSource() ) Case $803 ; close gadget Exit End Select WaitTimer Timer Forever CloseCommPort(File%) End ;-gadget actions-------------------------------------------------------- Function DoGadgetAction( gadget ) Select gadget Case btnButton0 ; user pressed button ACTIVATE LED Repeat SendMessage(File%, "1"+Chr$(13)+Chr$(10)) Message$ = RecvMessage(File%) If Message$ <> "" Then SetStatusText Arduino,"LED #11 ACTIVATED" ;Print Message$ AddTextAreaText(teaTextArea0,CurrentTime()+" | "+"LED #11 ACTIVATED"+Chr$(10)) DisableGadget btnButton0 EnableGadget btnButton1 Exit EndIf Forever Case btnButton1 ; user pressed button DEACTIVATE LED Repeat SendMessage(File%, "0"+Chr$(13)+Chr$(10)) Message$ = RecvMessage(File%) If Message$ <> "" Then SetStatusText Arduino,"LED #11 DEACTIVATED" ;Print Message$ EnableGadget btnButton0 DisableGadget btnButton1 AddTextAreaText(teaTextArea0,CurrentTime()+" | "+"LED #11 DEACTIVATED"+Chr$(10)) Exit EndIf Forever Case btnButton3 ; user pressed button CONNECT TO ARDUINO File% = OpenCommPort(3) Succes% = SetCommTimeouts%(File%, ReadMillisecs%, GENERIC_WRITE) SetComm(File%, "baud=9600 parity=N data=8 stop=1") SetCommTimeouts(File%, 12500, 12500) Repeat ;SendMessage(File%, "1"+Chr$(13)+Chr$(10)) Message$ = RecvMessage(File%) If Message$ <> "" Then ;Print Message$ SetStatusText Arduino,"Connected @ COM PORT: 3" EnableGadget btnButton1 DisableGadget btnButton3 Exit EndIf Forever End Select End Function Function SendMessage%(File%, Command$) Buffer% = CreateBank(Len(Command$)) For Offset% = 0 To Len(Command$)-1 PokeByte Buffer%, Offset%, Asc(Mid$(Command$, Offset%+1, 1)) Next Success% = WriteComm(File%, Buffer%, Len(Command$)) FreeBank Buffer% Return Success% End Function Function RecvMessage$(File%) Buffer% = CreateBank(1024) Count% = ReadComm(File%, Buffer%, 1024) If Count% > 0 Then For Offset% = 0 To Count-1 Message$ = Message$+Chr$(PeekByte(Buffer%, Offset%)) Next Return Message$ Else FreeBank Buffer% Return "" EndIf End Function Function OpenCommPort%(Port%) Local File% If (Port < 0) Or (Port > 255) Then Return -1 ; Open CommPort File% = apiCreateFile("COM"+Port%, GENERIC_READ Or GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, 0) If File% = INVALID_HANDLE_VALUE Then Return -1 Else Return File% EndIf End Function Function CloseCommPort%(File%) Return apiCloseHandle(File%) End Function Function WriteComm%(File%, Buffer%, Size%) Local Count%, Count2% If Size% > BankSize(Buffer%) Then Return 0 Count% = CreateBank(4) If apiWriteFile(File%, Buffer%, Size%, Count%, 0) = 0 Then FreeBank Count% Return 0 Else Count2% = PeekInt(Count%, 0) FreeBank Count% Return Count2% EndIf End Function Function ReadComm%(File%, Buffer%, Size%) Local Count%, Count2% If Size% > BankSize(Buffer%) Then Return 0 Count% = CreateBank(4) If apiReadFile(File%, Buffer%, Size%, Count%, 0) = 0 Then FreeBank Count% Return 0 Else Count2% = PeekInt(Count%, 0) FreeBank Count% Return Count2% EndIf End Function Function SetComm%(File%, Settings$) Local DCB% DCB% = CreateBank(28) ; Get States If apiGetCommState(File%, DCB) = 0 Then FreeBank DCB% Return False ElseIf PeekInt(DCB%, 0) <> 28 FreeBank DCB% Return False EndIf ; Build DCB If apiBuildCommDCB(Settings$, DCB%) = 0 Then FreeBank DCB% Return False EndIf ; Set States If apiSetCommState(File%, DCB%) = 0 Then FreeBank DCB% Return False Else FreeBank DCB% Return True EndIf End Function Function SetCommTimeouts%(File%, ReadTime%, WriteTime%) TimeOuts% = CreateBank(20) FreeBank TimeOuts Return True End Function Function Create_CenterWindow (title$, width, height, group = 0, style = 1);Expl. : Global Win = Create_CenterWindow("WINDOWS",800,600) Return CreateWindow (title$, (ClientWidth (Desktop ()) / 2) - (width / 2), (ClientHeight (Desktop ()) / 2) - (height / 2), width, height, group, style) End Function Arduino Code Code: [AUSKLAPPEN] #define ledPin 13
int incomingByte; void setup() { Serial.begin(9600); Serial.print("* startup "); Serial.println(""); pinMode(ledPin, OUTPUT); } void loop() { if (Serial.available() > 0) { incomingByte = Serial.read(); if (incomingByte == '1') { digitalWrite(ledPin, HIGH); Serial.println("LED ist eingeschaltet!"); } if (incomingByte == '0') { digitalWrite(ledPin, LOW); Serial.println("LED ist ausgeschaltet!"); } } } |
||
Übersicht BlitzBasic Codearchiv
Powered by phpBB © 2001 - 2006, phpBB Group