Go Down

Topic: Read/Write Serial communication thru CMD (Read 11431 times) previous topic - next topic

Domino60

Aug 25, 2015, 09:55 pm Last Edit: Aug 25, 2015, 09:56 pm by Domino60
Hi, I was experimenting a bit with serial communication thru windows command line and I fount this example :

https://batchloaf.wordpress.com/2013/02/12/simple-trick-for-sending-characters-to-a-serial-port-in-windows/

Everything works as in the example, setting the com port and sending data to arduino, I got this example led code for testing:
Code: [Select]
int led = 13;
int i;
void setup() {    

    Serial.begin(9600);
  pinMode(led, OUTPUT);    
}
void loop() {
  
  if(Serial.available() > 0){
    i = Serial.read() - '0';
   if(i == 1){
    digitalWrite(led, HIGH);
    Serial.println(i);
   }
    else if(i == 0){
    digitalWrite(led, LOW);
    Serial.println(i);
   }
  }
}


Nothing hard.

The main reason is that I couldn't find a way to simplify the cmd code and make a direct connection
like the serial monitor in the arduino IDE but thru windows cmd only.


Setting up the com port and sending data to test the it was easy:


but using that long code to send just data it's kinda not a good / nice way to write all the time
all that code  (  set /p x="1" <nul >\\.\COM4  ) just to send some data.

So is there any way to make a direct connection thru cmd or other already win. programs without  installing other programs like Arduino IDE.
To be or not to be? Read a book and you will see.
Join Discord Free_World (Arduino_Room) Live chat
https://discord.gg/bBXEuKQ

zoomkat

Quote
So is there any way to make a direct connection thru cmd or other already win. programs without  installing other programs like Arduino IDE.
You can use a batch file like below to send characters out the com port. Note the comport will open and close, causing the arduino to reset, so the reset feature will need to be defeated.

Code: [Select]

::@echo off
mode com3:9600,N,8,1 >nul

echo #0P2200 >com3
ping -n 2 127.0.0.1 >nul

echo #0P1500 t3000 >com3
ping -n 5 127.0.0.1 >nul

echo #0P2200 >com3
ping -n 2 127.0.0.1 >nul

echo #0P1500 t3000 >com3
ping -n 5 127.0.0.1 >nul

echo #0P2200 >com3
ping -n 2 127.0.0.1 >nul

exit
Google forum search: Use Google Search box in upper right side of this page.
Why I like my 2005 Rio Yellow Honda S2000  https://www.youtube.com/watch?v=pWjMvrkUqX0

Robin2

I would recommend writing a short Python program to communicate with the Arduino. It can take care of the Arduino reset business if it needs to. Then you can call the Python program from the command line.

This Python demo may give you some ideas.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

Domino60

zoomkat

It's a nice example but the reset gonna be a problem.

Robin2

Using Python is a nice idea but my goal is to use only already programs on windows, without installing
or programming / use extra programs.
To be or not to be? Read a book and you will see.
Join Discord Free_World (Arduino_Room) Live chat
https://discord.gg/bBXEuKQ

Robin2

my goal is to use only already programs on windows, without installing
or programming / use extra programs.
I am not familiar with Windows but I assumed Python was included.

Presumably there is an equivalent in Windows if you don't want to add Python.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

Domino60

To give an example, I reinstall windows and there's no any extra programs, i need to plug my arduino and start communicating with it, with the already existing programs inside the new installed OS.

No installs, nothing. Just open existing software and start communicating.
As I gave an example in the 1st comment with cmd but there no direct open communication, I can only send, not receive. Is there is a possible way to have a portable serial communication when I may accept it.
To be or not to be? Read a book and you will see.
Join Discord Free_World (Arduino_Room) Live chat
https://discord.gg/bBXEuKQ

zoomkat

If you want to do stuff native to windows, below is some old stuff from a long time back when I used the apache web server and batch files for web pan/tilt cams.

http://www.oocities.org/zoomkat/byte.htm

http://www.oocities.org/zoomkat/files/ezservo.txt

Google forum search: Use Google Search box in upper right side of this page.
Why I like my 2005 Rio Yellow Honda S2000  https://www.youtube.com/watch?v=pWjMvrkUqX0

Robin2

To give an example, I reinstall windows and there's no any extra programs, i need to plug my arduino and start communicating with it, with the already existing programs inside the new installed OS.

No installs, nothing. Just open existing software and start communicating.
Sounds like a great reason to use Linux.  :)


...R
Two or three hours spent thinking and reading documentation solves most programming problems.

Domino60

zoomkat

Yes I know that there is that way but I need a direct opened connection and writing direct letters/numbers without any command, just like serial monitor.

Robin2

Yea I know Linux has the ability to do great stuffs really easy but I'm working on Windows only.
To be or not to be? Read a book and you will see.
Join Discord Free_World (Arduino_Room) Live chat
https://discord.gg/bBXEuKQ

vbextreme

#9
Aug 29, 2015, 08:53 am Last Edit: Aug 29, 2015, 08:54 am by vbextreme
linux is definitely everything simpler .
For example you can create you a driver you maps to Arduino pins and use them directly as does the raspberry with gpio .
An example is the remoteGPIO to install and use it to read here

On Windows you can only emulate this mechanism .
Good luck for the sync command , remember that PCs are multitasking and two or more applications may call the device at the same time , difficult to manage with simple applications

Robin2

For example you can create you a driver you maps to Arduino pins and use them directly as does the raspberry with gpio
Not so easy on a laptop ?

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

vbextreme

what do you mean?
speak if the remoteGPIO go on a laptop ? Yes! It goes wherever located linux .
x86 , arm , etc ....
Once installed you'll get something like this:
Code: [Select]

odroid@odroid:~/Croject/remotegpio/src$ sudo insmod remotegpio.ko
odroid@odroid:~/Croject/remotegpio/src$ cd /sys/class/rgpio/
odroid@odroid:/sys/class/rgpio$ ls
board
odroid@odroid:/sys/class/rgpio$ echo "connect to=/dev/ttySAC0" > ./board
odroid@odroid:/sys/class/rgpio$ ls
a0.0  a2.0  a4.0  avr328p.0  d10.0  d12.0  d2.0  d4.0  d6.0  d8.0  eeprom.0
a1.0  a3.0  a5.0  board      d11.0  d13.0  d3.0  d5.0  d7.0  d9.0
odroid@odroid:/sys/class/rgpio$ cd avr328p.0
odroid@odroid:/sys/class/rgpio/avr328p.0$ ls
drv  lock  mode  option  power  ram  subsystem  timesleep  uevent  version
odroid@odroid:/sys/class/rgpio/avr328p.0$ cat ram
1326
odroid@odroid:/sys/class/rgpio/avr328p.0$ cat drv
id name nattr
0 servo 3

odroid@odroid:/sys/class/rgpio/avr328p.0$ echo "export 0"
export 0
odroid@odroid:/sys/class/rgpio/avr328p.0$ echo "export 0" > drv
odroid@odroid:/sys/class/rgpio/avr328p.0$ cd ..
odroid@odroid:/sys/class/rgpio$ ls
a0.0  a2.0  a4.0  avr328p.0  d10.0  d12.0  d2.0  d4.0  d6.0  d8.0  eeprom.0
a1.0  a3.0  a5.0  board      d11.0  d13.0  d3.0  d5.0  d7.0  d9.0  servo
odroid@odroid:/sys/class/rgpio$ cd servo
odroid@odroid:/sys/class/rgpio/servo$ ls
angle  attach  detach  lock  power  subsystem  uevent
odroid@odroid:/sys/class/rgpio/servo$ cd ..
odroid@odroid:/sys/class/rgpio$ cd d13.0
odroid@odroid:/sys/class/rgpio/d13.0$ ls
mode  power  subsystem  uevent  value
odroid@odroid:/sys/class/rgpio/d13.0$ echo "output" > mode
odroid@odroid:/sys/class/rgpio/d13.0$ echo "1" > value
odroid@odroid:/sys/class/rgpio/d13.0$ echo "0" > value

Robin2

what do you mean?
speak if the remoteGPIO go on a laptop
I don't know what you mean.

I have not noticed any GPIO pins on any of my laptops.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

Go Up