Software > Software

have C++ serial code?

(1/3) > >>

benji:
hey folks, anyone knows a library in c++ that has functions to send recieve via the serial port?

bens:
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).

benji:
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?

bens:
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();
  ...
}

benji:
u sure yiou dont have to include anythin here??? what files?

Navigation

[0] Message Index

[#] Next page

Go to full version