Solved

Retrieving the Appropriate Bits From Data

Posted on 2003-11-25
9
240 Views
Last Modified: 2012-05-04
Hi All,

I have a problem. I will be using VB6 to code an application to retrieve the appropriate bits from the data. This application will communicate with Device 1, whilst Device 2 can only communicate with Device 1. The application in the PC will always poll Device 1 for data, whilst Device 1 will poll Device 2 for data. The data is stored in the buffer of the device. The protocol is as follows:-

<Head><Type><Level><ID><Command><Length><Data>
    01         01       01       01         4fH            n        12bytes

When <Level> = 2, this show that PC is polling for Device 2 data. Device 1 will start to poll data in Device 2 buffer. The data will then transfer from Device 2 buffer to Device 1 buffer. how can I code in VB to send this command to poll for device 2. After getting the data, how can i abstract the last 6 bytes from the data and drop the first 6 bytes?

thanks you
0
Comment
Question by:wmchew
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
  • +1
9 Comments
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 168 total points
ID: 9816675
I think you will have to explain more about your scenario.

Are you able to communicate OK with your devices?

Assuming you are, it appears to be a matter of manipulating strings.

If all you need to poll device 2 is to change the level then

Device2Data = Left$(Device1Data,2) & chr$(02) & Mid$(Device1Data, 3)
 
0
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 9816681
And to drop the first 6 bytes

strRestOfBuffer = Mid$(strFullBuffer, 7)

0
 

Author Comment

by:wmchew
ID: 9817244
hi GrahamSkan,

Ok. Let me be more detail. I have this application(coded in VB6) in PC monitoring 2 card access readers. They are both installed on a different floor of a building. These access readers actually stores the swipe card records in the readers. this application will always poll for data from reader in the 1st level(the one nearest PC) whilst PC can only communicate with reader 2 through reader 1.

As you can see from the protocol, when the level = 2, that mean PC wanted to poll data from reader 2(in 2nd level). Then reader 1 will recognise this and poll for data in reader 2 which was stored in buffer. The data was then transferred from reader 2 buffer to reader 1 buffer, finally to PC.

How should I code this part.

Secondly, after getting this data how can I abstract the last 6 bytes of the 12 bytes data?

thanks.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:wmchew
ID: 9817249
BTW, the devices can communicate. and the communication standard is RS485.
0
 
LVL 26

Assisted Solution

by:EDDYKT
EDDYKT earned 166 total points
ID: 9817405
To send command


dim str as string

str = chr$(1) + chr$(1) + chr$(2) + ....   ' you get the idea here
MSComm1.Output = str


To extract the data

use GrahamSkan's method


ie

dim str as string

str = MSComm1.Input
str = mid$(str, 13, 6)
0
 
LVL 28

Assisted Solution

by:Ark
Ark earned 166 total points
ID: 10161515
      First_six_bits = (lData And &HFFF000) / &H1000
       Second_six_bits = lData And &HFFF&
0
 
LVL 28

Expert Comment

by:Ark
ID: 10161520
PS.
or reverse according BigEndian/LittleIndian bytes order
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question