473,499 Members | 1,562 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to send data Serially through COM port

108 New Member
Hi guys,

Just want to ask how can I send data serially? I have here a sample code but I use sockets and tcpclient class but I'm wondering how to do it using serial cable.Any idea?

Expand|Select|Wrap|Line Numbers
  1. Private Sub SendData(ByVal IpAdd As String, ByVal sData As String)
  2.  
  3.         Dim myIpAdd As System.Net.IPAddress
  4.         Dim myPort As Integer = 4003
  5.  
  6.         'Convert data String to Byte()
  7.         Dim pBytes() As Byte = Encoding.Default.GetBytes(sData)
  8.         'Debug:
  9.         'Dim pBytes() As Byte = Encoding.ASCII.GetBytes(sData)
  10.  
  11.         'create a socket
  12.         Dim isocket As Socket
  13.         isocket = New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)
  14.  
  15.         'convert string ip to IPAddress 
  16.         myIpAdd = IPAddress.Parse(IpAdd)
  17.  
  18.         'Debug:
  19.         'Dim temp As String = myIpAdd.ToString()
  20.         'Dim ret = IPAddress.TryParse(IpAdd, temp)
  21.  
  22.         'connect to remote host
  23.         Try
  24.             isocket.Connect(myIpAdd, myPort)
  25.             If isocket.Connected() Then
  26.  
  27.                 'Send Data
  28.                 isocket.Send(pBytes)
  29.  
  30.                 'Debug
  31.                 'MsgBox("Sent... ")
  32.  
  33.                 'close connection
  34.                 isocket.Close()
  35.  
  36.             End If
  37.  
  38.         Catch se As SocketException
  39.             MsgBox("Socket Exception")
  40.  
  41.         Catch ex As Exception
  42.             MsgBox("UnExpected exception")
  43.  
  44.         End Try
  45.  
  46.     End Sub
Thanks
Nov 22 '07 #1
3 1915
Shashi Sadasivan
1,435 Recognized Expert Top Contributor
Hi,
I have never tried this, BUt got some good looking links
link1 link2

hope it helps
Nov 22 '07 #2
romcab
108 New Member
Hi,
I have never tried this, BUt got some good looking links
link1 link2

hope it helps

thanks for this link...Anyway, did you experience sending data using sockets and tthe data is distorted? I just saw it today when I delete MsgBox which inform me that data is sent/failed. I think I need to add delay before sending the next one? Do you know the how to add delay or sleep in .net?
Nov 22 '07 #3
Shashi Sadasivan
1,435 Recognized Expert Top Contributor
thanks for this link...Anyway, did you experience sending data using sockets and tthe data is distorted? I just saw it today when I delete MsgBox which inform me that data is sent/failed. I think I need to add delay before sending the next one? Do you know the how to add delay or sleep in .net?
Thread.Sleep(time) will put the current operation to sleep
Nov 22 '07 #4

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

Similar topics

6
5631
by: Quarco | last post by:
Hi, Quick & simple question: I have to send the next data to a socket in order to make a popup visible on a windows machine.. TITLE Title of popup TEXT Text in popup POPUP
4
9627
by: Anne | last post by:
hi ng I would like to make a database where the user automatically can send a short message service (SMS) just by pressing a button. I know how to do it if it is an email (by using the...
0
2998
by: Gregory Hassett | last post by:
Hello, I want to periodically send a TCP packet to a peer, always from the same source port. That is, each packet will come from my local ip address, port 8801, and go to the peer's ip address,...
14
11857
by: eliss.carmine | last post by:
I'm using TCP/IP to send a Bitmap object over Sockets. This is my first time using C# at all so I don't know if this is the "right" way to do it. I've already found out several times the way I was...
3
10265
by: Jason | last post by:
Hello I've got some test code that I've found on the web that is a TCP server and a TCP client. The server sends data to the client on the port i specify. I know because get the port number...
1
2722
by: danfolkes | last post by:
Hey Everyone, I am trying to send repeated messages from a "Node" to a "Server". It works the first time I send the from the Node to Server, but after that it either errors, or does not do...
3
1730
by: danfolkes | last post by:
Why does the message send only once? The node sends once, then fails after that. <code> import socket import thread import time def Node(nodeAddress):
7
22837
by: Rob Dob | last post by:
The following code is giving me a timeout problem., no matter what I do I can't send a piece of mail using .net2.0 System.Net.Mail.SmtpClient via port 465 and using ssl, if however I try using...
0
5085
by: Xionbox | last post by:
Hello everybody, The error I have seems very easy to solve, but for some odd reason I can't seem to solve it. Anyways, here's my "setup". I created a server running on localhost:1200 (telnet...
0
7130
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
7007
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7171
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6893
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...
0
4599
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3098
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3090
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1427
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
295
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.