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

serial port

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,establish 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 2747
tlhintoq
3,525 Expert 2GB
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
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 Expert 2GB
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
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.output = 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(ByVal sender As Object, ByVal e As System.EventArgs) Handles AxMscomm1.OnComm

Dim commConst As MSCommLib.OnCommConstants

Select Case AxMscomm1.CommEvent
Case commConst.comEvReceive
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 Expert 4TB
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
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...
2
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. ...
3
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',...
13
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...
4
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. ...
4
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...
13
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...
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...
3
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...
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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,...

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.