Society of Robots - Robot Forum
Software => Software => Topic started by: benji on November 26, 2007, 11:12:00 AM
-
hey folks, anyone knows a library in c++ that has functions to send recieve via the serial port?
-
I know Microsoft's .Net framework has built-in support for serial ports, so if you're writing a computer-side application that sends data over the serial port I'd recommend Microsoft C++/C#/VB 2005 (it's free and the serial port interface is quite easy to use).
-
yes bens im using microsoft visual c++ ,,but i dont know the library and functions for sending recieving via the serial port,, what are they?
-
I've only done serial port stuff using C# and VB, but I expect it should be almost the same for visual C++. In C# (and maybe in C++), you would do the following:
System.IO.Ports.SerialPort port = new System.IO.Ports.SerialPort("COM1", 19200);
port.Open();
port.Write(new Byte[] { 128, 2, 45, 254 }, 0, 4); // array of bytes, array index of first byte to send, number of bytes to send
port.Close();
To read from the serial port you can either do
Byte[] buffer = new Byte[255];
int bytesToRead = 5;
port.Read(buffer, 0, bytesToRead);
or
int byte;
while (port.BytesToRead > 0)
{
byte = port.ReadByte();
...
}
-
u sure yiou dont have to include anythin here??? what files?
-
It's part of .Net 2.0 under the System.IO.Ports namespace. In C# you don't have to include anything, but in C++ you might need to include System.IO.Ports.h or something. Try using your visual C++'s help feature and search for serial port (or just write your program in C#, which is almost the same syntactically as C++ but I like a lot better). Make sure you're using Visual xx 2005.
-
Hi
You probably want to use termios.h
This lets you configure the port.
Then use can declare the device as a file and use standard write and read commands.
-
You probably want to use termios.h
yea but what are the functions? shouldnt there be also a .c file to include?
-
Why do you need a .c file?
Look for examples online as there are a lot of configurations to use it.
-
oh yea right but what are the functions included in this library< termios.h>?
-
open it and find out
-
(http://img134.imageshack.us/img134/7629/tccj7.th.jpg) (http://img134.imageshack.us/my.php?image=tccj7.jpg)
this is some simple code for serial communication!!!
outportb(port address,value);
this is the syntax and address for parallel port (LPT1) is 0x378 while for COM1(serial port) is 0x3f8 this can be checkd from device manager->ports->details
-
Hello,
I'm using Qt with http://qextserialport.sourceforge.net/ QextSerialPort and it works well.