VB.NET with X2 1284p

I’m trying to use .NET on the the X2 1284p (I’m positive the card is working perfectly because I have already successfully connected with AVRStudio/AVRISP and have run sample programs). I reused the code from here: (pololu.com/docs/0J36/6) with one difference: I’m using VB.NET instead of C#.NET. The code starts to execute okay, but, then, gets hung up on the line indicated below. I’ve gotten the same result when attempting it in (or out of) programming mode. Any ideas? Thanks, in advance.

Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        'Choose the port name and the baud rate. 
        Dim port As System.IO.Ports.SerialPort = New System.IO.Ports.SerialPort("COM5", 115200)

        'Connect to the port.

        'Transmit two bytes on the TX line: 1, 2
        port.Write(New Byte() {1, 2}, 0, 2)

        'Wait for a byte to be received on the RX line.
        Dim response As Integer = port.ReadByte() [b]-- Program hangs up here.[/b]

        'Show the user what byte was received.
        MsgBox("Received byte: " + response.ToString)

        'Disconnect from the port so that other programs can use it.

    End Sub

End Class


What do you expect to happen when you run that program? You haven’t said anything about the program you have running on the X2; did you actually program the X2 to receive and respond to serial data? Since you didn’t post your X2 code, it makes me think your hanging problem is being caused by waiting for data that the X2 never sends.

Also, the X2 should not be in programming mode when you send general serial data. In programming mode, incoming serial data is interpreted as AVRISP programming commands.

Also, in the interest of fostering better communication that will make troubleshooting smoother, I want to point out that comments like this are confusing and make it hard to initially figure out what you’re trying to do:

It makes it sound like you are trying to program the X2 in Visual Basic, which could immediately explain why you’re having problems. The better way to convey your situation (as I understand it) is that you’re “trying to write a PC program in .NET (Visual Basic) to send serial bytes to and receive serial bytes from the X2 via its USB connector.” Is my understanding of your situation correct?

- Ben

Yes, your understanding is correct. I was using the sample code because I just wanted to run a quick VB.NET test on the board, but I think I understand why the sample code was hanging up now. Ultimately, I’m going to use the board for driving gearmotors and would like to be able to write that code in VB.NET (as opposed to loading code on the X2, the PC will always be connected to the board and control the board/motors from a VB.NET program). Thanks!