#### Archived

This topic is now archived and is closed to further replies.

# Serial Port Programming

This topic is 5234 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I suppose I'll just stick my problem right out there: I want to send data like this over a serial port (rs-232?) at 250,000 bits per second: Now, as far as making high's and lows for the appropriate lengths, I know that at ~250,000bps, 4µs is one bit. Now, my question is, If I were to send a stream of bytes such as the first diagram, wouuld my computer automatically insert stop bits, parity bits, etc.. after each byte I send? Is there a way I can gain raw access to the serial port so it doesnt? Thanks, Matt EDIT: To make this easier to understand, I guess all I need is complete control over what's going over the line (i.e. stop bits, start bits, etc..) [edited by - Xtremehobo on March 21, 2004 12:27:08 PM]

Which OS?

##### Share on other sites
Windows XP

If there''s no possible way in XP, I might just code a simple real-mode bootstrap, put it on a floppy, and try to control the serial port from that, but I''d really preffer to find a way in XP.

##### Share on other sites
Last time I was doing serial port programming on WinXP, I found User Port to be very helpful. Worth looking into I think.

##### Share on other sites
hmm, looks like I might be able to get away using an rs-232 port, but does anybody know how many bits the "break" is in rs-232 serial communications?

##### Share on other sites
How bizarre. I've just started writing an application to control a multimeter via the RS-232 connection. It's really simple to implement in Win32:
HANDLE port = CreateFile ("COM1", GENERIC_READ | GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, 0);DCB state = {/* com port settings*/};SetCommState (port, &state);// receiving dataReadFile (port, buffer, bytes_to_read, &bytes_read, 0);// sending dataWriteFile (port, buffer, bytes_to_write, &bytes_written, 0);CloseHandle (port);

Look in the MSDN for the contents of the DCB structure. You can specify baud rate, number of data bits, number of stop bits, parity and lots of other stuff.

Skizz

EDIT: Should have said, you can't get raw access to the data stream - there's a chip on your motherboard (the UART) which converts data sent to it into a serial stream and vice-versa. It adds (or removes) the start, stop and parity bits as defined by the configuration settings. You can change those settings in the DCB structure.

[edited by - Skizz on March 22, 2004 7:25:17 AM]

##### Share on other sites
You can frob the serial port bits directly under XP, but only if you unlock them. Look at WinIO and the documentation for _outp().

I don't recommend it unless it's a hobbyist project, though - serial ports seem to be a dying breed (eg. most notebooks simply don't have them) so if you're making a product that you want people in general to be able to use, stick to standard RS232 IO, and that way it'll work through USB-to-serial adapters.

[edit: Yes, yes, you can write to the serial port with _inp(), really you can. Yes.]

[edited by - fractoid on March 22, 2004 8:03:52 AM]

1. 1
2. 2
Rutin
24
3. 3
4. 4
JoeJ
18
5. 5

• 14
• 28
• 11
• 11
• 9
• ### Forum Statistics

• Total Topics
631772
• Total Posts
3002260
×