Quantcast
Channel: Intel Communities: Message List
Viewing all articles
Browse latest Browse all 17969

Re: Arduino sketch - To create command window?

$
0
0

Not sure, if you need to set something up on the linux, than there may be some issues, but could work.

For the fun of it, I started a simple sketch to see how bad it would be to have simple sketch to be able to at first do simple commands, which take no input from the user.  instead of using the system command I instead use the popen command, which creates a pipe from the output of the command, which I can then direct to the Serial object.  Current program:

char abBuf[256];
void setup() {  delay(5000);  Serial.begin(115200);  delay(2000);  Serial.println("Serial Terminal");  Serial.flush();
}

void loop() {
  // put your main code here, to run repeatedly:  // readbytesUntil eats CPU so:  int cbRead = 0;  for (;;) {    while (!Serial.available())      delay(10);  // give some time for inputs    abBuf[cbRead] = Serial.read();    if (abBuf[cbRead] == 13)      break;    if (abBuf[cbRead] > 13)  // ignore control characters...      cbRead++;  }  abBuf[cbRead] = 0;  Serial.print("cb Read: ");  Serial.println(cbRead, DEC);  Serial.print("Cmd: ");  Serial.println(abBuf);  FILE *fpipe;  if ( !(fpipe = (FILE*)popen(abBuf,"r")) ) {    Serial.println("Problems with pipe");    return;  }  while ( fgets( abBuf, sizeof(abBuf), fpipe)) {    Serial.print(abBuf);  }  pclose(fpipe);
}

So far this works for simple things, like: I did an ls of the /tmp directory and cat of the error file.  Part of the output:

Serial Terminal

cb Read: 7

Cmd: ls /tmp

log.txt

log_er.txt

systemd-private-29aac466f3ec41d38837c3720cc04e50-systemd-timesyncd.service-EtZd2A

watchdog-sample.tmp

wpa_ctrl_233-1

cb Read: 19

Cmd: cat /tmp/log_er.txt

sysfs-error: err set drive fs_path=/sys/class/gpio/gpio12/drive

 

sysfs-error: err set drive fs_path=/sys/class/gpio/gpio13/drive

 

sysfs-error: err set drive fs_path=/sys/class/gpio/gpio14/drive

 

sysfs-error: err set drive fs_path=/sys/class/gpio/gpio40/drive

 

sysfs-error: err set drive fs_path=/sys/class/gpio/gpio41/drive

 

sysfs-error: err set drive fs_path=/sys/class/gpio/gpio42/drive

 

sysfs-error: err set drive fs_path=/sys/class/gpio/gpio43/drive

 

sysfs-error: err set drive fs_path=/sys/class/gpio/gpio44/drive

 

sysfs-error: err set drive fs_path=/sys/class/gpio/gpio45/drive

 

sysfs-error: err set drive fs_path=/sys/class/gpio/gpio46/drive

 

Next phase if I continue would be to try to create pipes for both input and output.  I believe the way this is done, is you do a fork call to crate a duplicate child process, where you then create the pipes attached to the first 3 file descriptors, and then do an exec of  /bin/sh

...

 

Again may be fun!


Viewing all articles
Browse latest Browse all 17969

Trending Articles