rs232

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Lou

    #1

    rs232

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

    Private Sub Rs232SendData(B yVal cmd As String)

    Try

    cmd=cmd & vbCrLf

    'Convert it to byte data here

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

    SerialPort1.Wri te(byteData)

    txtData.AppendT ext(Now.ToShort TimeString & "->Sent: " & cmd)

    Catch ex As System.Exceptio n

    MessageBox.Show (ex.Message)

    End Try

    End Sub


    -Lou


  • Spam Catcher

    #2
    Re: rs232

    "Lou" <lou.garvin@com cast.netwrote in news:#Rfx6YTpHH A.3968
    @TK2MSFTNGP06.p hx.gbl:
    How do i convert a string to bytes?
    Depending on what encoding you're using (ASCII in this case):

    System.Text.ASC IIEncoding.ASCI I.GetBytes(MySt ringHere)

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

    Comment

    • Cor Ligthert [MVP]

      #3
      Re: rs232

      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



      "Lou" <lou.garvin@com cast.netschreef in bericht
      news:%23Rfx6YTp HHA.3968@TK2MSF TNGP06.phx.gbl. ..
      How do i convert a string to bytes?
      I want to send raw bytes out the serial control.
      >
      Private Sub Rs232SendData(B yVal cmd As String)
      >
      Try
      >
      cmd=cmd & vbCrLf
      >
      'Convert it to byte data here
      >
      ??????????????? ??????????
      >
      SerialPort1.Wri te(byteData)
      >
      txtData.AppendT ext(Now.ToShort TimeString & "->Sent: " & cmd)
      >
      Catch ex As System.Exceptio n
      >
      MessageBox.Show (ex.Message)
      >
      End Try
      >
      End Sub
      >
      >
      -Lou
      >

      Comment

      • Lou

        #4
        Re: rs232

        Thanks everyone..

        "Cor Ligthert [MVP]" <notmyfirstname @planet.nlwrote in message
        news:%23UYsuSUp HHA.596@TK2MSFT NGP06.phx.gbl.. .
        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
        >
        >
        >
        "Lou" <lou.garvin@com cast.netschreef in bericht
        news:%23Rfx6YTp HHA.3968@TK2MSF TNGP06.phx.gbl. ..
        >How do i convert a string to bytes?
        >I want to send raw bytes out the serial control.
        >>
        >Private Sub Rs232SendData(B yVal cmd As String)
        >>
        >Try
        >>
        >cmd=cmd & vbCrLf
        >>
        >'Convert it to byte data here
        >>
        >?????????????? ???????????
        >>
        >SerialPort1.Wr ite(byteData)
        >>
        >txtData.Append Text(Now.ToShor tTimeString & "->Sent: " & cmd)
        >>
        >Catch ex As System.Exceptio n
        >>
        >MessageBox.Sho w(ex.Message)
        >>
        >End Try
        >>
        >End Sub
        >>
        >>
        >-Lou
        >>
        >
        >

        Comment

        Working...