Don't ad-block us - support your favorite websites. We have safe, unobstrusive, robotics related ads that you actually want to see - see here for more.
0 Members and 1 Guest are viewing this topic.
uartGetByteint uartGetByte(UART* uart)Returns the next byte from the receive buffer or -1 if there is no buffer or the buffer is empty.Example:Code: [Select]int ch = uartGetByte(UART0);if(ch!=-1){// We have got a character in 'ch'}There are shorthand forms when dealing with a specific uart. eguart0GetByte() is the same thing as uartGetByte(UART0) anduart1GetByte() is the same thing as uartGetByte(UART1)
int ch = uartGetByte(UART0);if(ch!=-1){// We have got a character in 'ch'}
but it seems this is only for integers.
int ch = uartGetByte(UART1);if( ch != -1 ){ char ascii = ch & 0xff ; // Get the character from the low byte of the returned value // 'ascii' now holds the character}
I see what you mean Webbot. I was didnt realize that it was just checking to make sure it was just NOT -1.Also, could you explain how that code takes a whole string of data? It seems it just takes a one number and does things accordingly. I would like to enter, say, a whole password in my program. I am guessing you would just have to use the uartGetByte() on the Hyperterminal UART connection however many times there are letters, (use it five times for a five letter password) then assemble them into a single string?
while(cByte!=';') { cByte=GET_DATA_U0;//store command data if(cByte!=-1)//has new data { Razer_Raw_Data[counter]=cByte;//store data counter++; }
what it does is cycle through , going to the next array node (its a node, right?) after it recognizes you have entered new character until it gets to 15, when the array runs out.My only question is what happens when you get to 15 characters in this? What if I kept entering characters? I remember something about exceeding array sizes being bad, but I might be wrong...
I see.is there any way to use another key like 'return' or shift
So I assume that using uartGetByte(uart0); Would return CR? but wouldnt that be two characters?
if (Typed_letter == "CR")
#include "hardware.h"int letter = -1;char password[9];uint8_t counter=0;// Initialise the hardwarevoid message();void appInitHardware(void) { initHardware();}// Initialise the softwareTICK_COUNT appInitSoftware(TICK_COUNT loopStart){ return 0;}// This is the main loopTICK_COUNT appControl(LOOP_COUNT loopCount, TICK_COUNT loopStart) { while(SWITCH_released(&button)){ // released } // -------- End Switch/Button------- rprintf("Enter Password:"); letter = uartGetByte(uart1);while(letter != 0x0d) { //store command data letter = uartGetByte(uart1); if(letter!=-1)//has new data { password[counter]=letter;//store data counter++; } } if (password[1] == 's' && password[2] == 'e' && password[3] == 'm' && password[4] == 'i' && password[5] == 'n' && password[6] == 'o' && password[7] == 'l' && password[8] == 'e' && password[9] == 's') { message(); } // -------- Start Marquee------- // Marquee - see 'segled.h' // Before using the Marquee you need to redirect rprintf to write to it // This can be done using
/* This file has been auto-generate by WebbotLib tools V1.1 ** DO NOT MODIFY BY HAND ***/#ifndef _HARDWARE_H_#define _HARDWARE_H_#include "xhardware.h"// Type of interrupt handler to use for uart interrupts.// Do not change unless you know what you're doing.#ifndef UART_INTERRUPT_HANDLER#define UART_INTERRUPT_HANDLER ISR#endif// ------------------- uart1 -------------------// Create hardware UART uart1HW_UART _uart1 = MAKE_UART_BUFFERED(null,null,UCSR1A,UCSR1B,UBRR1L,UBRR1H,UDR1,null,BV(U2X1),D2,D3,&uart1GetByte,&uart1SendByte);// Create a routine to write bytes to uart1// You can set rprintf to use it by calling rprintfInit(&uart1SendByte)MAKE_WRITER(uart1SendByte){ return uartSendByte(uart1,byte);}// Create a routine to read a byte from uart1// Returns -1 if there was no dataMAKE_READER( uart1GetByte){ return uartGetByte(uart1);}#ifndef USART1_TX_vect# error Uart1 Tx complete vector undefined#elseUART_INTERRUPT_HANDLER(USART1_TX_vect){ uartTransmitService(uart1);}#endif#ifndef USART1_RX_vect# error Uart1 Rx complete vector undefined#elseUART_INTERRUPT_HANDLER(USART1_RX_vect){ uartReceiveService(uart1);}#endif// ----------- Define the ADC channels ----------const uint8_t NUM_ADC_CHANNELS = 16;// ----------- My devices -----------------------SWITCH button = MAKE_SWITCH(D5);SEGLED led_display = MAKE_SEGLED(C3,C2,C0,D6,D7,C4,C5,null,false);static SEGLED_LIST marquee_list[] = {&led_display};MARQUEE marquee = MAKE_MARQUEE(marquee_list,500000,2000000,&marquee_put_char);// Create a Writer to write to marqueeMAKE_WRITER(marquee_put_char){ return marqueeSendByte(&marquee,byte);}// ----------- Initialise built in devices ------void sysInitHardware(void){ SWITCH_init(&button); setErrorLog(&uart1SendByte); rprintfInit(&uart1SendByte); uartInit(uart1,115200); segled_init(&led_display);}// ----------- Initialise my added devices ------void initHardware(void){}// ----------- Register the statusLED -----------void registerLED(void){ statusLEDregister(C1,false);}// ----------- Ports are configured on the fly --void configure_ports(void){}#endif
2. I begin to type the password but nothing appears on the Hyperterminal window. )I continued to type thinking that it may just not appear) I press enter and then after a few seconds I get WebbotLib Error: 11What is this?What does it mean? My code compiled with 0 errors and warnings.
If (counter < 7) { counter++ }
counter++
/* This is the Header file for password protecting any made programs for the Axon II ________ ____ ____ ____ | | \ \ / \ / / | | | | | | | | |_______/ \ \ / \ / / | | | | | | | | \ \/ \/ / | |__________________| _____ | | | | ____ ____ |___ / / / \ | | | | | | \_____/ */int letter = -1;char password[9];int counter=0;void Pass_pro(){ while(SWITCH_released(&button)){ // released } while (password[0] != 's' || password[1] != 'e' || password[2] != 'm' || password[3] || 'i' && password[4] || 'n' && password[5] != 'o' || password[6] != 'l' || password[7] != 'e' || password[8] != 's') { rprintf("Enter Password:\n"); letter = uartGetByte(uart1); while(letter != 0x0d) { //store command data letter = uartGetByte(uart1); if(letter!=-1)//has new data { password[counter]=letter;//store data counter++; } } }}
Webbot, that is a thought . . . adding a password protection function into the library.Hijacking another robot/microcontroller with any wireless capability would be easy without it . . .
Wait, no 256 bit data encryption?!
unfortunately no John (I may call you john right? Admin sounds so.... General...)