rs232

  • Thread starter Thread starter Lou
  • Start date Start date
L

Lou

How do i convert a string to bytes?
I want to send raw bytes out the serial control.

Private Sub Rs232SendData(ByVal cmd As String)

Try

cmd=cmd & vbCrLf

'Convert it to byte data here

?????????????????????????

SerialPort1.Write(byteData)

txtData.AppendText(Now.ToShortTimeString & "->Sent: " & cmd)

Catch ex As System.Exception

MessageBox.Show(ex.Message)

End Try

End Sub


-Lou
 
How do i convert a string to bytes?

Depending on what encoding you're using (ASCII in this case):

System.Text.ASCIIEncoding.ASCII.GetBytes(MyStringHere)

If it's another encoding type, swap ASCIIEncoding with the other classes.
 
Lou,

Maybe this page gives an explanation

http://msdn2.microsoft.com/en-us/library/ms172828.aspx

Use only ASCII if you are sure that you are only the 7 less significant
bites from a byte (127bits) as ASCII is only for that. It is using in a lot
of countries different code pages and gives therefore different results as
it is used in that if it is about the full byte.

Cor
 
Back
Top