Getting Propeller to communicate with VB.NET using SEROUT (BS2_Functions OBJ)
Hey guys.
I'm working on trying to get a Propeller to communicate to a VB.NET program using the BS2_Functions Object from the Object Exchange. I'm fairly new to the Propeller, so I want to make sure that I'm doing everything correctly. Every time I run the program the red light on the QuickStart flashes, so I assume that data gets sent out, but right after that the TextBox on the VB Program stays the same value. Can anyone see what I'm doing wrong??
SPIN
VB.NET
I don't know if I'm doing the Serial Port part on VB the correct way. It's been a while since I've dealt with Serial Ports in VB.NET.
EDIT:
I found the Serial Port code for VB that I used a while back and it works fine with the BS2 using
I'm working on trying to get a Propeller to communicate to a VB.NET program using the BS2_Functions Object from the Object Exchange. I'm fairly new to the Propeller, so I want to make sure that I'm doing everything correctly. Every time I run the program the red light on the QuickStart flashes, so I assume that data gets sent out, but right after that the TextBox on the VB Program stays the same value. Can anyone see what I'm doing wrong??
SPIN
OBJ BS2 : "BS2_Functions"
PUB main
BS2.start(31,30)
pause(10000)
BS2.Serout_Str(5,string("Hello World!"),9600,1,8)
PUB pause(ms)
waitcnt(clkfreq/1000 * ms + cnt)
VB.NET
Public Class Form1
Private WithEvents COMPort As New IO.Ports.SerialPort
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If COMPort.IsOpen Then
COMPort.Close()
End If
Try
With COMPort
.PortName = "COM7"
.BaudRate = 9600
.Parity = IO.Ports.Parity.None
.DataBits = 8
.StopBits = IO.Ports.StopBits.One
.Handshake = IO.Ports.Handshake.None
End With
COMPort.Open()
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
Private Sub COMPort_DataReceived(ByVal sender As System.Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles COMPort.DataReceived
TextBox1.Text = COMPort.ReadLine
End Sub
End Class
I don't know if I'm doing the Serial Port part on VB the correct way. It's been a while since I've dealt with Serial Ports in VB.NET.
EDIT:
I found the Serial Port code for VB that I used a while back and it works fine with the BS2 using
SEROUT 16, 16468, ["Hello World!"]but when I use the Propeller code (above) it doesn't do anything but send a '?' to the computer. Am I using the Prop SEROUT correctly?

Comments
I've not used the BS2 functions, so I'm wondering what the "5" parameter is for ?
BS2.Serout_Str(5,string("Hello World!"),9600,1,8)
Also, you might need to send a carriage return after the string.
Bean
CON _clkmode = xtal1 + pll16x _xinfreq = 5_000_000 OBJ BS2 : "BS2_Functions" PUB main BS2.start(31,30) pause(1000) BS2.Serout_Str(30,string("Hello World!"),9600,1,8) PUB pause(ms) waitcnt(clkfreq/1000 * ms + cnt)Also, this is bad in a Win Form...
Private Sub COMPort_DataReceived(ByVal sender As System.Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles COMPort.DataReceived TextBox1.Text = COMPort.ReadLine End SubYou need a method like the on below to write to the UI from a secondary thread. Your method will work for the most part but it can cause unexpected results from time to time.
private void SetText(String message) { try { if (txtStatus.InvokeRequired) { SetTextCallback del = new SetTextCallback(SetText); this.Invoke(del, message); } else { txtStatus.AppendText(message); } } catch (Exception ex) { throw ex; } }Serial comms in vb.net are a bit funky in my experience. Would you mind sharing your vb.net code?
Private readBuffer As String = String.Empty Private CharToRead As String = String.Empty Private Bytenumber As Integer Private ByteToRead As Integer Private byteEnd(2) As Char Private comOpen As Boolean Private counter As Integer = 0 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load With comPort .ParityReplace = &H3B .PortName = "COM7" .BaudRate = 9600 .Parity = IO.Ports.Parity.None .DataBits = 8 .StopBits = IO.Ports.StopBits.One .Handshake = IO.Ports.Handshake.None .RtsEnable = False .ReceivedBytesThreshold = 1 .NewLine = vbCr .ReadTimeout = 10000 End With Try comPort.Open() comOpen = comPort.IsOpen Catch ex As Exception comOpen = False MsgBox(ex.Message) End Try End Sub Public Sub DoUpdate(ByVal sender As Object, ByVal e As System.EventArgs) TextBox1.Text = readBuffer End Sub Private Sub comPort_DataReceived(ByVal sender As System.Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles comPort.DataReceived If comOpen Then Try Threading.Thread.Sleep(250) 'This pause can be removed. Just wanted to make sure that everything in the string was being read. byteEnd = comPort.NewLine.ToCharArray Bytenumber = comPort.BytesToRead readBuffer = comPort.ReadExisting Me.Invoke(New EventHandler(AddressOf DoUpdate)) Catch ex As Exception MsgBox(ex.Message) End Try End If End Sub