views:

122

answers:

2
+1  Q: 

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...

A: 

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.

ChrisW
hithanks for your answermy problem didnt solve i can send/receive data to/from com port my os is winxp
Mehdi
i sett the bisoscom with api 0 but it dosnt work please help me
Mehdi
@user222820 How do you know that it's not working (what are the symptoms of its not working)? Are you compiling your software as a 16-bit DOS executable? Have you tried other COM ports? The supported (32-bit Windows) API for writing to serial ports under Windows is as described here: http://msdn.microsoft.com/en-us/library/ms810467.aspx ... the O/S may try to support applications using the BIOS (INT 14h) API, but I don't think that's officially supported.
ChrisW
+4  A: 

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.

tomlogic
you might want to toss SetCommTimeouts() in there, too
JustJeff
ChrisW's link in the comment to his answer provides more details on accessing serial ports with Win32: http://msdn.microsoft.com/en-us/library/ms810467.aspx
tomlogic