473,563 Members | 2,904 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

serial port

2 New Member
Hello I have a project which i need to build an interface in vc++.Net to communicate with a serial port with a microcontroller .I am a little bit amateur in programming.I search the web but i haven't find sth for this in this language.Is there anyone who knows sth?I just need how to open a serial,establis h the serial,close serial,send data to serial and read from serial.
Because I have find some projects with serial in other languages if someone know how to make a project where i have the program in vc++.NET and the program for serial in another language.

Thank you...
May 11 '09 #1
5 2755
tlhintoq
3,525 Recognized Expert Specialist
Have you used the SerialPort component supplied by Visual Studio?
You can drag/drop that onto your form from the Toolbox and go from there pretty painlessly.
Properties exist for port, baud etc.
Events exist for DataReceived, ErrorReceived, PinChange
May 11 '09 #2
kwstas86
2 New Member
Yes I have done this one.But the thing that want to do is everytime i will open the interface to connect direct to the serial without pressing any button.So for this one i have to write some code as public i guess.And then when i press one button i want to send one 8bit number to the serial.From the otherside i will have maybe some textboxes to watch some values from my circuit-like temperature.
So i need some samples of code to open automatically the serial connection with the circuit and some examples for how to send and read data.
May 11 '09 #3
tlhintoq
3,525 Recognized Expert Specialist
i will open the interface to connect direct to the serial without pressing any button.
This implies that you first need to load your saved settings from someplace. That's up to you: Config file, registry, whatever.

Create a method for loading your settings. LoadSettings(); for example.
Create a method for opening your serial port. StartSerial(); for example

From the .Load event of the custom control you are making call the LoadSettings() method followed by the StartSerial() method.

Expand|Select|Wrap|Line Numbers
  1.         private void TempSensor_Load(object sender, EventArgs e)
  2.         {
  3.             LoadSettings();
  4.             StartSerial();
  5.         }
  6.  
For testing I suggest you also add a Start button that calls the same methods. This way you can start/stop it at will and not just when the control is loaded.

some examples for how to send and read data.
Before we just give you all the code... do some reading and some experimenting. If you read up on the SerialPort component (MSDN Library for example) you will see there are methods for .Read() .ReadLine() .Write() and .WriteLine()
May 11 '09 #4
prasad599
24 New Member
There is one way to do it. Use the MSComm Control i.e Microsoft Communication control. Add this component from the list of com components.
Right click the toolbox of the .NET IDE then click on Choose items.Then from com components add Microsoft Communications control.

Drag and drop the control from toolBox

The default name for the control comes as AxMscomm1

Set the port number for the control either in design view or runtime.
Then open the port using PortOpen property.
Use the 'Output' property to send the data
e.g Dim data(10) as byte

AxMscomm1.outpu t = data


Also create an event handler for the 'OnComm' event of the AxMscomm1
This event is triggered when the data is received at the serial port.

the code for the event should look like this:
Variable receivedData is declared as string.

Private Sub mscomm_OnComm(B yVal sender As Object, ByVal e As System.EventArg s) Handles AxMscomm1.OnCom m

Dim commConst As MSCommLib.OnCom mConstants

Select Case AxMscomm1.CommE vent
Case commConst.comEv Receive
receivedData = receivedData & AxMscomm1.Input
End Select
End Sub


When you send some data to the connected hardware , you can check the response in a timer , by checking the receiveddata contents.

Some of the properties of the control that needs to be changed in the design time.

Right click on the control and then click on properties then click on Buffers
Set RThreshold =1 and SThreshold =1

Well the above code is in VB.NET
May 15 '09 #5
Plater
7,872 Recognized Expert Expert
If you are using anything newer then .NET1.1 you should NOT use the mscomm dll, but instead use the SerialPort class built into .NET
May 15 '09 #6

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

Similar topics

4
9067
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...
2
13161
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...
3
5029
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
4800
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...
4
11173
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...
4
17796
by: Frank | last post by:
Hello, how to get information about all serial ports in the PC? I use the following code, but i got only the data of the FIRST serial port. All other serial port information are not available with this code sample: ManagementObjectSearcher searcher = new ManagementObjectSearcher("Select * from WIN32_SerialPort");
13
6176
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...
4
11698
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...
3
11557
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...
6
6637
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
7665
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...
0
7583
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...
0
7888
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. ...
0
8106
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...
0
7950
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...
0
6255
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...
0
5213
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...
0
3626
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
924
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...

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.