Dos Serial Port Monitor

 admin  

Is there a way to read a line of data from the serial port from DOS/NT COMMAND. The only method I've found mentioned in my web searches is the 'TYPE' command. But I've not been able to make it work. If I enter 'type com1', it seems to begin reading the port, but no matter what control characters I send.

Dos serial port monitor
Active6 years, 9 months ago

Right now I am using an Arduino to send data from an analog sensor to COM4. I am trying to make a python script that continuously monitors that data and looks for a certain parameter.

I tried something like this but it isn't alerting me correctly Bangla dictionary software download for mobile.

dsolimano
7,5973 gold badges41 silver badges57 bronze badges
jakke34jakke34

3 Answers

If the serial package you are using is pySerial, take note of the definition of the Serial.read() method:

read(size=1)

Parameter: size – Number of bytes to read.

Returns: Bytes read from the port.

Read size bytes from the serial port. If a timeout is set it may return less characters as requested. With no timeout it will block until the requested number of bytes is read.

Changed in version 2.5: Returns an instance of bytes when available (Python 2.6 and newer) and str otherwise.

Although you are trying to process byte objects, you may (depending on Python version) be handling str or bytes (array) objects. These objects do not necessarily correspond to integer values.

Dos Serial Port Monitor

Even when receiving byte objects from read(), the largest unsigned integer will be 255.Comparing value with 400 doesn't make sense. Try to find the type of the returned objects with a simple debugging output.

If you need to handle an str object, check the use of ord() for convertion.

(The flush suggestion refers to the original question, which used print, not tkinter).

See how-to-flush-output-of-python-print, and try the command line shell, not the IDE which may affect output buffering.

Community
gimelgimel
60.7k10 gold badges63 silver badges98 bronze badges

Instead of having the Arduino code relay all the analog values to COM4, have it relay a flag only when you meet the conditional.

So arduino code could be:

Then your Python code can just look for the flag like this:

sdsdsdsd

Assuming that you are using pySerial, serial.read() only reads one byte, which means a maximum value of 255. If your Arduino is sending string values back it's probably best to separate them with newline characters and use serial.readline().

Unless you have specific performance requirements sending strings back from the Arduino will make debugging significanly easier anyway.

Also if you are receiving strings back from the Arduino, your test should be if int(value) > 400:

Dos
Dan HeadDan Head

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

PagesFavoritedFavorite27

Command Line (Windows, Mac, Linux)

As mentioned earlier, you can use command line interfaces to create serial connections. The major limiting factor is the lack of connection options. Most of the programs we've discussed so far have a slew of options that you can tweak for your specific connection, whereas the command line method is more of a quick and dirty way of connecting to your device in a pinch. Here's how to accomplish this on the three major operating systems.

Terminal and Screen (Mac, Linux)

Mac

Open Terminal. See the Connecting to Your Device section for directions.

Now type ls /dev/tty.* to see all available ports.

You can now use the screen command to to establish a simple serial connection.

Type screen <port_name> <baud_rate> to create a connection.

The terminal will go blank with just a cursor. You are now connected to that port!

To disconnect, type control-a followed by control-. The screen will then ask if you are sure you want to disconnect.

There are other options you can control from screen, however it is recommended that you only use this method if you are comfortable with the command line. Type man screen for a full list of options and commands.

Linux

The screen command can also be used in Linux. There are only a few variations from the Mac instructions.

If you do not have screen installed, get it with sudo apt-get install screen.

Making a connection is the same as Mac.

To disconnect, type control-a then shift-k.

That's all there is to it.

MS-DOS Prompt (Windows)

The fastest way to get to the command line in Windows is to click on the start menu, type cmd into the search field, and press Enter.

This will open up a blank MS-DOS command line prompt.

To be able to issue Serial commands, you must first enter PowerShell. Type powershell to get into PowerShell command mode.

To see a list of all the available COM ports, type

You should now see something like this.

Now create an instance of the port you want with this command

With that, you can now connect to and send data to or from that COM port.

Again, this method of serial communication is only recommended for advanced command line users.

← Previous Page
ZTerm (Mac)
   Coments are closed