Solved

Retrieving the Appropriate Bits From Data

Posted on 2003-11-25
9
209 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
  • 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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 

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 27

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 27

Expert Comment

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

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

747 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now