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

Serial communication

i want to perform serial communication on selecting

.Net Framework2.0--->Visual Basic--->Device application

presently i am using this code

Expand|Select|Wrap|Line Numbers
  1. Imports System.IO.Ports
  2. Imports System.IO.Ports.Serialport
  3.  
  4. If Button1.Text Is "open port" then
  5.     SerialPort1.Open()
  6.     Button1.Text="close port"
  7.     Button2.Enabled=True
  8.  
  9. Else If Button1.Text Is "close port" then
  10.     SerialPort1.Close()
  11.     Button1.Text="open port"
  12.     Button2.Enabled=False
  13. End If
  14.  
  15. //Inside button2 i am writing this code
  16. SerialPort1.WriteLine(Textbox1.Text)
  17. Listbox1.Items.Add("sent:" +TextBox1.Text)
  18.  
  19. //Inside serialport's property in DataReceived,i hav written this statement
  20. ListBox1.Items.Add("Received" +Serialport1.ReadLine())
but i am getting error as

"An unhandled exception of type System.InvalidOperationException occurred in System.dll
Additional Information: The basestream is only available when the port is open "

so plz anyone help me in this issue ...

Thanking U in advance.....
expecting ur valuable results earlier.....

Regards
Indu
Aug 11 '09 #1
1 1972
tlhintoq
3,525 Expert 2GB
Additional Information: The basestream is only available when the port is open "
When you are sending the text to the port, the port is not open.
Just because you issued a command to open the port you cannot assume that it worked. Maybe there is a problem with the port. Maybe the port number you specified is not valid. Maybe some other application or the OS closed the port after you opened it. Maybe your attempt to opent he port failed because you didn't specify everything correctly that you needed to.

Coding is easy in a perfect world. Too bad we don't live in one. I have found that for every line of code there are 10 more to handle probable error conditions.

Where you open the port
Expand|Select|Wrap|Line Numbers
  1. If Button1.Text Is "open port" then
  2.     SerialPort1.Open()
  3.     Button1.Text="close port"
  4.     Button2.Enabled=True
You never check to see if it really opened. You just assume it did and activate your send button.

In your send method, do you check if the port is open before you try to shove text through it?
Aug 11 '09 #2

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

Similar topics

1
by: Andreas Horneff | last post by:
Hi @ all, I've got a problem with serial communication in Borland C++ Builder. I've already found a lot of stuff about serial communication in the internet, but it dosen't work. What I want...
11
by: sarah | last post by:
hI, I have a project. I need to realise serial communication between PC and Altera FPGA in c or c++. The function of FPGA is working well. it can send data to uart. Does anybody know how to...
3
by: carmen | last post by:
I'm working in an aplication for a Smart Device that need to "talk" with a printer continuosly through the serial port. I'm trying to use the John Hint's sample code "Use P/Invoke to develop a .NET...
4
by: Vidya Bhagwath | last post by:
Hello Experts, I am porting the C++ code into the Visual C#.NET. My C++ code is mainly based on the serial communication. So I am using the windows structure such as DCB.. etc and the windows...
6
by: Leandro Berti via DotNetMonster.com | last post by:
Hi All, I wrote a code to do serial communication with an equipament. When i use the code outside of threaded class it seens work properly, but when i put inside a class and execute a thread in...
4
by: joe bloggs | last post by:
I am writing a mobile application to interface with a legacy system and I am planning to use web services to communicate with this system. The legacy system receives data through a serial port. ...
2
by: Marco Trapanese | last post by:
Hi, every 250 ms (timer event) I must send several commands via serial port. The serial unit will answer to each command sent. I must wait the answer before send the next command. How can I...
4
by: max_mont | last post by:
Hi all, I'm a newbie in .NET technology. I've already developed Serial communication applications in C++ (WIN32). And I wanted to migrate to .NET technology. There is a serial component in...
2
by: Adrian Chen | last post by:
please help me! I come across a problem. Now I develop a finger print management system which is based on B/S.When users click a button in the web pages, a device connected to the COM1 serial port...
0
by: Dhananjay | last post by:
Hi, I am working on an VB.Net application which I want to communicate to external device using comm port (Serial Port) . So for that first I am trying to simulate the communication on serial...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...

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.