Baud Port Checker Rare

I need to use an UART to communicate between beaglebone and the device. I have written the C code, but it has a few problems within it. I can't identify the cause of the problem or to be more precise don't know how fix it.

Active5 months ago

In Windows command prompt to configure a serial port, I can simple use:

or to read the configuration:

Are there similar commands in Linux? What would be the easiest way to find and configure the serial port in Linux?

Hrvoje THrvoje T
4271 gold badge5 silver badges22 bronze badges

1 Answer

You can use the stty command to set such parameters.

This will show all settings on the first serial port (replace ttyS0 with ttyUSB0 if using an USB serial port):

How

This will set the baud rate to 9600, 8 bits, 1 stop bit, no parity:

One thing that generally confuses people is that most serial drivers will reset the settings to the defaults once the device is closed (i.e. no process has the device open anymore). So the above stty command will set the settings, then when it's done the driver resets them again. If you first have your POS software open the device and then perform the stty settings, they should stick around until your POS software closes the device again (e.g. upon exiting).

I'd have thought that the POS software should have some way of configuring these settings on its own. If you're writing your own software to drive the printer, make sure you first open the device, and then perform the stty command.

You may also need to play around with other settings, e.g. opost means that output postprocessing will be performed. If opost and onlcr are both set, the onlcr will cause an extra carriage return (0xd) to be added when a newline (0xa) byte is output, typically to prevent staircase printing such as

This may or may not be what you want. If you want a raw one-to-one output to the printer turn opost off (add -opost to the stty parameters).

Handshaking (flow control) is also controlled with stty, without knowing more about the printer I can't tell whether you need to set anything.

Check the stty manpage for lots more info.

wurtelwurtel
11.9k1 gold badge16 silver badges29 bronze badges

Not the answer you're looking for? Browse other questions tagged serial-port or ask your own question.

Active7 months ago

Is there a way to find out all the available baud rates that a particularsystem supports via C#? This is available through Device Manager-->Portsbut I want to list these programmatically.

Cœur
21.9k10 gold badges127 silver badges178 bronze badges
HiteshPHiteshP
4572 gold badges7 silver badges15 bronze badges

3 Answers

I have found a couple of ways to do this. The following two documents were a starting point

Port Scan

The clue is in the following paragraph from the first document

The simplest way to determine what baud rates are available on a particular serial port is to call the GetCommProperties() application programming interface (API) and examine the COMMPROP.dwSettableBaud bitmask to determine what baud rates are supported on that serial port.

At this stage there are two choices to do this in C#:

Baud Port Checker Rare

Define the following data structure

Then define the following signatures

Now make the following calls (refer to http://msdn.microsoft.com/en-us/library/aa363858(VS.85).aspx)

Where portName is something like COM?? (COM1, COM2, etc). commProp.dwSettableBaud should now contain the desired information.

Reflection can be used to access the SerialPort BaseStream and thence the required data as follows:

Note that in both the methods above the port(s) has to be opened at least once to get this data.

HiteshP

Baud Port Checker Rare Earth

HiteshP
4572 gold badges7 silver badges15 bronze badges

Obviously, this doesn't help me.So this is what I am currently relying upon:

Port Checker

The baud rates are in strings because they are destined for a combo box.

How To Open Port

You can improve on performance if you know the minimum baud rate supported by all of the serial ports you plan to open. For instance, starting with 115,200 seems like a safe lower limit for serial ports manufactured in this century.

Max EuweMax Euwe

I don't think you can.

I recently had this problem, and ended up hard coding the baud rates I wanted to use.

Open Port Checker

MSDN simply states, 'The baud rate must be supported by the user's serial driver'.

BryanBryan
1,8417 gold badges33 silver badges54 bronze badges

Port Checker Windows

Not the answer you're looking for? Browse other questions tagged c#serial-portbaud-rate or ask your own question.