readBytesUntil() using a negative termination character

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

readBytesUntil() using a negative termination character

Postby jmz » Wed May 02, 2012 11:00 am

I'm sending serial commands from processing to an arduino teensy via xbee and want to have it read 15 different values/bytes at a time. Negative (signed) integers are transferred serially without a problem, however when I try to use a negative integer as a termination value for the buffer, it never recognizes it as such. 

All values I'm sending are positive integers, so I want to keep all 128 values reserved for commands and not have to worry about one being the termination character. Is there something I'm missing, or is it just not possible to have a negative integer as that termination character??

For example:
readBytesUntil(-10, buff, BUFF_SIZE);

Thanks in advance :)
jmz
 
Posts: 6
Joined: Tue Sep 27, 2011 7:00 pm

Re: readBytesUntil() using a negative termination character

Postby adafruit_support_bill » Wed May 02, 2012 12:08 pm

Are you transmitting data as ASCII strings? ReadBytesUntil() is testing for a character byte value, not the value of an integer string.
User avatar
adafruit_support_bill
 
Posts: 16027
Joined: Sat Feb 07, 2009 9:11 am

Re: readBytesUntil() using a negative termination character

Postby pylon » Wed May 02, 2012 12:16 pm

Your code should work although I would never use a negative integer literal as the value for a character but use a hex value (0xf6 in your case) instead. Please note that an integer is two bytes (in Arduino terms) and a character is one byte. This may be the reason for your code to fail, if the PC sends integers (may be two or even four bytes) and the Arduino expects bytes. Try to define exactly what byte sequence your PC is sending.
pylon
 
Posts: 14
Joined: Tue Apr 24, 2012 10:27 am


Return to Arduino

Who is online

Users browsing this forum: No registered users and 8 guests

Stuff to buy from the Adafruit store and links to product documentation!


New Products [103]

Raspberry Pi[80]
 
FLORA[23]
 
Bunnie Studios[9]
 
FPGA[1]
 
mbed[11]
Arduino[60]
 
NETduino[14]
 
BeagleBone[24]
 
Android[6]
 
XBee[10]
More Dev Boards[30]


 
BoArduino[8]
 
SpokePOV[4]
 
TV-B-Gone[4]
 
MiniPOV[3]
 
SIM reader[3]
 
Microtouch[5]
 
Clocks & Watches[18]
 
Drawdio[4]
 
Brain Machine[1]
 
Game of Life[2]
 
MintyBoost[2]
More DIY Kits[16]


 
MaKey MaKey[3]
 
Tweet-a-Watt[5]
 
Young Engineers[33]
 
Discover Electronics[2]
 
Snap Circuits[4]
 
littleBits[3]
 
Project packs[8]


 
Breakout Boards[33]
LCDs & Displays[48]
Components & Parts[69]
Batteries & Power[49]
EL Wire/Tape/Panel[52]
LEDs[109]
 
Wireless[14]
Cables[61]
 
Lasers[6]
Sensors/Parts[145]
 
Enclosures/Cases[11]
 
Solar[11]
 
RFID / NFC[13]
Prototyping[70]
 
iDevices[13]
Tools[71]
 
Wearables[39]
 
CNC[37]
 
Robotics[29]
 
3D printing[1]
 
Materials[24]


 
Stickers[41]
 
Skill badges[55]
 
Books[25]
 
Circuit Playground[7]
 
Gift Certificates[4]