473,563 Members | 2,762 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 1933
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(ti me) 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
5636
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
9634
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 docmd.sendobject method) - but what code do I need to send a SMS Thanks in advance Anne
0
3011
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, to HIS port 8801. This means that I need to bind my sender socket to (myaddress,8801), use it for the send, then shut it down and close it. Then...
14
11875
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 doing something was really inefficient and could reduce 10 lines of code with 2, etc. For reading, I am using a TcpClient and I call ...
3
10273
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 through an IPEndPoint. However when I send the data back to the server, the server receives it on a different port number then what I specify, and I...
1
2727
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 anything. I would love some help, here is the code: import socket import thread import time
3
1736
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
22853
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 outlook or outlook express it works fine.. System.Net.Mail.MailMessage msgMail = new System.Net.Mail.MailMessage("myemail@mydomain.com",...
0
5093
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 localhost 1200 proves that it is up and running) and I coded a client which is supposed to connect to that server and send it data. The odd part is...
0
7885
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8106
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7638
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7948
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5484
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5213
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
2082
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 we have to send another system
1
1198
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
923
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.