473,722 Members | 2,430 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Writing serial port does not work

Currently I am writing a program which sends and receives messages
through serial port to a device. I am using C# and Microsoft Visual
studio 2005 for windows program. But my problem is when i try to write
in serial port from my windows a Timeoutexceptio n is thrown. I use
SerialPort class in System.IO.Ports and for writing port i used
write() function under the built in class SerialPort. But when i use
hyperterminal , everything goes fine.

Can anyone say how can i overcome this problem?

Another thing , I have used SerialPort.GetP ortNames() to get the list
of serial ports. But sometimes the list of serial ports that is
returned by this method is not same as the list of serial ports shown
in device manager.(Curren tly SerialPort.GetP ortNames() return COM1
and COM3 but no existence of COM3 in device manager) Which method can
i use to get the actual list of serial ports?

Thanks in advance
Nasif Bin Shafi

Nov 11 '07 #1
2 7844
I don't understand the whole situation, but remember that if your computer
has an internal modem, that occupies one of the serial ports. You may be
using the wrong serial port.

The other thing to be aware of is the connection of CTS, DSR, etc. (the
various "ready" signals). Either loop them back properly or tell the
software to ignore them.
Nov 11 '07 #2
On Sun, 11 Nov 2007 12:38:07 -0000, Nasif <na*******@gmai l.comwrote:
>Currently I am writing a program which sends and receives messages
through serial port to a device. I am using C# and Microsoft Visual
studio 2005 for windows program. But my problem is when i try to write
in serial port from my windows a Timeoutexceptio n is thrown. I use
SerialPort class in System.IO.Ports and for writing port i used
write() function under the built in class SerialPort. But when i use
hypertermina l , everything goes fine.

Can anyone say how can i overcome this problem?

Another thing , I have used SerialPort.GetP ortNames() to get the list
of serial ports. But sometimes the list of serial ports that is
returned by this method is not same as the list of serial ports shown
in device manager.(Curren tly SerialPort.GetP ortNames() return COM1
and COM3 but no existence of COM3 in device manager) Which method can
i use to get the actual list of serial ports?

Thanks in advance
Nasif Bin Shafi
Hi Nasif,
You 100% sure you are opening the port correctly before trying the
write?
i.e.
The following works for me, admittedly the com port is not connected
to anything.
private void button1_Click(o bject sender, EventArgs e)
{
SerialPort s = new SerialPort("Com 1", 9600, Parity.None,
7, StopBits.One);
s.Open();
s.Write("HelloW orld");
s.Close();
s.Dispose();
}
Nov 12 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
9094
by: ^CeFoS^ | last post by:
Hello to everybody, I've done an application that draws in a frame the trajectory of a robot. The robot position is readed through the serial port, and several commands are wrote through the same port to change the direction of the robot. The trajectory frame is managed by an applet, and the project works good when the applet is called by a html document allocated in the same local machine under W98 where the classes and the serial port...
14
4056
by: McBooCzech | last post by:
Hi I am just trying to analyze (parse) data from the serial port (I have connected GPS receiver to the ttyS0, so I can read ASCII characters in the CSV form on the serial port 1). I am doing this just to understand how Python works (yes, you can call me Python/Linux newbie :) My environment is Fedora Core 4, Python 2.4.1 CSV alone (to read CSV data from the file) and py-serial alone (to read data from the serial port) are working...
21
2984
by: The Man With The Harmonica | last post by:
Hi All, What kind of commands can I use to control the serial and parallel port of my pc. I want to use my laptop instead of microcontrollers and write my software in ANSI C to be used for control purposes of sensors and other electronic devices. I haven't done any C for a while now so I would assume my knowledge is that of a beginner now.
13
4831
by: Al the programmer | last post by:
I need to access the serial ports on my webserver from an asp.net page. I have no problem accessing the serial ports from a windows form application, but the code doesn't work in asp.net. I have been told it is not possible to access the serial ports from asp.net. The application is used to control custom hardware. The hardware is connected to a PC through serial ports. Our customer wants to control the hardware from a remote...
13
6858
by: jay.dow | last post by:
I want to write to the pins of an RS232 without using the serial protocol. The use would be every pin could act to complete a circuit in customized hardware. I could use python to communicate serially to a BASIC stamp or a Javelin stamp and then use the stamp to set however many pins as 0's or 1's but should it be that hard to do with python. I've looked through how python does serial with the "serial" module but it just uses Java's...
5
2335
by: Franklin M. Gauer III | last post by:
Hi All, I've written an ASP.NET application (webservice) that does simple serial communications via the .NET 2.0 SerialComm object. The application runs fine on my development machine. The problem is when we try to deploy it to another machine we receive: ACCESS IS DENIED TO COM1 PORT. We have tried unsuccessfully to get this to work. We have tried the following: 1) Assign the IUSR.... account to Administrators
7
5392
by: davetelling | last post by:
I'm a newbie that is still struggling with OOP concepts & how to make things work they way I want. Using Visual C# Express, I have a form in which I added a user control to display a graph, based upon data received via the serial port. If I run the serial port in the main form code, I can get data and, using public properties of the user control, transfer the data to be shown on the graph. However, I am trying to add a feature that will...
4
2662
by: Petr Jakes | last post by:
I am trying to save data it is comming from the serial port continually for some period. (expect reading from serial port is 100% not a problem) Following is an example of the code I am trying to write. It works, but it produce an empty gz file (0kB size) even I am sure I am getting data from the serial port. It looks like g.close() does not close the gz file. I was reading in the doc: Calling a GzipFile object's close() method does...
2
5430
by: colin | last post by:
Hi, Im having a tiresome amount of trouble with using a bluetooth serial link. The receiving end is a bluetooth-rs232 module conected to my embeded system. The PC has a little usb bluetooth dongle, ive tried a another dongle with widicom software as I was having problems with the IVT bluesoleil software. that seems to have got rid of some other problems,
0
8863
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8739
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9384
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9157
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
9088
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8052
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5995
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4762
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2602
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.