程序是通过摄像机返回的图像识别车牌,然后把车牌通过串口发送到IDE上显示,下面是代码,cpsb_HavePlates是识别到车牌的事件,sendPlateToLED是
发送车牌到IED,在运行生成的EXE的时候如果我把sendPlateToLED (plateName)屏蔽没问题,如果我加上的话就报内存错误,直接运行工程都没问题
Private Sub cpsb_HavePlates(ByVal strPicName As String, ByVal strPlateName As String, ByVal strPlateColor As String, ByVal trPlateType As String)
Dim picName, plateName, plateColor, plateType, driection As String
driection = cpsb.GetDriection
If driection = "向上行驶" Or driection = "向左行驶" Then
Exit Sub
Else
isOK = False
plateName = strPlateName
Label3.Caption = plateName
'Label3.Caption = driection
plate = plateName
sendPlateToLED (plateName)
End If
End Sub
Private Function sendPlateToLED(ByVal plateName As String)
On Error GoTo myerr
Dim outByte(15) As Byte
Dim dataByte() As Byte
Dim dataLen As Integer
Dim checknum, index As Integer
checknum = 0
If MSComm1.PortOpen = False Then
MSComm1.CommPort = comPort
' 9600 波特,无奇偶校验,8 位数据,一个停止位。
MSComm1.Settings = "9600,N,8,1"
' 打开端口。
MSComm1.PortOpen = True
MSComm1.InputMode = comInputModeBinary
End If
' 告诉控件读入整个缓冲区。
MSComm1.InputLen = 0
MSComm1.InBufferCount = 0
MSComm1.OutBufferCount = 0
'生成数据包
dataByte = StrConv(plateName, vbFromUnicode)
dataLen = UBound(dataByte) + 4
outByte(0) = &HAA
outByte(1) = &H55
outByte(2) = Val("&h" & Hex(dataLen))
outByte(3) = &H0
outByte(4) = &H70
index = 5
For i = 0 To UBound(dataByte)
outByte(i + 5) = dataByte(i)
index = index + 1
Next
For i = 2 To UBound(outByte)
checknum = checknum + outByte(i)
Next
outByte(index) = Val("&h" & Right(Hex(checknum), 2))
outByte(index + 1) = Val("&h" & Left(Hex(checknum), 1))
'发送数据包。
MSComm1.Output = outByte
Sleep (200)
Call openLED
Command1.Enabled = True
Timer1.Enabled = True
Exit Function
myerr:
MsgBox "向LED发送文本出错:" + Err.Description
End Function
发送车牌到IED,在运行生成的EXE的时候如果我把sendPlateToLED (plateName)屏蔽没问题,如果我加上的话就报内存错误,直接运行工程都没问题
Private Sub cpsb_HavePlates(ByVal strPicName As String, ByVal strPlateName As String, ByVal strPlateColor As String, ByVal trPlateType As String)
Dim picName, plateName, plateColor, plateType, driection As String
driection = cpsb.GetDriection
If driection = "向上行驶" Or driection = "向左行驶" Then
Exit Sub
Else
isOK = False
plateName = strPlateName
Label3.Caption = plateName
'Label3.Caption = driection
plate = plateName
sendPlateToLED (plateName)
End If
End Sub
Private Function sendPlateToLED(ByVal plateName As String)
On Error GoTo myerr
Dim outByte(15) As Byte
Dim dataByte() As Byte
Dim dataLen As Integer
Dim checknum, index As Integer
checknum = 0
If MSComm1.PortOpen = False Then
MSComm1.CommPort = comPort
' 9600 波特,无奇偶校验,8 位数据,一个停止位。
MSComm1.Settings = "9600,N,8,1"
' 打开端口。
MSComm1.PortOpen = True
MSComm1.InputMode = comInputModeBinary
End If
' 告诉控件读入整个缓冲区。
MSComm1.InputLen = 0
MSComm1.InBufferCount = 0
MSComm1.OutBufferCount = 0
'生成数据包
dataByte = StrConv(plateName, vbFromUnicode)
dataLen = UBound(dataByte) + 4
outByte(0) = &HAA
outByte(1) = &H55
outByte(2) = Val("&h" & Hex(dataLen))
outByte(3) = &H0
outByte(4) = &H70
index = 5
For i = 0 To UBound(dataByte)
outByte(i + 5) = dataByte(i)
index = index + 1
Next
For i = 2 To UBound(outByte)
checknum = checknum + outByte(i)
Next
outByte(index) = Val("&h" & Right(Hex(checknum), 2))
outByte(index + 1) = Val("&h" & Left(Hex(checknum), 1))
'发送数据包。
MSComm1.Output = outByte
Sleep (200)
Call openLED
Command1.Enabled = True
Timer1.Enabled = True
Exit Function
myerr:
MsgBox "向LED发送文本出错:" + Err.Description
End Function
Private Function sendPlateToLED(ByVal plateName As String)
On Error GoTo myerr
Dim outByte(15) As Byte
Dim dataByte() As Byte
Dim dataLen As Integer
Dim checknum, index As Integer
checknum = 0
If MSComm1.PortOpen = False Then
MSComm1.CommPort = 1 'comPort
' 9600 波特,无奇偶校验,8 位数据,一个停止位。
MSComm1.Settings = "9600,N,8,1"
' 打开端口。
MSComm1.PortOpen = True
MSComm1.InputMode = comInputModeBinary
End If
' 告诉控件读入整个缓冲区。
MSComm1.InputLen = 0
MSComm1.InBufferCount = 0
MSComm1.OutBufferCount = 0
'生成数据包
dataByte = StrConv(plateName, vbFromUnicode)
dataLen = UBound(dataByte) + 4
outByte(0) = &HAA
outByte(1) = &H55
outByte(2) = Val("&h" & Hex(dataLen))
outByte(3) = &H0
outByte(4) = &H70
index = 5
Dim i As Long
For i = 0 To UBound(dataByte)
outByte(i + 5) = dataByte(i)
index = index + 1
Next
For i = 2 To UBound(outByte)
checknum = checknum + outByte(i)
Next
outByte(index) = Val("&h" & Right(Hex(checknum), 2))
outByte(index + 1) = Val("&h" & Left(Hex(checknum), 1))
'发送数据包。
MSComm1.Output = outByte
'Sleep (200)
'Call openLED
Command1.Enabled = True
Timer1.Enabled = True
Exit Function
myerr:
MsgBox "向LED发送文本出错:" + Err.Description
End FunctionPrivate Sub Command1_Click()
Call sendPlateToLED(strplateName)
End SubPrivate Sub Form_Load()
strplateName = "123456"
End Sub
Dim picName, plateName, plateColor, plateType, driection As String
driection = cpsb.GetDriection
If driection = "向上行驶" Or driection = "向左行驶" Then
Exit Sub
Else
isOK = False
plateName = strplateName
Label3.Caption = plateName
'Label3.Caption = driection
plate = plateName
Call sendPlateToLED(plateName)
End If
End Sub在sendPlateToLED (plateName)前加Call