Mehdi
Mehdi

Reputation: 167

serial port in C

I have written a program in C to send a byte to serial port (com). I have used BIOSCOM to send data but I guess that it doesn't open the port. Please tell how I can open and close a com port in C.

My code is here:

#define COM1 1;
bioscom (1 , 65 , COM1);

Please help me...

Upvotes: 2

Views: 1404

Answers (2)

tomlogic
tomlogic

Reputation: 11694

I've used the following Win32 APIs for opening a serial port in a command-line Win32 utility:

CreateFile - Use the string COMx as the filename, replacing x with the number of the serial port.

BuildCommDCB and SetCommState - Used to set parameters (baud, parity, databits, stopbits).

ReadFile and WriteFile - Used to read and write using the handle returned by CreateFile.

CloseHandle - Close the handle returned by CreateFile.

Search MSDN for documentation on each function, and you should be able to get it working quickly.

Upvotes: 5

ChrisW
ChrisW

Reputation: 56083

One of the bioscom APIs (API number 0) is used to initialize (not open) the serial port: e.g. to specify the baud rate etc.

Assuming the bioscom is using the BIOS API, I think that the serial port doesn't need to be opened: because the serial port hardware already exists, and the BIOS outputs to the hardware.

However the BIOS API may be disabled by the operating system, when the operating system puts the processor into protected mode and installs an O/S-specific device driver.

I don't know bioscom, but Google finds documentation and examples of how to use it.

Upvotes: 0

Related Questions