S
SteelMillDon
Hi,
I'm really having problems converting the CopyMemory function from VB6 to
2005/2008 VB. I'm using UDP to catch data from a real time system (intel
MBII) then store data into SQL SERVER. Below is parts of my VB6 code. I'm not
sure if I should dump the SocketTool's (3rd party addon) and do all in VB.
Can some one please point me in the right direction?
Thanks
Don
Option Explicit
Private Declare Function SetThreadPriority Lib "kernel32" (ByVal hThread As
Long, ByVal nPriority As Long) As Long
Private Declare Function GetCurrentProcess Lib "kernel32" () As Long
Private Declare Function SetPriorityClass Lib "kernel32" (ByVal hProcess As
Long, ByVal dwPriorityClass As Long) As Long
Const REALTIME_PRIORITY_CLASS = &H100
Const HIGH_PRIORITY_CLASS = &H80
Private Declare Sub CopyMemory Lib "kernel32" _
Alias "RtlMoveMemory" _
(lpvDest As Any, lpvSrc As Any, ByVal dwSize&)
Private Declare Function timeGetTime Lib "winmm.dll" () As Long
Private Declare Function GetTickCount Lib "kernel32" () As Long
Private Type tcsDataType ' Real data coming from TM TCS System
MsgID As Long 'DINT
SeqCount As Long
QDIntelSysCntr As Long
StripID As String * 12 'in TCS as StripID(0 To 11) As Byte
ExitStripID As String * 12 'in TCS as StripID(0 To 11) As
Byte
StripWidth As Single
StripSetThick As Single
S1ActStripLength As Single
S2ActStripLength As Single
S3ActStripLength As Single
S4ActStripLength As Single
S5ActStripLength As Single
S5Speed As Single
C1RefTot As Single
C1OpTrim As Single
C1Act As Single
C2RefTot As Single
C2OpTrim As Single
C2Act As Single
ActFlatRef(0 To 53) As Single
ActFlatAct(0 To 53) As Single
C4Act As Single
SpareR01 As Single
SpareR02 As Single
SpareR03 As Single
SpareR04 As Single
SpareR05 As Single
SpareR06 As Single
SpareR07 As Single
SpareR08 As Single
SpareR09 As Single
SpareR10 As Single
SpareI01 As Long 'DINT
End Type
Private fromData As tcsDataType
Private fromBuffer(572) As Byte 'Was 272 'Make 572
Private sendBuffer(572) As Byte 'To CMCCEV
Private nBytes As Integer
Private nBytes2 As Integer
Private Sub Socket1_Read(DataLength As Integer, IsUrgent As Integer)
'Get Number of Bytes Recived from TCS
nBytes = Socket1.ReadBytes(fromBuffer)
'put into var
CopyMemory fromData, fromBuffer(0), Len(fromData)
CopyMemory sendBuffer(0), fromData, Len(fromData)
nBytes2 = Socket2.WriteBytes(sendBuffer)
' Put data into array that will be put to database table
With fromData
DataToDBTCS_Main(1) = .MsgID
DataToDBTCS_Main(2) = .SeqCount
DataToDBTCS_Main(3) = .QDIntelSysCntr
DataToDBTCS_Main(4) = timeGetTime
DataToDBTCS_Main(5) = Now
DataToDBTCS_Main(6) = .QDIntelSysCntr
DataToDBTCS_PDI(1) = .StripID
DataToDBTCS_PDI(2) = .ExitStripID
DataToDBTCS_PDI(3) = .StripWidth
DataToDBTCS_PDI(4) = .StripSetThick
DataToDBTCS_StripData(1) = .S1ActStripLength
DataToDBTCS_StripData(2) = .S2ActStripLength
DataToDBTCS_StripData(3) = .S3ActStripLength
DataToDBTCS_StripData(4) = .S4ActStripLength
DataToDBTCS_StripData(5) = .S5ActStripLength
DataToDBTCS_ProcessDataAct(1) = .S5Speed
DataToDBTCS_ProcessDataAct(2) = .S5Speed
'Put In Stand 5 Shape Data ACTUAL
DataToDBTCS_FlatnessS5Act(1) = .C1OpTrim
DataToDBTCS_FlatnessS5Act(2) = .C1Act
DataToDBTCS_FlatnessS5Act(3) = .C2OpTrim
DataToDBTCS_FlatnessS5Act(4) = .C2Act
DataToDBTCS_FlatnessS5Act(5) = .C4Act
For Index = 6 To 59
DataToDBTCS_FlatnessS5Act(Index) = .ActFlatAct(Index - 6)
Next Index
End With
End Sub
Private Sub Form_Load()
Dim Temp As Integer
OldSeqCount = 0
ErrorCountCycleTime = 0
ZeroShapeDataCount = 0
StripMovementInMeters = 0#
StripMovementInMetersResetAt10 = 0#
OldS5ActStripLength = 9999999
OldS5ActStripLengthForNewEntryCoil = 0#
StripMovementInMetersResetAt10 = 0#
OldEntryStripID = "123"
OldEntryStripID2 = "123"
OldExitStripID = "123"
NewEntryCoil = False
NewEntryCoilByZeroLengthCount = 0
ShapeDisplayAvgCount = 0
WaterFallDisplayAvgCount = 0
Timer1.Interval = 5000 ' Set Interval to 5 sec
QDIntelSysCntrOldValue = 0
TCSLinkDown = 0
TCSLinkDownResetCount = 0
DoubleW.Text = TCSLinkDownResetCount
'Zero Out Shape Display Data
For Index = 1 To 5
DataToDBTCS_ViolationParameters(Index) = 0#
DataToDBTCS_ViolationParametersZeroValue(Index) = 0#
Next Index
For Index = 0 To 53
DataToDBTCS_ShapeDisplay(Index) = 0#
DataToDBTCS_ShapeDisplayZeroValue(Index) = 0#
Next Index
'
' Initialize the socket control
'
Socket2.AddressFamily = AF_INET
Socket2.Binary = True
Socket2.Blocking = False
Socket2.Protocol = IPPROTO_IP
Socket2.SocketType = SOCK_DGRAM
'Socket2.LocalPort = 2500
Socket2.RemotePort = 3500
Socket2.HostName = "10.176.26.63"
Socket2.Action = SOCKET_OPEN
Socket1.AddressFamily = AF_INET
Socket1.Binary = True
Socket1.Blocking = False
Socket1.Protocol = IPPROTO_IP
Socket1.SocketType = SOCK_DGRAM
Socket1.LocalPort = 3000
Socket1.Action = SOCKET_OPEN
End Sub
Private Sub Form_Unload(Cancel As Integer)
If Socket1.Handle <> -1 Then Socket1.Action = SOCKET_CLOSE
MyConnection.Close
End Sub
Private Sub Socket1_LastError(ErrCode As Integer, ErrMsg As String, Response
As Integer)
MsgBox ErrMsg
End Sub
Private Sub SocketReset_Click()
Socket1.Action = SOCKET_FLUSH
If Socket1.Handle <> -1 Then Socket1.Action = SOCKET_CLOSE
Socket1.Action = SOCKET_OPEN
'Debug.Print "SOCKET RESET"
TCSLinkDownResetCount = TCSLinkDownResetCount + 1
DoubleW.Text = TCSLinkDownResetCount
End Sub
I'm really having problems converting the CopyMemory function from VB6 to
2005/2008 VB. I'm using UDP to catch data from a real time system (intel
MBII) then store data into SQL SERVER. Below is parts of my VB6 code. I'm not
sure if I should dump the SocketTool's (3rd party addon) and do all in VB.
Can some one please point me in the right direction?
Thanks
Don
Option Explicit
Private Declare Function SetThreadPriority Lib "kernel32" (ByVal hThread As
Long, ByVal nPriority As Long) As Long
Private Declare Function GetCurrentProcess Lib "kernel32" () As Long
Private Declare Function SetPriorityClass Lib "kernel32" (ByVal hProcess As
Long, ByVal dwPriorityClass As Long) As Long
Const REALTIME_PRIORITY_CLASS = &H100
Const HIGH_PRIORITY_CLASS = &H80
Private Declare Sub CopyMemory Lib "kernel32" _
Alias "RtlMoveMemory" _
(lpvDest As Any, lpvSrc As Any, ByVal dwSize&)
Private Declare Function timeGetTime Lib "winmm.dll" () As Long
Private Declare Function GetTickCount Lib "kernel32" () As Long
Private Type tcsDataType ' Real data coming from TM TCS System
MsgID As Long 'DINT
SeqCount As Long
QDIntelSysCntr As Long
StripID As String * 12 'in TCS as StripID(0 To 11) As Byte
ExitStripID As String * 12 'in TCS as StripID(0 To 11) As
Byte
StripWidth As Single
StripSetThick As Single
S1ActStripLength As Single
S2ActStripLength As Single
S3ActStripLength As Single
S4ActStripLength As Single
S5ActStripLength As Single
S5Speed As Single
C1RefTot As Single
C1OpTrim As Single
C1Act As Single
C2RefTot As Single
C2OpTrim As Single
C2Act As Single
ActFlatRef(0 To 53) As Single
ActFlatAct(0 To 53) As Single
C4Act As Single
SpareR01 As Single
SpareR02 As Single
SpareR03 As Single
SpareR04 As Single
SpareR05 As Single
SpareR06 As Single
SpareR07 As Single
SpareR08 As Single
SpareR09 As Single
SpareR10 As Single
SpareI01 As Long 'DINT
End Type
Private fromData As tcsDataType
Private fromBuffer(572) As Byte 'Was 272 'Make 572
Private sendBuffer(572) As Byte 'To CMCCEV
Private nBytes As Integer
Private nBytes2 As Integer
Private Sub Socket1_Read(DataLength As Integer, IsUrgent As Integer)
'Get Number of Bytes Recived from TCS
nBytes = Socket1.ReadBytes(fromBuffer)
'put into var
CopyMemory fromData, fromBuffer(0), Len(fromData)
CopyMemory sendBuffer(0), fromData, Len(fromData)
nBytes2 = Socket2.WriteBytes(sendBuffer)
' Put data into array that will be put to database table
With fromData
DataToDBTCS_Main(1) = .MsgID
DataToDBTCS_Main(2) = .SeqCount
DataToDBTCS_Main(3) = .QDIntelSysCntr
DataToDBTCS_Main(4) = timeGetTime
DataToDBTCS_Main(5) = Now
DataToDBTCS_Main(6) = .QDIntelSysCntr
DataToDBTCS_PDI(1) = .StripID
DataToDBTCS_PDI(2) = .ExitStripID
DataToDBTCS_PDI(3) = .StripWidth
DataToDBTCS_PDI(4) = .StripSetThick
DataToDBTCS_StripData(1) = .S1ActStripLength
DataToDBTCS_StripData(2) = .S2ActStripLength
DataToDBTCS_StripData(3) = .S3ActStripLength
DataToDBTCS_StripData(4) = .S4ActStripLength
DataToDBTCS_StripData(5) = .S5ActStripLength
DataToDBTCS_ProcessDataAct(1) = .S5Speed
DataToDBTCS_ProcessDataAct(2) = .S5Speed
'Put In Stand 5 Shape Data ACTUAL
DataToDBTCS_FlatnessS5Act(1) = .C1OpTrim
DataToDBTCS_FlatnessS5Act(2) = .C1Act
DataToDBTCS_FlatnessS5Act(3) = .C2OpTrim
DataToDBTCS_FlatnessS5Act(4) = .C2Act
DataToDBTCS_FlatnessS5Act(5) = .C4Act
For Index = 6 To 59
DataToDBTCS_FlatnessS5Act(Index) = .ActFlatAct(Index - 6)
Next Index
End With
End Sub
Private Sub Form_Load()
Dim Temp As Integer
OldSeqCount = 0
ErrorCountCycleTime = 0
ZeroShapeDataCount = 0
StripMovementInMeters = 0#
StripMovementInMetersResetAt10 = 0#
OldS5ActStripLength = 9999999
OldS5ActStripLengthForNewEntryCoil = 0#
StripMovementInMetersResetAt10 = 0#
OldEntryStripID = "123"
OldEntryStripID2 = "123"
OldExitStripID = "123"
NewEntryCoil = False
NewEntryCoilByZeroLengthCount = 0
ShapeDisplayAvgCount = 0
WaterFallDisplayAvgCount = 0
Timer1.Interval = 5000 ' Set Interval to 5 sec
QDIntelSysCntrOldValue = 0
TCSLinkDown = 0
TCSLinkDownResetCount = 0
DoubleW.Text = TCSLinkDownResetCount
'Zero Out Shape Display Data
For Index = 1 To 5
DataToDBTCS_ViolationParameters(Index) = 0#
DataToDBTCS_ViolationParametersZeroValue(Index) = 0#
Next Index
For Index = 0 To 53
DataToDBTCS_ShapeDisplay(Index) = 0#
DataToDBTCS_ShapeDisplayZeroValue(Index) = 0#
Next Index
'
' Initialize the socket control
'
Socket2.AddressFamily = AF_INET
Socket2.Binary = True
Socket2.Blocking = False
Socket2.Protocol = IPPROTO_IP
Socket2.SocketType = SOCK_DGRAM
'Socket2.LocalPort = 2500
Socket2.RemotePort = 3500
Socket2.HostName = "10.176.26.63"
Socket2.Action = SOCKET_OPEN
Socket1.AddressFamily = AF_INET
Socket1.Binary = True
Socket1.Blocking = False
Socket1.Protocol = IPPROTO_IP
Socket1.SocketType = SOCK_DGRAM
Socket1.LocalPort = 3000
Socket1.Action = SOCKET_OPEN
End Sub
Private Sub Form_Unload(Cancel As Integer)
If Socket1.Handle <> -1 Then Socket1.Action = SOCKET_CLOSE
MyConnection.Close
End Sub
Private Sub Socket1_LastError(ErrCode As Integer, ErrMsg As String, Response
As Integer)
MsgBox ErrMsg
End Sub
Private Sub SocketReset_Click()
Socket1.Action = SOCKET_FLUSH
If Socket1.Handle <> -1 Then Socket1.Action = SOCKET_CLOSE
Socket1.Action = SOCKET_OPEN
'Debug.Print "SOCKET RESET"
TCSLinkDownResetCount = TCSLinkDownResetCount + 1
DoubleW.Text = TCSLinkDownResetCount
End Sub