473,386 Members | 1,712 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.

C# - Serial Handshaking Problem

I have rewritten a faulty serial app that my company uses at several sites. In most cases, it works fine. At one site, it does not work. I know for certain the following:

Port=COM1, Rate=9600bps, Framing=8+N+1, and Control Flow is either none or XON/XOFF.

I am using a .NET SerialPort object to manage the port. To open the port, I do the following:

serialPort.PortName = port;
serialPort.BaudRate = transmissionRate;
serialPort.DataBits = framingDataBits;
serialPort.Parity = framingParity;
serialPort.StopBits = framingStopBits;
serialPort.Handshake = handshake;

serialPort.Open();

At this one site, the old program opens the port correctly. It uses the following statement:

phandle = CreateFile(port, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL);

However, with my program, the host on the other end complains that there is nothing on the other end to talk to. If I run PuTTY and connect to the same port as my program would, using 9600, 8+N+1, XON/XOFF, the host stops complaining.

Any ideas?

TIA,
Bob
Jul 29 '08 #1
7 18723
Plater
7,872 Expert 4TB
With XON/XOFF you might need to send XON at the start to let the other program know you are up and running.
You are sure it doesn't try to use hardware flow control?
Jul 29 '08 #2
...you might need to send XON at the start
Although on the surface that doesn't make sense to me, it's exactly what I was thinking. I'm going to try that next.

You are sure it doesn't try to use hardware flow control?
Just considering the hardware, that would seem to make sense, however I dismissed that when I was able to get the device to... "come to life" when I connected to it via PuTTY using only XON/XOFF.
Jul 29 '08 #3
Plater
7,872 Expert 4TB
Although on the surface that doesn't make sense to me, it's exactly what I was thinking. I'm going to try that next.
Well if you think of it like the device got an XOFF from something and is sitting there waiting for an XON before it will talk, simply connecting to it won't do it.

I might actually suggest that your program send an XOFF as the very first thing, then send an XON when you are ready for data. Although I suppose it depends on who is considered the "master" for that to work.
Jul 29 '08 #4
...send an XOFF as the very first thing, then send an XON
Exactly what I was thinking. Adding to the fun, the agency in question is halfway across the country. My contact will be in tomorrow morning, I'll try it then and post my results. Thanks again!
Jul 29 '08 #5
Starting with XON did not work, nor did XOFF then XON.

The intriguing part is that If I PuTTY to COM1, which is where the external device is connecting, said external device sees PuTTY connecting and is happy. Similarly, if the old application connects to COM1, the external device is once again, happy. It's my program that uses the Microsoft SerialPort object's Open() method that is somehow failing to put the port into an appropriate state. I'll be online with the client again today. I'm adding the two lines at the bottom of this snippet:

serialPort.Open();
if ( handshake == Handshake.XOnXOff )
{
Reply( DC3 );
Reply( DC1 );
}

serialPort.DtrEnable = true;
serialPort.RtsEnable = true;
Jul 31 '08 #6
Adding the lines:

serialPort.DtrEnable = true;
serialPort.RtsEnable = true;

resolved the issue for the installation in question.
Jul 31 '08 #7
Plater
7,872 Expert 4TB
Adding the lines:

serialPort.DtrEnable = true;
serialPort.RtsEnable = true;

resolved the issue for the installation in question.
That is hardware flow control. Very strange.
Jul 31 '08 #8

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

Similar topics

2
by: Sonoman | last post by:
Hello everyone: I am new to Visual Basic and I have a problem that I cannot put my finger on. I am working on a school project and I am getting some serial data from a microprocessor. I have...
2
by: bray_stenovations | last post by:
Hello, I am experiencing some strange problems while using a usb to serial adapter vs. a real comm port. The problems started with getting a blue screen at random times. Changing usb to serial...
3
by: Michael Chong | last post by:
I wrote a program that communicate with SerialComm. In every 300 milliseconds, my program continuously send & receive data via the serial port once the program starts. My program is once in a...
0
by: Michael Chong | last post by:
I am not very good in C++ problem and this is my codes below. I do not know whether I got handshaking involve in my code. Could you guys let me know? HANDLE OpenComm(char *lpszPort, int nBaud,...
4
by: Lonifasiko | last post by:
Hi, I've been able to communicate using HyperTerminal with my device via serial port COM1. I just send a command and device switches on. I just need that to start playing with it. This way, I...
0
by: alnsaisrinivas | last post by:
Hi I've a problem with I/O blocking on my serial port at this particular scenario... 1.I've developed a driver to communicate with some device using Serial Comm (overlapped I/O). 2.I'm able to...
9
by: gene.james | last post by:
One of those cases where the problem is probably right under my nose but I can't see it. This serial test code fails to send the right data: Private Sub Button3_Click(ByVal sender As...
2
by: Mihai Popescu | last post by:
I wrote a simple application in MFC that uses MSComm ActiveX Control for serial communication. This app works just fine but I have to port it to Pocket PC. So, I wrote another simple application in...
6
by: Steve Mowbray | last post by:
Hi I am using SerialPort component to send raw binary files to a remote device with RTS/CTS handshaking - the remote device has a small receive buffer and is slow so needs to be hardware flow...
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: 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: 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
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,...
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...
0
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,...
0
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...

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.