2
我的问题是,当我运行程序它工作得很好,但程序的一个周期后崩溃。下面是一些代码:串行端口system.unauthorizedaccess
Private Sub Receiver(ByVal sender As Object, ByVal e As SerialDataReceivedEventArgs) Handles COMPort.DataReceived
Dim RXByte As Byte
key = 0
cut = False
c.Open()
Do
RXCnt = 0
Do
RXByte = COMPort.ReadByte
If (RXByte = 29) Then
c.Write(Chr(10))
cut = True
c.Close()
If c.IsOpen = False Then
ts = "BLAH"
Process.Start(System.Windows.Forms.Application.StartupPath & "\e.exe", ts)
Process.Start(System.Windows.Forms.Application.StartupPath & "\Test.exe", c.PortName)
Else
End If
End If
If (cut = True) Then
Exit Do
End If
c.Write(Chr(RXByte))
addText(Chr(RXByte))
RXArray(RXCnt) = LookUpTable(RXByte >> 4)
RXCnt = RXCnt + 1
RXArray(RXCnt) = LookUpTable(RXByte And 15)
RXCnt = RXCnt + 1
RXArray(RXCnt) = " "
RXCnt = RXCnt + 1
SpaceCount = (SpaceCount + 1) And 31
If SpaceCount = 0 Then
RXArray(RXCnt) = Chr(13) ' CR
RXCnt = RXCnt + 1
RXArray(RXCnt) = Chr(10) ' LF
RXCnt = RXCnt + 1
Else
If (SpaceCount And 3) = 0 Then
RXArray(RXCnt) = " "
RXCnt = RXCnt + 1
RXArray(RXCnt) = " "
RXCnt = RXCnt + 1
End If
End If
Loop Until (COMPort.BytesToRead = 0)
Me.Invoke(New MethodInvoker(AddressOf Display))
Loop Until (COMPort.BytesToRead = 0)
c.Close()
End Sub
我相信这个问题在代码
Process.Start(System.Windows.Forms.Application.StartupPath & "\Test.exe", c.PortName)
系统抛出一个System.UnauthorizedAccessException的错误在这一点上发生。此外,测试程序还与相同的串行端口进行通信。当我运行程序时,进程启动并完成,但当前进程抛出错误。这是UAC错误吗?
好,如果你看看代码我打开test.exe之前关闭端口,所以不应该再次打开端口? –
什么是'c'和'COMPort'?两个不同的串行端口? – dsolimano