473,287 Members | 1,868 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,287 software developers and data experts.

How to send data Serially through COM port

108 100+
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 1905
Shashi Sadasivan
1,435 Expert 1GB
Hi,
I have never tried this, BUt got some good looking links
link1 link2

hope it helps
Nov 22 '07 #2
romcab
108 100+
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 Expert 1GB
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
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
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
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
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
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
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
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
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
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...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...

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.