Download the free trial version
Basic4android Video
Features
Tutorials and manuals
Showcase
Screenshots

Go Back   Android Development Forum - Basic4android > Basic4ppc (Windows Mobile) > Questions (Windows Mobile)
Documentation Wiki Register Members List B4P Search Today's Posts Mark Forums Read

Questions (Windows Mobile) Post any question regarding Basic4ppc.

Help with Serial binary download?

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-21-2008, 11:50 PM
Knows the basics
 
Join Date: Jun 2008
Location: Barneveld, NL
Posts: 78
Default Help with Serial binary download?

I have been trying to use the SerialEx DLL to download data from a proprietary datalogger. I have done it in the past to a PC but after a couple of hours of floundering in the dark, I have come to the conclusion that it needs a better man than I to get the thing going on a device.

The data is sent in binary form. The relevant bits from the datalogger manual are: "After receiving an S from the PC, the instrument will transmit 32 signed integers as 64 bytes and wait for the next character S from the PC. .... All data are output in binary (signed integer) format, 2 bytes per integer, MSB first."

I know I can get data, I send an S and see 'stuff' on the device - but it is not in a format that I can equate to the description in the manual or past experience with the same data on a PC. I have attached a screenshot of my test program showing what comes in.

Somewhere at the very start of this datastream must be the integer 32700 followed by 1, 1, 20, 0, 100.

The lines in the screenshot are produced by:
Code:
Buffer()=com.InputArray
For i = 0 To ArrayLen(Buffer())-1
    ReceivedString=ReceivedString & 
Chr(Buffer(i))
Next
ReceivedString=ReceivedString & 
" - "
For i = 0 To ArrayLen(Buffer())-1
    ReceivedString=ReceivedString & 
Asc(Buffer(i))
Next
listbox1.Add(ArrayLen(Buffer()) & 
"[" & ReceivedString & "]")
I would be most grateful to anyone who can make any useful suggestions about how I can read this data.
David.
Attached Images
File Type: png comm1.png (3.7 KB, 21 views)
Reply With Quote
  #2 (permalink)  
Old 11-22-2008, 07:10 AM
taximania's Avatar
Basic4ppc Expert
 
Join Date: May 2007
Location: Derbyshire. UK
Posts: 592
Awards Showcase
Beta Tester 
Total Awards: 1
Default

32 signed integers as 64 bytes, is that not 2 bytes per integer ?

32700 is '7F BC' in Hex, or a 'square' and a '1/4' as two bytes.

That is among the first 2 characters of your screen shot.

I think it's reading the data Ok.

Hope you get my drift
__________________
.
.
.
Don't ask, I'm fine, honest. !!
.
.
.
Just a little crazy at times



O2 XDA, GW Evo 2.1 UC WWE Rom, WM6.1
Radio Ver 03.34.90
With Basic4ppc V6.80


http://www.taximania.co.uk
Reply With Quote
  #3 (permalink)  
Old 11-22-2008, 08:48 AM
Knows the basics
 
Join Date: Jun 2008
Location: Barneveld, NL
Posts: 78
Default

Thanks! I think I need to study the codes a bit more...

It's a good job I don't do this for a living - oh wait - I do
Reply With Quote
  #4 (permalink)  
Old 11-22-2008, 08:49 AM
agraham's Avatar
Basic4ppc Expert
 
Join Date: Jul 2007
Location: Cheshire, UK
Posts: 6,072
Awards Showcase
Innovator medal Beta Tester Forum Contributer 
Total Awards: 3
Default

Like Taximania says, it looks like you are getting the data OK, you just need to turn it into usable numbers. Try the Int16FromBytes method in my BytesConverter library http://www.basic4ppc.com/forum/addit...html#post14218.

Something like
Code:
Dim Bytes(0)
Dim Data(32)
 ... 

Bytes() = SerialEx.InputArray() 
' this is simplistic, all the data may not arrive in one read

For i = 0 to 31 
  Data(i) = Conv.Int16FromBytes(Bytes(), i+i)
Next
Reply With Quote
  #5 (permalink)  
Old 11-22-2008, 08:56 AM
agraham's Avatar
Basic4ppc Expert
 
Join Date: Jul 2007
Location: Cheshire, UK
Posts: 6,072
Awards Showcase
Innovator medal Beta Tester Forum Contributer 
Total Awards: 3
Default

Quote:
Originally Posted by DaveW View Post
IAll data are output in binary (signed integer) format, 2 bytes per integer, MSB first."
I just noticed that the data is Big-endian. You will need to shuffle the bytes, this is probably not the most elegant way of tackling it but ...

Code:
For i = 0 to 31 
  temp = Bytes(i)
  Bytes(i) = Bytes(i+
1)
  Bytes(i+
1) = temp
  Data(i) = Conv.Int16FromBytes(Bytes(), i+i)
Next
Reply With Quote
  #6 (permalink)  
Old 11-22-2008, 02:58 PM
Knows the basics
 
Join Date: Jun 2008
Location: Barneveld, NL
Posts: 78
Default

Hi Andrew,

Thank you for helping with this. Using your BytesConverter and the sample code I can now get valid numbers out of the datalogger.

I would like to point out (for others that might find this posting useful) that the sample code did not work 'out of the box'. I had to change it to:

Code:
Bytes() = com.InputArray 
posn = 
0 
For i = 0 To 31
      temp = Bytes(posn)   
'swap the bytes to make them LSB first
      Bytes(posn = Bytes(posn+1)
      Bytes(posn+
1) = temp
      Data(i) = Conv.Int16FromBytes(Bytes(), posn)  
'convert the next 2 bytes to an integer
    posn = posn + 2  'move to the next integer position
Next
Reply With Quote
  #7 (permalink)  
Old 11-22-2008, 03:13 PM
agraham's Avatar
Basic4ppc Expert
 
Join Date: Jul 2007
Location: Cheshire, UK
Posts: 6,072
Awards Showcase
Innovator medal Beta Tester Forum Contributer 
Total Awards: 3
Default

Quote:
Originally Posted by DaveW View Post
the sample code did not work 'out of the box'.
Sorry! I normally test code fragments, in this instance I didn't with the inevitable result that it was wrong.
Reply With Quote
  #8 (permalink)  
Old 11-22-2008, 03:54 PM
Knows the basics
 
Join Date: Jun 2008
Location: Barneveld, NL
Posts: 78
Default

It may have been 'wrong' but it was good enough to get me started ! I am more than happy with that
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Reading binary files jgm Questions (Windows Mobile) 5 05-28-2008 10:09 AM
Using Binary.dll... how to? Rod Questions (Windows Mobile) 9 12-17-2007 01:24 PM
Binary files on device Ianmac Questions (Windows Mobile) 4 08-24-2007 07:49 AM
Binary File problem Ianmac Questions (Windows Mobile) 3 08-07-2007 05:44 PM
binary serial input problem lucifer1 Questions (Windows Mobile) 3 06-03-2007 06:26 PM


All times are GMT. The time now is 03:16 AM.


Powered by vBulletin® Version 3.6.12
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0