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

C# serial connection problems

I've written an app in C# in the compact framework. I've got a serial connection with a device running embedded C. We are using no flow control. That's not optional at this point. We are talking at 19200 baud, 8 bits, no parity, one stop bit. I can't get stable communication into my side.

Symptoms: If we put interrupts in the embedded C (also not an option), I get my data just fine. However, without the interrupts, I only get the first byte.

I have a tester that sends the data as I key it in, and I receive all of the data. However, if I user Hyper Terminal, sending all of the data from a file, I only get one byte. Here's the strange thing: If I close my form and reopen it, while continuing to send data via Hyper Terminal each time I open it, I move up a character in the line of data each time. My form is called from a main form, which I don't close each time; but I initialize my buffer from the constructor of the form. I also call dispose each time I close the form.

Questions:
1. It seems that my event handler is just not fast enough to recover and get the next byte. Is there anything that I can do to speed things up?
2. Is there a way to access the hardware buffer where the data is being stored during the transfer?

Thanks in advance for any insights.

--
Message posted via http://www.dotnetmonster.com
Nov 16 '05 #1
1 3959
The following was written by me in visual c++ for use on a windows CE device
talking to a pc. I had to use flow control on wired comms or it wouldn't
work. Flow control turned off for use with our CE device's IR connection.
Sorry, I know you're using compact framework but I assume you're utilising
some object that allows you to set up SetCommState values.
Maybe it will help.

void CJFMComport::Connect(BYTE portnum)
{
CString Port;
int CaseCounter = 0;
DCB dcb;
WORD result = E_OK;
BOOL Finished = false;

if (m_hComport != INVALID_HANDLE_VALUE)
{
DoShowError(E_PORTOPEN, false);
return;
}

// Create the port string
Port.Format(_T("COM%d:"),portnum);

while ((result == E_OK)&&(Finished == false))
{
switch (CaseCounter)
{

case 0:
{
// Open port
m_hComport = CreateFile(Port,
GENERIC_READ | GENERIC_WRITE,
0,
NULL,
OPEN_EXISTING,
0,
NULL);
if (m_hComport == INVALID_HANDLE_VALUE)
result = E_UNOPPORT;

break;
}// case 0

case 1:
{

// Set timeouts
COMMTIMEOUTS ct;
ct.ReadIntervalTimeout = -1; // 2 sec between 2 bytes signifys time
out
ct.ReadTotalTimeoutConstant = 1000;
ct.ReadTotalTimeoutMultiplier = 0;
ct.WriteTotalTimeoutConstant = 1000;
ct.WriteTotalTimeoutMultiplier = 0;

if (!SetCommTimeouts(m_hComport, &ct))
result = E_UNTIMEOUT;

break;

}//case 1

case 2:
{
// Read current communication parameters
dcb.DCBlength = sizeof(DCB);
if (!GetCommState(m_hComport, &dcb))
result = E_UNDCB;

break;
}// case 2

case 3:
{
// on the DI we only have the CTS, RTS, TX and RX pins available
// so disable other pins and types of flow control
// and enable RTS/CTS flow control.
dcb.DCBlength = sizeof(DCB);
dcb.BaudRate = ((CCollectorApp*)(AfxGetApp()))->nBaudRate;
dcb.fBinary = true;
dcb.fParity = false;
dcb.ByteSize = 8;
dcb.Parity = NOPARITY;
dcb.StopBits = ONESTOPBIT;
dcb.fDtrControl = DTR_CONTROL_ENABLE;// Set DTR high
dcb.fOutX = false;//x on/off flow control not used
dcb.fInX = false;// x on/off flow control not used
dcb.fOutxDsrFlow = false;// NO DSR

// If this is wired RS232 then use CTS handshaking
if (portnum != 5)
{
dcb.fOutxCtsFlow = true;// CTS/RTS flow control used
dcb.fRtsControl = RTS_CONTROL_HANDSHAKE; // CTS/RTS flow
control used
}
else
{
// IR(flow control is turned off)
dcb.fOutxCtsFlow = false;
dcb.fRtsControl = RTS_CONTROL_ENABLE; // Keep RTS high
}
if (!SetCommState(m_hComport, &dcb))
result = E_UNDCB;

break;
}// case 3

case 4:
{
// Set buffer sizes
if (SetupComm(m_hComport, TEMPBUFFSIZE * 2, TEMPBUFFSIZE * 2) ==
false)
result = E_UNBUFFSIZE;

break;
}

default:
Finished = true;
}//switch (CaseCounter)

// increment the counter
CaseCounter++;

}//while (CaseCounter < 100)

if (result != E_OK)
{
Disconnect();
DoShowError(result, true);
}

}
Nov 16 '05 #2

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

Similar topics

3
by: Blaine HIlton | last post by:
I'm trying to send data over the serial port using PHP and Serproxy. I downloaded Serproxy from http://www.lspace.nildram.co.uk/freeware.html. From the manual page at...
3
by: Claudio Lapidus | last post by:
Hello Now perhaps this is a bit dumb, but... I just populated a new table via \copy. After that, I realize that perhaps is a good thing to have a row identifier in it, so I try clapidus=>...
3
by: Essam | last post by:
Hi All I have two programs ; both of them I need to give read/write access to the same Comm Port. How can I do so; using Code or third party tool/library
1
by: henrycortezwu | last post by:
Hi All, I'm trying to connect to a virtual port (COM19, OUTGOING, "Bluetooth Serial Port") using VS2005 System.IO.Ports. When I ran the ff code below here's what happens. 1) VS2005 Compiles w/o...
38
by: shussai2 | last post by:
Hi, I am trying to access Serial Port in XP. I am using Dev-C++ IDE that uses Mingw as a compiler. I just want to know how I can open up serial port on COM1 and write some data. I have searched...
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...
2
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...
6
by: terry | last post by:
Hi, I am trying to send a character to '/dev/ttyS0' and expect the same character and upon receipt I want to send another character. I tired with Pyserial but in vain. Test Set up: 1. Send...
4
by: JDS | last post by:
I have an application that interfaces with a USB device using the .Net serial port. The code works fine, displaying live data on the screen; that is until the USB lead is pulled out from the PC...
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
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...
0
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...
0
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,...
0
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...

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.