I have a Problem with the COM Ports, perhaps it is my mistake, but in every case (COM1,2,3) i got an I/O Exception Error, when i want to open the COM Port. The code is working fine on my x64 System and I think everything is right.
I am working on armstonea5 with wec2013 and i read that i had to remove ndcucfg on Startup and deactivated Serial Debugging (ndcucfg --> Serial debug off, ),which i have done, but i have the same Problem on every com port.
Thank you very much !
//Action
//Class COMPortA
Code
- Imports System.IO.Ports
- Public Class COMPortA
- Dim SerialPort1 As SerialPort
- Private SerialDataReceivedEventHandler1 As New SerialDataReceivedEventHandler(AddressOf SerialPort1_DataReceived)
- Public Sub New()
- SerialPort1 = New SerialPort
- openComPort()
- End Sub
- Private Sub openComPort()
- Try
- If SerialPort1.IsOpen = False Then
- With SerialPort1
- .PortName = "COM1"
- .BaudRate = CInt("38400")
- .Parity = IO.Ports.Parity.None
- .DataBits = 7
- .StopBits = IO.Ports.StopBits.Two
- .Handshake = IO.Ports.Handshake.None
- .RtsEnable = False
- .DtrEnable = False
- .ReadTimeout = 2000
- End With
- SerialPort1.Open()
- AddHandler SerialPort1.DataReceived, SerialDataReceivedEventHandler1
- End If
- Catch ex As Exception
- MessageBox.Show(ex.Message)
- End Try
- End Sub
- Public Sub SerialPort1_DataWrite()
- Try
- SerialPort1.Write(New Byte(5) {81, 0, 49, 241, 0, 140}, 0, 6)
- Catch ex As Exception
- MessageBox.Show(ex.Message)
- End Try
- End Sub
- Private Sub SerialPort1_DataReceived(ByVal sender As Object, ByVal e As SerialDataReceivedEventArgs)
- Dim Bytenumber As Integer
- Dim readBuffer(5) As Byte
- Bytenumber = SerialPort1.BytesToRead
- SerialPort1.Read(readBuffer, 0, Bytenumber)
- For Each item In readBuffer
- MessageBox.Show(item.ToString)
- Next
- End Sub
- End Class
Edit by F&S: Fix indendation by using "code" tags.