Click here to Skip to main content
15,897,371 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi! everyone,

I'm making an app that connect to a serial port device, The Newbridge 36110 MainStreet, I am able to login type in a command like "CFG" then the terminal would prompt me with CFG>
but when I send a command like "FEP 01,X25" it gives me an error syntax error and it displays only "FEP[][]" then when I send that command again it would display "FEP,X[][]" then again would display "FEP 0[][]" it like can only process the 1st syntax not after the space or byte by byte not sure. By the way the [] is an ascii box code. Please help me on this guys. actual code below.

VB
       Dim WithEvents SP As New IO.Ports.SerialPort

       Private Sub frmMain_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        SP.PortName = "COM1"
        SP.BaudRate = 9600
        SP.Parity = IO.Ports.Parity.None
        SP.StopBits = IO.Ports.StopBits.One
        SP.DataBits = 8
        SP.DtrEnable = True
        SP.RtsEnable = True
        SP.Encoding = System.Text.Encoding.ASCII
        SP.Handshake = IO.Ports.Handshake.None
    End Sub

Private Sub btnSend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSend.Click
        Try
            SP.Write(txtCommand.Text & Chr(13))
            txtCommand.Text = String.Empty
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
    End Sub


Private Sub btnFEP_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFEP.Click
        'Send A FEP 01,X25 Command
        Dim str As String = "FEP 01,X25"
        SP.Write(str & Chr(13))
    End Sub


I created the btnFEP to send the command automatically, the command can also be sent from btnSEND where the txtCommand is where typed in the syntax.
Posted

1 solution

In string expressions the symbol "X" is used for specific purpose, check out the string format on msdn library you will find it, it is the reason I believe you are not getting the right output.
 
Share this answer
 
Comments
teebonaire 11-Jun-10 8:29am    
Thanks Muhammadumairomee for a response but sir, I tried sending "FEP 01" without "X25" I still got an error and response from serial port still contains [][] ascii codes... I've seen this code but it's C# I converted it to VB.NET:

Dim mbuffer as Byte() = System.Text.Encoding.Ascii.Getbytes("Hello World")
SerialPort.Write(mbuffer,0,mbuffer.Length)

I haven't tried it yet, I'll try this and update you if its gonna work.
teebonaire 15-Jun-10 1:49am    
Sorry the mbuffer code did not work.
teebonaire 15-Jun-10 3:55am    
Follow Up Question : How to add vbCR in SP.Write(mbuffer,0,mbuffer.length)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900