serialport send more than one byte?

DanielB33

Active member
Joined
Mar 29, 2013
Messages
40
Programming Experience
1-3
I am writing to a micro via usb using a virtual com port. I can send and receive data 1 byte at a time as shown below...

'Send "PAUSE" command
Dim buffer() As Byte = {80, 65, 85, 83, 69, 13}
mySerialPort.Write(buffer, 0, 1)
mySerialPort.Write(buffer, 1, 2)
mySerialPort.Write(buffer, 2, 3)
mySerialPort.Write(buffer, 3, 4)
mySerialPort.Write(buffer, 4, 5)
mySerialPort.Write(buffer, 5, 6)

This is time consuming and...not practical. I have to believe a printf() equivalent must have been included in vb.net in the process of the billions Microsoft spent making it??? I am not seeing anything online though.\

Note: If I tried to write mySerialPort.Write(buffer, 0, 6) to simply send the whole buffer, the device only sees the first character.

Thanks for the help.
 
If you send the whole buffer and it doesn't work then either you haven't configured the SerialPort properly or there's a limitation at the receiving end. So, how have you configured the SerialPort? Do you have any directions from the hardware provider as to how it should be done?

The SerialPort.Write method is overloaded and will accept a String.
 
Below is the configuration. Pretty straight forward, looks right to me. I can communicate with hyper-terminal just fine with it, back and forth. But when Sending a full string to my board, it only received the first character?

I should note that I CAN communicate just fine with my board via hyper terminal. But when my board and VB.Net start communicating...only 1 character received at a time.

I am using mySerialPort.Write("M1N: 10" & vbNewLine) format. This wont work unless I broke it up into sections and sent 1 character at a time.

Imports System.IO.Ports


Private mySerialPort As New SerialPort 'Define serial port object


Private Sub CommPortSetup() 'Initialize port with settings correspodning to PEM Relay Testing Board
With mySerialPort
.PortName = cboCOM.Text
.BaudRate = 115200
.DataBits = 8
.Parity = Parity.None
.StopBits = StopBits.One
.Handshake = Handshake.None
End With
Try
mySerialPort.Open()
Catch ex As Exception
MessageBox.Show("ERROR")
End Try
End Sub

Any ideas? This is killing me! I don'y want to send information 1 piece at a time.
 
Good thought. To change this all I do is place
Public Property Encoding As UTF32Encoding
in my code, right?

I believe it starts as ASCIIEncoding if not defined, and this is what I need. I tried changing them (by placing the above code) under public class main.

Any other ideas??? I will post if I find any solutions
 
No, Encoding is a property of the SerialPort class. You assign a Encoding object to your SerialPort object if you want to change from default encoding.
 
Back
Top