am able to send hex data to the hardware device but not able to receive the data it is sending here is my code
Expand|Select|Wrap|Line Numbers
- Public Function getMessage() As Integer
- Try
- Dim hostEntry As IPHostEntry = Nothing
- Dim s As Socket = Nothing
- Dim i As Integer
- Dim str, str1 As String
- str = String.Empty
- 'serialport.Open()
- If ServerConnection = True Then
- While True
- If ServerConnection = True Then
- str1 = String.Empty
- Dim byteToRead As Byte = serialport.ReadByte()
- Buffer.Add(byteToRead)
- If Buffer.Count < 7 Then
- 'If Buffer.Count < 7 And Buffer.Item(0) = &H1 And Buffer.Item(2) = &H4 And Buffer.Item(3) = &H50 And Buffer.Item(4) = &H0 And Buffer.Item(5) = &H10 And Buffer.Item(7) = &HFF Then
- receivesuccess = True
- For iInside As Integer = 0 To 7
- str = Hex(Buffer.Item(iInside))
- If str.Length = 1 Then
- str = "0" + str
- End If
- str1 += str + " "
- Next
- RR.Insert(0, str1)
- 'End If
- End If
- End If
- End While
- End If
- End Function
this is send message in hex format and this is working and it is writing data to the serial port and am able to display it.
Expand|Select|Wrap|Line Numbers
- Public Function SendMessage(ByVal NoOfData As Integer) As Integer
- Try
- serialport.Close()
- serialport.Open()
- 'serialport.PortName = "COM3"
- If serialport.IsOpen Then
- serialport.Write(MassageToSend, 0, NoOfData)
- 'serialport.Read(ReceivedResponse, 0, 24)
- Dim str, str1 As String
- str = ""
- For ctr As Byte = 0 To CByte(NoOfData - 1)
- str1 = Hex(ServerComm.MassageToSend(ctr))
- If str1.Length = 1 Then
- str1 = "" + "0" + str1 + ""
- End If
- str = str + Space(7) & str1 + ""
- Next
- str = ">>" + str
- Threading.Thread.Sleep(100)
- 'str = System.Text.Encoding.Default(str + vbCrLf)
- With SunRose.tbText
- .Font = New Font("Garamond", 12.0!, FontStyle.Regular)
- SunRose.Tx.FillColor = Color.White
- SunRose.Tx.FillColor = Color.Red
- .SelectionColor = Color.Red
- .AppendText(str & vbCrLf)
- .ScrollToCaret()
- Dim file As String = Application.StartupPath() + "\Backup\Excel\" + "HEXdata" + System.DateTime.Now.ToString("dd" & "MM" & "" & "yyyy") + ".csv"
- Dim str_send = ""
- str_send += str + " - " + System.DateTime.Now.ToString("dd") + "/" + System.DateTime.Now.ToString("MM") + "/" + System.DateTime.Now.ToString("yyyy") + " " + System.DateTime.Now.ToString("HH") + ":" + System.DateTime.Now.ToString("mm") + ":" + System.DateTime.Now.ToString("ss") + vbCrLf
- End With
- Threading.Thread.Sleep(800)
- end sub