My VB2005 program has a DataReciever thread that recieves data from an
Activex VB6 thread. The data comes from a USB device that delivers 10 bit
data in a series of bytes.
So the low byte can be 0 to 255 but the high byte can only be 0 to 4. What's
happening is that quite often a zero high byte becomes 255 after it goes
through shared memory.
The bytes are in groups of 24 bytes.
As you will see below, I added a check loop in the VB6 transmitter that will
present a msgbox if the high byte is greater than 4. Never happens.
I added the same feature to the data receiver and in a group of 24 bytes I
get at least four or five MsgBox messages. The values are always 255 instead
of 0.
Anyone have a clue as to what's wrong?
Galen
VB2005
Shared memory
m_SharedFile = CreateFileMappi ng(New IntPtr(-1), sa,
PageProtection. ReadWrite, 0, _
MaxDataSize + 4, ChannelName + "_BUFFER")
If (m_SharedFile = IntPtr.Zero) Then
Throw CreateApplicati onException("Fa iled to create a file mapping to
slot " _
+ ChannelName + "_BUFFER")
End If
m_SharedMem = MapViewOfFile(m _SharedFile, SECTION_MAP_WRI TE, 0, 0,
MaxDataSize + 4)
If (m_SharedMem = IntPtr.Zero) Then
Throw CreateApplicati onException("Fa iled to create a mapping view
for slot " + ChannelName + "_BUFFER")
End If
Recieve routine
Dim arrSize As Integer = Marshal.ReadInt 32(m_SharedMem)
Dim data(arrSize - 1) As Byte
Dim i As Integer
For i = 0 To arrSize - 1
data(i) = Marshal.ReadByt e(New IntPtr(m_Shared Mem.ToInt32() + i +
4))
Next
For i = 1 To arrSize - 1 Step 2
If data(i) 4 Then
MsgBox "Too big " & i & " " & data(i)
End If
Next
RaiseEvent OnData(data)
VB6 ActiveX
Shared memory
hSharedFile = CreateFileMappi ng(-1, sa, 4, 0, Quant + 4, ChannelName &
"_BUFFER")
hSharedMem = MapViewOfFile(h SharedFile, SECTION_MAP_WRI TE, 0, 0, Quant +
4)
Transmit routine
Public Sub Transmit()
On Error GoTo Transmit_Error
CopyMemory ByVal hSharedMem, Quant, 4
Dim i As Long
For i = 0 To Quant - 1
CopyMemory ByVal (hSharedMem + 4 + i), DatAry(i), 1
Next
SetEvent hEventData
For i = 1 To Quant - 1 Step 2
If DatAry(i) 4 Then
MsgBox "Too big " & i & " " & DatAry(i)
Exit For
End If
Next
On Error GoTo 0
Exit Sub
Transmit_Error:
MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure
Transmit"
End Sub 5 1456
Galen,
>So the low byte can be 0 to 255 but the high byte can only be 0 to 4. What's happening is that quite often a zero high byte becomes 255 after it goes through shared memory.
Are all the other values (the low bytes and the array size) correct?
>Anyone have a clue as to what's wrong?
No, the code sure looks like it should work.
I would just recommend that you read/write the entire array at once
(with a single call to CopyMemory in the VB6 side and by using
Marshal.Copy on the managed site) rather than byte by byte.
Mattias
--
Mattias Sjögren [C# MVP] mattias @ mvps.org http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Inline
"Mattias Sjögren" <ma************ ********@mvps.o rgwrote in message
news:ez******** ******@TK2MSFTN GP06.phx.gbl...
Galen,
>>So the low byte can be 0 to 255 but the high byte can only be 0 to 4. What's happening is that quite often a zero high byte becomes 255 after it goes through shared memory.
Are all the other values (the low bytes and the array size) correct?
Yes, they appear to be correct and the array size is correct.
>
>>Anyone have a clue as to what's wrong?
No, the code sure looks like it should work.
I would just recommend that you read/write the entire array at once
(with a single call to CopyMemory in the VB6 side and by using
Marshal.Copy on the managed site) rather than byte by byte.
I would like to. The array size is written by naming the variable and
showing #bytes as 4.
Would I just give the array name and #bytes as 24 ??
>
Mattias
--
Mattias Sjögren [C# MVP] mattias @ mvps.org http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Galen
The aheader I go, the behinder I get.
Changed byte reads to array copy. Same problem, 0's sent to shared memory
become 255's in managed code.
I added some test lines to both the data transmitter and the data reciever
as follows:
VB2005
Marshal.Copy(Ne w IntPtr(m_Shared Mem.ToInt32() + 4), bytAry, 0, 24)
For i = 1 To arrSize - 1 Step 2
TestAry(TestCou nt) = bytAry(i)
TestCount = TestCount + 1
If bytAry(i) = 255 Then bytAry(i) = 0
Next
RaiseEvent OnData()
VB6 ActiveX
For i = 1 To Quant - 1 Step 2
If DatAry(i) <0 Then
MsgBox "Not zero " & i & " " & DatAry(i)
Exit For
End If
Next
It turns out that all integer values from USB device are 255 and below. So
the VB6 MsgBox never appears.
But a look at the TestAry in VB2005 shows at least 30% of the high bytes are
255 ???
HELP ME
Galen
"Galen Somerville" <ga***@communit y.nospamwrote in message
news:ef******** ******@TK2MSFTN GP03.phx.gbl...
Inline
"Mattias Sjögren" <ma************ ********@mvps.o rgwrote in message
news:ez******** ******@TK2MSFTN GP06.phx.gbl...
>Galen,
>>>So the low byte can be 0 to 255 but the high byte can only be 0 to 4. What's happening is that quite often a zero high byte becomes 255 after it goes through shared memory.
Are all the other values (the low bytes and the array size) correct?
Yes, they appear to be correct and the array size is correct.
>>
>>>Anyone have a clue as to what's wrong?
No, the code sure looks like it should work.
I would just recommend that you read/write the entire array at once (with a single call to CopyMemory in the VB6 side and by using Marshal.Copy on the managed site) rather than byte by byte.
I would like to. The array size is written by naming the variable and
showing #bytes as 4.
Would I just give the array name and #bytes as 24 ??
>> Mattias
-- Mattias Sjögren [C# MVP] mattias @ mvps.org http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com Please reply only to the newsgroup.
Galen
Hi Galen,
It seem fine with your code. I cannot figure out the root cause just now,
but we suggest you may write all binary data into file before sent them to
DataReciever, and write all received binary data into another file after
DataReciever received data. These two binary files should be same. Please
compare them with "fc /b binarayfile1.da t binarayfile2.da t". This will tell
you what wrong with them. Additionally, you may open two binary files with
"UltraEdit" to drill down and trouble-shot the issue.
About how to write binary data into binary file in VB.net
Dim binWriter As New IO.BinaryWriter (System.IO.File .Create("c:\
binarayfile2.da t"))
binWriter.BaseS tream.Write(dat a,0,data.Length )
binWriter.Close ()
About how to write binary data into file in VB, please reference the
following document. http://www.computing.net/programming...orum/1965.html
[Subject: VB6 Read/Write Binary File]
Hope this helps.
Sincerely,
Wen Yuan
Thanks, will give that a try.
Galen
""WenYuan Wang"" <v-******@online.m icrosoft.comwro te in message
news:Mm******** ******@TK2MSFTN GHUB02.phx.gbl. ..
Hi Galen,
It seem fine with your code. I cannot figure out the root cause just now,
but we suggest you may write all binary data into file before sent them to
DataReciever, and write all received binary data into another file after
DataReciever received data. These two binary files should be same. Please
compare them with "fc /b binarayfile1.da t binarayfile2.da t". This will
tell
you what wrong with them. Additionally, you may open two binary files with
"UltraEdit" to drill down and trouble-shot the issue.
About how to write binary data into binary file in VB.net
Dim binWriter As New IO.BinaryWriter (System.IO.File .Create("c:\
binarayfile2.da t"))
binWriter.BaseS tream.Write(dat a,0,data.Length )
binWriter.Close ()
About how to write binary data into file in VB, please reference the
following document. http://www.computing.net/programming...orum/1965.html
[Subject: VB6 Read/Write Binary File]
Hope this helps.
Sincerely,
Wen Yuan This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Charles Hunt |
last post by:
Hi,
When running this code in VB2003
Sub guidtest()
Dim gstring As String
Dim gid As Guid
|
by: Larry Lard |
last post by:
This came out of a thread explaining to "BK" about error BC42025
("Access of shared member through an instance; qualifying expression
will not be evaluated"); Frans Clasener then came up with another
similar problem, which I believe shows up a bug (well, a problem) in
VB2005.
As many will know, VB2005 saw the reintroduction of the 'default
instance' of Form classes, allowing one to write code such as
Form1.Show
|
by: MikeCS |
last post by:
Problem:
I wanted to implement what I did in VB6 where I would use a global structure and dimension an array of structures then the program could load data into it at start up. Global routines would be able access the data whenever required and save any changes. Since it isn't a lot of data, I don't want the overhead of a dbms.
With VB2005 (express) I created a class that consisted essentially of one record of the previous structure. Now I...
|
by: MikeCS |
last post by:
Problem:
I wanted to implement what I did in VB6 where I would use a global structure and dimension an array of structures then the program could load data into it at start up. Global routines would be able access the data whenever required and save any changes. Since it isn't a lot of data, I don't want the overhead of a dbms.
With VB2005 (express) I created a class that consisted essentially of one record of the previous structure. Now I...
|
by: Galen Somerville |
last post by:
I have been converting a VB6 project to VB2005 for lo these many months.
Most of my problems have been solved thanks to people like WanYuan Wang and
Mattias Sjogren. But now the Graphics aspect is the problem.
This program gets Heart sounds and ECG trace data from a USB device via an
ActiveX thread and an internal DataReciever thread in the main program. The
display is like an oscilloscope in that it sweeps across the screen in real...
| |
by: Aalaan |
last post by:
I am presently a user of classic vb6 and hang out on those newsgroups. Some
of you may be aware that there is a very anti MS and vb2005 feeling there. I
have tried to get them to tell me which features of vb2005 are actually
worse then vb6 in practice, and forget the philosophy of backward
compatibility for a moment.
I would now like to hear "the other side". Could *anyone who previously used
vb6* (only those pleased; I feel the others...
|
by: Javad |
last post by:
Hello
I know that I should get the information of windows internet connections by
using "rasapi32.dll" library, and I also have some sample codes, but I can't
make them work. My exact need is to get the "UserName" of a connection. How
is it possible?
plz hlp
thnk u
|
by: =?Utf-8?B?QmVu?= |
last post by:
Hi all,
I am new to vb2005. I have two list boxes on a form. one on the left and
the other on the right. The left contains a list of items. Between the two
list boxes I have a button to add selected items in the left list box to the
right list box.
Programmatically, I need to item I am trying to add from the left list box
is not already in the right list box so as not to create a duplicate entry.
When I click on the add button, it...
|
by: Vae07 |
last post by:
Ok so here is a brief summary of my problem. I need a pop up form that submits input text box information to a pocket excel workbook upon a command botton click. Text box inputs are checked for validity upon individual text box exit (don't have a problem with this part).
All this could be done with Excel VBA easily, but pocket excel doesn't have VBA/Macro support. In as much, I have been trying to create a VB2005 application that I can load...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |