473,856 Members | 1,779 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Simple serial port

ORC
Hi,

I'm looking for a way to implement a simple functionality in my serial port
C# wrapper. I'm making a program that must run on both a Pocket PC and a
"normal" PC. The application is quite simple:
A calling thread is blocked untill Readfile returns with "bytesToRea d"
numbers of bytes or untill "TotalTimeo ut" specified in the "COMMTIMEOU T"
struct has been exceeded. Another thread must be able to write to the same
serial port while the first thread is waiting in the readfile function. This
all works very well on the Pocket PC! But on the desktop PC the writefile is
prevented to be executed until the readfile has finished. I have tried
setting the Overlapped to true in createfile and applied both readfile and
writefile with an overlapped struct - This makes however the readfile return
immediately no matter if any characters are received and whatever is
specified in the COMMTIMEOUT structure. The COMMTIMEOUT struct is specified
as this:
CommPort.ReadIn tervalTimeout = 5000;
CommPort.ReadTo talTimeoutMulti plier = 0;
CommPort.ReadTo talTimeoutConst ant = 5000;
CommPort.WriteT otalTimeoutMult iplier = 0;
CommPort.WriteT otalTimeoutCons tant = 1000;

Does anyone knows a proper way to handle this??? Any help is highly
appreciated!

I don't use WaitCommEvents and all that stuff and would prefer not to (it
shouldn't be neccesary as the application is quite simple). I have had a
look at the Serial Class from OpenNetCF but it is far to heavy for my
application.

Thanks
Ole
Nov 16 '05 #1
1 4914
I do that in my app and it works fine. I write in one thread while reading
from another. I can't be sure that the write is not being blocked by the
read since my read thread can be very busy, but I have not coded it to be
exclusive, nor have I seen any issues leading me to think it is.

You probably already know this but the commtimeouts only work if you receive
at least one byte from the read. The timeout is a count between read bytes
and does not start until the first byte arrives. Otherwise it blocks
forever.

jim

"ORC" <or*@sol.dk> wrote in message
news:eP******** ******@TK2MSFTN GP11.phx.gbl...
Hi,

I'm looking for a way to implement a simple functionality in my serial
port
C# wrapper. I'm making a program that must run on both a Pocket PC and a
"normal" PC. The application is quite simple:
A calling thread is blocked untill Readfile returns with "bytesToRea d"
numbers of bytes or untill "TotalTimeo ut" specified in the "COMMTIMEOU T"
struct has been exceeded. Another thread must be able to write to the same
serial port while the first thread is waiting in the readfile function.
This
all works very well on the Pocket PC! But on the desktop PC the writefile
is
prevented to be executed until the readfile has finished. I have tried
setting the Overlapped to true in createfile and applied both readfile and
writefile with an overlapped struct - This makes however the readfile
return
immediately no matter if any characters are received and whatever is
specified in the COMMTIMEOUT structure. The COMMTIMEOUT struct is
specified
as this:
CommPort.ReadIn tervalTimeout = 5000;
CommPort.ReadTo talTimeoutMulti plier = 0;
CommPort.ReadTo talTimeoutConst ant = 5000;
CommPort.WriteT otalTimeoutMult iplier = 0;
CommPort.WriteT otalTimeoutCons tant = 1000;

Does anyone knows a proper way to handle this??? Any help is highly
appreciated!

I don't use WaitCommEvents and all that stuff and would prefer not to (it
shouldn't be neccesary as the application is quite simple). I have had a
look at the Serial Class from OpenNetCF but it is far to heavy for my
application.

Thanks
Ole

Nov 16 '05 #2

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

Similar topics

4
9097
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...
38
3558
by: jrlen balane | last post by:
basically what the code does is transmit data to a hardware and then receive data that the hardware will transmit. import serial import string import time from struct import * ser = serial.Serial()
2
13208
by: willie | last post by:
Hi, I'm writing a program which requires the use of three serial ports and one parallel port. My application has a scanning devices on each port, which I can access fine with pyserial. However, I'm unsure of how exactly I should be designing the program, I thought I could use threading to start class: class scanner(Thread): def __init__(self,port):
3
5060
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', '\0', '\1', 'Z', '0', '0',
13
4841
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...
4
11214
by: joe bloggs | last post by:
I am writing a mobile application to interface with a legacy system and I am planning to use web services to communicate with this system. The legacy system receives data through a serial port. What I would like to do is make the serial port accessible via a web service. The web service and the legacy application would be running on the same machine. The mobile application would access the web service via a network connection. It...
13
6222
by: Rob | last post by:
Hi all, I am fairly new to python, but not programming and embedded. I am having an issue which I believe is related to the hardware, triggered by the software read I am doing in pySerial. I am sending a short message to a group of embedded boxes daisy chained via the serial port. When I send a 'global' message, all the connected units should reply with their Id and Ack in this format '0 Ack' To be certain that I didn't miss a...
3
11676
by: naveen.sabapathy | last post by:
Hi, I am trying to use virtual serial ports to develop/test my serial communication program. Running in to trouble... I am using com0com to create the virtual ports. The virtual ports seem to be working fine when I test it with Hyperterminal . I am using the example program that comes with pyserial, as below. --------------- import serial
6
6677
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.
0
9906
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
11051
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...
0
10694
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
10379
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
9528
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...
1
7929
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7088
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
5956
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4171
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.