Hi Everybody,
Im a new programmer.........
i had used the following code to output data to com port.....
#include<iostream.h>
#include<conio.h>
#include<dos.h>
#include<bios.h>

#define SETTINGS (_COM110|_COM_CHR7|_COM_STOP1|_COM_NOPARITY)
void main()
{
clrscr();
_bios_serialcom(_COM_INIT,0,SETTINGS);
outportb(0x03f8,0);
getch();
}

when i run the programme,when i connect pin 3(tx pinn) to a LED it blinks one tym..........

so how can i tx a file..............

how can transmit relevent characters in binary....(how to convert it to binary........)

how i can use inportb() methord?

Please help me.............................

if u know more details please tell me........
if u got more teaching meterials please mail to <email address snipped> okk

Dani AI

Generated

Quick practical summary: a file is already a stream of bytes, so you do not "convert it to binary" before sending — open it with std::ifstream in binary mode and stream those bytes to the port. The real work is getting the hardware and the protocol right: correct voltage levels, matching baud/parity/stop, and some form of packet/checksum so the receiver can detect errors. For a beginner () the fastest path is to use a serial library or a terminal program that already implements file-transfer protocols rather than trying to bit-bang individual pins.

Hardware and safety checks first: PC COM ports use true RS-232 voltages (± volts) while many microcontrollers use TTL (0/5V). Do not hook TX directly to an LED or another device without a proper level shifter (MAX232) or a USB-serial adapter. Do a local loopback test (wire TX to RX) to verify your software and settings before wiring two machines together.

A minimal reliable workflow: pick baud/parity/stop; open the port with an OS API or library (Boost.Asio, libserialport, Win32 CreateFile/SetCommState, or POSIX termios); open the file in binary mode; send fixed-size packets (128–1024 bytes) with a checksum/CRC; wait for ACK/NAK and implement timeouts/retries; finally verify size/CRC. If you want to avoid reinventing reliability, use a standard transfer protocol (XMODEM/YMODEM/ZMODEM) or a library that implements one.

Example snippet (Boost.Asio) to stream a file to a port:

#include <boost/asio.hpp>
#include <fstream>

boost::asio::io_context io;
boost::asio::serial_port port(io, "COM1"); // or "/dev/ttyUSB0"
port.set_option(boost::asio::serial_port_base::baud_rate(115200));

std::ifstream in("file.bin", std::ios::binary);
char buf[1024];
while (in.read(buf, sizeof(buf)) || in.gcount()) {
    boost::asio::write(port, boost::asio::buffer(buf, in.gcount()));
}

A final note: low-level calls like inportb/outportb are DOS/kernel-era and are not available from normal user-mode programs on modern Windows/Linux without a driver. As suggested, libraries save you a lot of trouble; and as hinted, check your environment and use modern APIs for correct, safe operation.

Recommended Answers

All 2 Replies

There are many libraries that will do all the hard work for you, requiring just a stream of bytes as input and producing a stream of bytes as output on the other end.

But you can indeed do it all yourself, by taking each byte, pulling it apart into bits, and pumping it over the connection like you did that single blip.

how i can use inportb() methord?

See in the help section. It needs the port id as the argument and returns the byte received at that port.

But, it would definitely be easier to use the libraries as jwenting suggested.

If your purpose is just to transmit or receive a file, use hyperterminal instead. It will do all the low-level stuff on its own.

this program cannot use in Microsoft visual c++

Specify the errors you encounter.

Don't use old style header files. And yes, void main() must be replaced by int main() ;).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.