0

I m new to the visual studio I want to trnsfer and receive some data from LPC2148 kit for thisI want to do the serial communication in Visual studio.

I have used dos.h in turboC Bios.h is also used for the same purpose but those are for Turbo.C compiler

In visual studio I have found a header files Windows in api are writen but I don't know how to use it please help

Saurabh
  • 1
  • 1
  • 1

2 Answers2

0

There are many articles in CodeProject with libraries for handling Serial Communication. You can start from here and here.

May I also suggest that it will be easier to use C# for this task. You will be able to build the GUI faster and a serial port control is already provided (no need to fight with the API or find a library).

kgiannakakis
  • 103,016
  • 27
  • 158
  • 194
  • Actually I m using opencv library for image subtraction, I need to send that data to the board that why I m using C instead of C#. – Saurabh Dec 24 '10 at 08:36
  • I saw that opencv has a python wrapper. If you know python this will be definitely the way to go. Python has a reliable and cross-platform serial library (PySerial) that is very easy to use. – kgiannakakis Dec 24 '10 at 09:10
  • Changing to (and possibly having to learn) and entirely different language (and a scripted one at that) just to get a serial driver is not really "*the way to go*" at all! – Clifford Dec 24 '10 at 18:39
0

Serial comms in Win32 is not particularly well catered for, the API is somewhat cumbersome to use but is dealt with fairly comprehensively in this article on MSDN.

The .Net 2.0 (and later) Framework includes an excellent and easy to use serial communications class that makes the whole process much simpler, but you'll need to use C++/CLI or C# or some other .NET language to access that.

For very simple serial I/O you can always use stdio and simply open the COM*n* device where n is the port number you wish to open. Stdio provides no means to set baud rate and framing etc., but this can easily be achieved by invoking the mode command via a system call. It is crude and lacks the flexibility of the API level interface, but may be adequate for your needs for a quick-and-dirty solution. For example:

system( "MODE COM1: BAUD=115200 PARITY=n DATA=8 STOP=1" ) ;
FILE port = fopen( "COM1:", "wb" ) ;
fprintf( port, "hello, world!\n" ) ;
fclose( port ) ;
Clifford
  • 88,407
  • 13
  • 85
  • 165
  • Do I need to include some kind of headers for the same – Saurabh Dec 28 '10 at 13:14
  • @Saurabh: You'll will of course need the headers that declare the functions that you use; that is a given in any event. The example code above will need the standard library headers stdlib.h and stdio.h. Does that really need saying!? – Clifford Dec 28 '10 at 14:50