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

Read/ write string to com port

Hi friends,

I have written code in asp.net to read or write string in com port(COM1).But when i run the program i am not getting any output .Below is my code .How can i check the string which i have send in com port is available in com port for read.

private SerialPort port = new SerialPort("COM1", 9600, Parity.None, 8, StopBits.One);
port.Open();



// port.Write("He");

port.Close();
port.Open();
port.ReadTo("e");
Console.WriteLine(port.ReadLine());


please reply as soon as possible.........................Thanx in advance for reply...
Oct 16 '08 #1
14 3042
joedeene
583 512MB
Is it possible to have a serialdatareceived args, with the handles in asp.net? If so, try that, maybe its not receiving it yet. You can always look up examples on google.


ex of the data received handler:

Expand|Select|Wrap|Line Numbers
  1. Private Sub port_DataReceived(ByVal sender As Object, ByVal e As _
  2.        System.IO.Ports.SerialDataReceivedEventArgs) Handles port.DataReceived
  3.  
  4.        End If
  5.     End Sub
joedeene
Oct 16 '08 #2
Plater
7,872 Expert 4TB
How do you know it is not working?
You know that code will be run on the server's COM port and not on the computer viewing the webpage right?
Oct 16 '08 #3
because after port.write statement i have written

Console.WriteLine(port.ReadExisting()); and in my console window m nog getting any out put;

2)even if i used
port.DataReceived += new SerialDataReceivedEventHandler(port_DataReceived);


private void port_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
// Show all the incoming data in the port's buffer
Console.WriteLine(port.ReadExisting());
}
this handle does not fire;


Thanx for reply .if you can provide more solution i am waiting to ur suggestion.
Oct 16 '08 #4
Plater
7,872 Expert 4TB
In your example code you call a Close() and then an Open(), why? The data could come in durring that time and you would never see it?
Are you making sure there is no flowcontrol enabled for the port (or enabled if you need to use it)
Oct 16 '08 #5
Because first open port and i am writing the string to send to port like
port.write("string")

after writing string i am closing port as suggested somewhere in google.

then i am opening the port and reading the data.

actually i followed this link here is code for that:
http://msmvps.com/blogs/coad/archive.../23/39466.aspx
Oct 16 '08 #6
Plater
7,872 Expert 4TB
Well that is a bad practice, and nowhere in the article's sample code did I see where it said to close and then open.
You should close the object when you are done with it, if it is not open, how do you expect to receive data?
Oct 16 '08 #7
Can u give me any solution???which is good
Oct 16 '08 #8
Plater
7,872 Expert 4TB
Well for testing purposes, try this:
Expand|Select|Wrap|Line Numbers
  1. private SerialPort port = new SerialPort("COM1", 9600, Parity.None, 8, StopBits.One);
  2.  
  3. port.Open();
  4. port.Write("He");
  5. string firstread=port.ReadTo("e");
  6. System.Threading.Thread.Sleep(100);//pause for 1/10 a second
  7. Console.WriteLine(port.ReadLine());
  8. port.Close();
  9.  
Oct 16 '08 #9
Hi,
I did same as u send but still in console window i am not able to see any thing.
is there any other thing,that i need to set in computer
Oct 16 '08 #10
Plater
7,872 Expert 4TB
What is attached on the COM port of the server computer? Are you using the corrrect baud rate? Are you using the correct COM port?

I am confused, your original post says you are doing this in ASP.NET, but you say you are in a console window?
Oct 16 '08 #11
What is attached on the COM port of the server computer? Are you using the corrrect baud rate? Are you using the correct COM port?

I am confused, your original post says you are doing this in ASP.NET, but you say you are in a console window?


yes i am doing in console application .
Oct 17 '08 #12
It is in Asp.net Console application.
Oct 17 '08 #13
joedeene
583 512MB
It is in Asp.net Console application.
An Asp.Net Console Application?! I've never heard of such, even googled it and nothing comes up relevant, how did you come about creating such, like what is some code from your asp.net console app? because it could just be a console app. Can you see it in your browser? Or just in a black standard console window...?

joedeene
Oct 17 '08 #14
Curtis Rutland
3,256 Expert 2GB
It is in Asp.net Console application.

ASP.NET is for website programming. ASP stands for Active Server Pages. I think you might mean .NET Console Application.

ASP.NET Console makes no sense.
Oct 17 '08 #15

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

Similar topics

8
by: collinm | last post by:
hi we use linux and c language under bash i do echo -e \\000\\000\\000\\000\000\\001Z00\\002AA LINUX \\004 >/dev/ttyS2 that send command to a led display (alpha sign communication)
3
by: collinm | last post by:
hi i send a command to a led display, the led display is suppose to return me some character i write a string on a serial port void ledDisplayExist() { char msg={'\0', '\0', '\0', '\0',...
4
by: Dakkar | last post by:
I write a program for connecting to mysql database and read the values that i want from the database so i wrote my code like this RegistryKey uo =...
1
by: vkrasner | last post by:
It works with VS2003 and does not in VS2005: in VS2003 : string sMyvalue = ConfigurationSettings.AppSettings; in VS2005 (does not work!!) string sMyvalue = ConfigurationManager.AppSettings; ...
5
by: Jens | last post by:
Hello, I have been looking for some C-code which listens on a user-defined port for incoming data traffic. When data is received, the data is written to a file. I found some C-code (server)...
0
by: daikeechi | last post by:
hello guys .. i want to perform pc to pc chatting via null modem cable.. i managed to write and sent data to serial port but how to write loops to read data from serial port ? i'm using visual c++...
4
by: rowan | last post by:
I'm writing a driver in Python for an old fashioned piece of serial equipment. Currently I'm using the USPP serial module. From what I can see all the serial modules seem to set the timeout when...
0
by: darkking | last post by:
Ok, I'm trying to read data from the serial port. Problem is, that i always have to query the port for new data, and in 99.9% of acses my query doesn't return the result cause of the fact it's...
3
by: madsornomads | last post by:
Hi all, I have a problem with reading from a Java server after I have written to it - it just hangs. It works fine if I just write to the server and not try to write. I have read the HOWTO on...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
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: 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?
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...

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.