send a byte
send a byte
send a byte
send a byte
send a byte
send a byte send a byte send a byte send a byte send a byte send a byte send a byte send a byte
send a byte send a byte
send a byte
Go Back  Xtreme Visual Basic Talk > > > send a byte


Reply
 
Thread Tools Display Modes
  #1  
Old 05-09-2009, 06:29 PM
johnsmith123 johnsmith123 is offline
Newcomer
 
Join Date: Jan 2006
Posts: 20
Default send a byte


Hello Guys,

I have a VB6 program I successfully wrote that communicates with an MP3 device. Very simple VB program reads a string of bytes (the configuration byte being the first byte) and depending on the user's input, sets/clears specific bits in the config byte, then the user can enter other data for the remaining bytes and the program re-writes the string back to the device.

The problem:

IF the first byte ends up a one char value (lower than 0x16) then it messes up the other bytes that are sent or read back later on in the program. For example:

the VB program reads the following string from the device:
Code:
17 62 DF FF FC 28 56
if the first byte is 07 (the upper nibble is 0, not 1) then the rest of the string is messed up by one char or 4 bits like this:

Code:
76 2D FF FF C2 85 06
the above string should look like this:
Code:
07 62 DF FF FC 28 56
the "0" in 07 does not appear, shifting all the data 4 bits to the left. I managed a workaround by setting bit 5, which then changes the first digit from a "0" to a "2", but then the device cannot use bit 5 for configuration, and I have to re-write the code for the MP3 device.

The data is converted to decimal before it is sent to the device with MSComm.

There must be a better way to do this. Anyone have any suggestions on how to make the configuration byte (1st byte in string) contain two chars or two nibbles no matter what the user enters?

How can I get around this? I am an assembly programmer, not a VB programmer.

Any ideas would be appreciated.

Last edited by johnsmith123; 05-09-2009 at 06:35 PM.
Reply With Quote
  #2  
Old 05-09-2009, 08:44 PM
vb5prgrmrsend a byte vb5prgrmr is offline
Senior Contributor

* Expert *
 
Join Date: Mar 2009
Posts: 1,087
Default

I believe it is in the way VB handles strings. It looks like because the first byte is 0, VB is expecting a unicode string. Try saving/reciving the data in a byte array.

Good Luck
Reply With Quote
  #3  
Old 05-10-2009, 07:14 AM
johnsmith123 johnsmith123 is offline
Newcomer
 
Join Date: Jan 2006
Posts: 20
Default

Thanks for the reply. I tried saving the string to a buffer, then writing the string with the same result.

There must be a simple way to get around this.
Reply With Quote
  #4  
Old 05-10-2009, 09:31 PM
vb5prgrmrsend a byte vb5prgrmr is offline
Senior Contributor

* Expert *
 
Join Date: Mar 2009
Posts: 1,087
Default

Don't know what to say, you should be recieving the 0'ed byte and you should be able to read said such byte...

Have you tried to read just the first byte???
Reply With Quote
  #5  
Old 05-11-2009, 12:29 AM
mkaras's Avatar
mkarassend a byte mkaras is offline
Ultimate Contributor

Retired Leader
* Expert *
 
Join Date: Mar 2004
Location: Beaverton, OR
Posts: 1,874
Default

It seems to me that the data is being brought from and sent to the device as a string of hex digits represented as ASCII characters. As you get set to send the data back to the device you need to properly convert the data to two digits characters for each byte. That means you need to use a conversion procedure that puts on leading zeros in the case that the byte value is less than 16. A pretty standard way to do this type of conversion of a byte to a string of two digits is to use the following line of code. In this code the variable bNum has the byte value. The result is placed into the two character string variable named bHexA.

bHexA = Right$("00" & Hex$(bNum), 2)

- mkaras
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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
send a byte
send a byte
send a byte send a byte
send a byte
send a byte
send a byte send a byte send a byte send a byte send a byte send a byte send a byte
send a byte
send a byte
 
send a byte
send a byte
 
-->