New topic: 

Raw data string in serial port

<http://forums.realsoftware.com/viewtopic.php?t=31378>

       Page 1 of 1
   [ 6 posts ]                 Previous topic | Next topic         Author  
Message       mb52505           Post subject: Raw data string in serial 
portPosted: Wed Dec 02, 2009 11:59 am                        
Joined: Thu Oct 08, 2009 8:59 am
Posts: 28              I have a data stream that contains 2 bytes of raw data 
preceeded by 2 qualifiers (which can easily be integers) which are preset.

Like this --

132, 214, data1, data2

in other words --

132, 214, 01101100, 00000101

or "whatever".

I'm at a standstill trying to figure out how to decipher my data -- the 
serialport will only read strings, so conversion is in order. 

I have an array setup for starters --
dim rcvdata(12)     //using 12 elements for redundancy

rcvdata(12) = serial1.readall    //encoding?

Anyway, here I am with an array full of strings and rather lost at what to do 
next.


I've tried to use rcvdata.indexof to find my 132 or 214 but not having much 
luck with that either.


Also -- what the heck is a memory block?
In this situation would it be of value?

THANKS   
                            Top                timhare           Post subject: 
Re: Raw data string in serial portPosted: Wed Dec 02, 2009 12:38 pm             
           
Joined: Fri Jan 06, 2006 3:21 pm
Posts: 6867
Location: Portland, OR  USA              If the data is to be treated as raw 
bytes, then you want to ignore encoding completely.  So make sure you use the 
"B" version of everything: LEFTB, RIGHTB, MIDB, LENB, ASCB, etc.

An RB String is just a sequence of bytes.  You can apply an encoding to it and 
have the system interpret it as text, but it really is just a bunch of bytes.  
So you might have code like:
Code:dim data as string
dim qual1, qual2, raw1, raw2 as integer
data = me.ReadAll
qual1 = ascb(midb(data, 1, 1)
qual2 = ascb(midb(data, 2, 1)
raw1 = ascb(midb(data, 3, 1)
raw2 = ascb(midb(data, 4, 1)



Alternately, you could use a memoryblock.  It is simply an api for accessing a 
chunk of memory in some arbitrary way - as bytes, integer, strings, whatever.
Code:dim data as memoryblock
data = me.ReadAll   // strings auto-convert to memoryblocks
qual1 = data.byte(0)
qual2 = data.byte(1)
raw1 = data.byte(2)
raw2 = data.byte(3)


HTH,
Tim   
                            Top               mb52505           Post subject: 
Re: Raw data string in serial portPosted: Wed Dec 02, 2009 1:16 pm              
          
Joined: Thu Oct 08, 2009 8:59 am
Posts: 28              Tim -- thanks a lot.

As a newb, I'm sure you can understand my confusion on it.

I like that memory block thing -- very straightforward.

Over the hump now, I hope.   
                            Top                mb52505           Post subject: 
Re: Raw data string in serial portPosted: Wed Dec 02, 2009 1:29 pm              
          
Joined: Thu Oct 08, 2009 8:59 am
Posts: 28              Works like a champ Tim.

Thanks again.   
                            Top                Phil M           Post subject: 
Re: Raw data string in serial portPosted: Wed Dec 02, 2009 1:31 pm              
          
Joined: Fri Sep 30, 2005 12:18 pm
Posts: 566              Another option since you know what the data format is 
going to be, is a Structure.  Add a new structure to a module or class and 
define the structure elements as:
Code:qual1 As UInt8
qual2 As UInt8
raw1 As UInt8 // or Int8 for signed byte
raw2 As UInt8 // or Int8 for signed byte

Then your code can pass around these structures directly.

Or you could use the MemoryBlock technique and have the entire data wrapped 
into a Class.  This would allow you to have accessor methods (or computed 
properties) that can convert the data into more meaningful properties.

There are lots of options.   
                            Top               timhare           Post subject: 
Re: Raw data string in serial portPosted: Wed Dec 02, 2009 2:03 pm              
          
Joined: Fri Jan 06, 2006 3:21 pm
Posts: 6867
Location: Portland, OR  USA              As you progress in RB, I would 
seriously recommend you explore Phil's suggestions.  It may be too much all at 
once right now, but it would be worthwhile to keep in mind for the future.   
                            Top           Display posts from previous: All 
posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost 
timeSubject AscendingDescending          Page 1 of 1
   [ 6 posts ]     
-- 
Over 1500 classes with 29000 functions in one REALbasic plug-in collection. 
The Monkeybread Software Realbasic Plugin v9.3. 
http://www.monkeybreadsoftware.de/realbasic/plugins.shtml

[email protected]

Reply via email to