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 = CreateFileMapping(New IntPtr(-1), sa,
PageProtection.ReadWrite, 0, _
MaxDataSize + 4, ChannelName + "_BUFFER")
If (m_SharedFile = IntPtr.Zero) Then
Throw CreateApplicationException("Failed to create a file mapping to
slot " _
+ ChannelName + "_BUFFER")
End If
m_SharedMem = MapViewOfFile(m_SharedFile, SECTION_MAP_WRITE, 0, 0,
MaxDataSize + 4)
If (m_SharedMem = IntPtr.Zero) Then
Throw CreateApplicationException("Failed to create a mapping view
for slot " + ChannelName + "_BUFFER")
End If
Recieve routine
Dim arrSize As Integer = Marshal.ReadInt32(m_SharedMem)
Dim data(arrSize - 1) As Byte
Dim i As Integer
For i = 0 To arrSize - 1
data(i) = Marshal.ReadByte(New IntPtr(m_SharedMem.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 = CreateFileMapping(-1, sa, 4, 0, Quant + 4, ChannelName &
"_BUFFER")
hSharedMem = MapViewOfFile(hSharedFile, SECTION_MAP_WRITE, 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