473,395 Members | 1,631 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

how to receive data from a hardware device through serial port.

hii
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
  1. Public Function getMessage() As Integer
  2.         Try
  3.             Dim hostEntry As IPHostEntry = Nothing
  4.             Dim s As Socket = Nothing
  5.  
  6.  
  7.             Dim i As Integer
  8.             Dim str, str1 As String
  9.             str = String.Empty
  10.             'serialport.Open()
  11.  
  12.             If ServerConnection = True Then
  13.                 While True
  14.                     If ServerConnection = True Then
  15.                         str1 = String.Empty
  16.  
  17.  
  18.                         Dim byteToRead As Byte = serialport.ReadByte()
  19.                         Buffer.Add(byteToRead)
  20.  
  21.                         If Buffer.Count < 7 Then
  22.                             '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
  23.                             receivesuccess = True
  24.  
  25.                             For iInside As Integer = 0 To 7
  26.                                 str = Hex(Buffer.Item(iInside))
  27.                                 If str.Length = 1 Then
  28.                                     str = "0" + str
  29.                                 End If
  30.                                 str1 += str + "  "
  31.                             Next
  32.                             RR.Insert(0, str1)
  33.                             'End If
  34.  
  35.                         End If
  36.                     End If
  37.                 End While
  38.  
  39.             End If
  40. End Function
  41.  

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
  1. Public Function SendMessage(ByVal NoOfData As Integer) As Integer
  2.         Try
  3.             serialport.Close()
  4.             serialport.Open()
  5.             'serialport.PortName = "COM3"
  6.  
  7.             If serialport.IsOpen Then
  8.                 serialport.Write(MassageToSend, 0, NoOfData)
  9.                 'serialport.Read(ReceivedResponse, 0, 24)
  10.                 Dim str, str1 As String
  11.  
  12.                 str = ""
  13.                 For ctr As Byte = 0 To CByte(NoOfData - 1)
  14.                     str1 = Hex(ServerComm.MassageToSend(ctr))
  15.                     If str1.Length = 1 Then
  16.                         str1 = "" + "0" + str1 + ""
  17.                     End If
  18.                     str = str + Space(7) & str1 + ""
  19.  
  20.                 Next
  21.  
  22.                 str = ">>" + str
  23.                 Threading.Thread.Sleep(100)
  24.                 'str = System.Text.Encoding.Default(str + vbCrLf)
  25.                 With SunRose.tbText
  26.                     .Font = New Font("Garamond", 12.0!, FontStyle.Regular)
  27.                     SunRose.Tx.FillColor = Color.White
  28.                     SunRose.Tx.FillColor = Color.Red
  29.                     .SelectionColor = Color.Red
  30.                     .AppendText(str & vbCrLf)
  31.                     .ScrollToCaret()
  32.  
  33.  
  34.                     Dim file As String = Application.StartupPath() + "\Backup\Excel\" + "HEXdata" + System.DateTime.Now.ToString("dd" & "MM" & "" & "yyyy") + ".csv"
  35.  
  36.                     Dim str_send = ""
  37.  
  38.                     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
  39.  
  40.                 End With
  41.                 Threading.Thread.Sleep(800)
  42. end sub
but in getmessage() as soon as debuger is executing readbyte() it is not moving and nothing is geting displayed so plz help me with code and sugestions
May 17 '12 #1
0 1594

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Alex | last post by:
Hi, I'm new at this serial port thing and I'm developing an App to receive data from the serial port, but the transmission baud rate must be of 460800 bps or higher, so my question is: is it...
4
by: Jan | last post by:
Hello can someone tell were I can find good documentation on serial port programming? TIA
3
by: Rasha | last post by:
Hi, What is the right way for transmitting data on the serial port of a PC using VB.NET (under XP) ? I used to use the ActiveX MSComm under VB6, which becomes obsolete and needs a...
2
by: wesolutki | last post by:
Hi, how to send data to other application by serial port? I want to have two programs opened on one computer, one send and second recive data, but using serial port. Wesolutki :-)
4
by: ganesah | last post by:
hi, Im working on a project where i need to send binary format data to serial port and output the exact data through parallel port? could anyone explain me how to do, what language should i use ? If...
7
by: summerch2 | last post by:
I have developed a hardware that will give data in terms of angle of rotation. The hardware is connected to PC via serial port. I can show the value through Hyperterminal. Now i'm on the way to...
5
by: Tony K | last post by:
I have a slight problem. When attempting to receive data via my serial port I sometimes do not get the complete data. For example, I have a scanner that reads barcodes. When reading barcode...
6
by: terry | last post by:
Hi, I am trying to send a character to '/dev/ttyS0' and expect the same character and upon receipt I want to send another character. I tired with Pyserial but in vain. Test Set up: 1. Send...
1
by: MaryKJolly | last post by:
How can I access data from a serial port from my VB6 program?
1
by: amrhosam | last post by:
how can i find the data form i recieve from a serial port? do i receive it in Hex? or binary? or ASCII? a simple micrcontroller as a transmitter sends me 0x8F in hex for example..how am i gonna...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.