473,732 Members | 2,190 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 3978
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::Co nnect(BYTE portnum)
{
CString Port;
int CaseCounter = 0;
DCB dcb;
WORD result = E_OK;
BOOL Finished = false;

if (m_hComport != INVALID_HANDLE_ VALUE)
{
DoShowError(E_P ORTOPEN, false);
return;
}

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

while ((result == E_OK)&&(Finishe d == 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.ReadInterval Timeout = -1; // 2 sec between 2 bytes signifys time
out
ct.ReadTotalTim eoutConstant = 1000;
ct.ReadTotalTim eoutMultiplier = 0;
ct.WriteTotalTi meoutConstant = 1000;
ct.WriteTotalTi meoutMultiplier = 0;

if (!SetCommTimeou ts(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_ENA BLE;// Set DTR high
dcb.fOutX = false;//x on/off flow control not used
dcb.fInX = false;// x on/off flow control not used
dcb.fOutxDsrFlo w = false;// NO DSR

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

break;
}// case 3

case 4:
{
// Set buffer sizes
if (SetupComm(m_hC omport, 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(res ult, true);
}

}
Nov 16 '05 #2

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

Similar topics

3
16539
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 http://www.php.net/function.fopen I was able to find sample code using Serproxy and directly opening the serial port. My application requires the use of multiple serial ports on other computers so I'm left with only Serproxy. The code I am using is"
3
17006
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=> alter table tickets add column rid serial; NOTICE: ALTER TABLE will create implicit sequence "tickets_rid_seq" for SERIAL column "tickets.rid" ERROR: adding columns with defaults is not implemented
3
3291
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
10919
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 errors 2) My Nokia 6600 prompted me the message "Accept Connection request from DEMON?" note: DEMON is my computers name. 3) Using my Nokia 6600, I hit the button that refers to the "Yes"
38
9659
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 quite a bit over the web and could not find anything useful. I don't want to use Visual C++ or Cygwin, linux, etc. If any of you guys have some little tid bit of code that would be great to look at.
4
11785
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 you open a serial port. This is not what I want to do. I need to change the timeout each time I do a "read" on the serial port, depending on which part of the protocol I've got to. Sometimes a return character is expected within half a second,...
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,
6
6666
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 '%' to serial port and make sure it reached the serial port. 2. Once confirmed, send another character.
4
4772
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 when the program hangs. The obvious answer is not to pull the lead out, but unfortunately the application is one in which there is a high possibility the lead will be pulled out so the code needs to be more robust. The form has a timer...
0
8946
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
8774
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
9307
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8186
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
6031
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
4550
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4809
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3261
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2180
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.