Writing to linux tty (/dev/) files in c# -


i need program execute command in bash this: "echo p1-12=175 > /dev/servoblaster". how do in mono/c# on linux? wrote following class:

public static class servoblasterpwm {     private static filestream devfile;      public static bool isrunning     {         get;         private set;     }      public static bool initialize()     {         try         {             devfile = file.open("/dev/servoblaster", filemode.open);         }         catch (exception e)         {             log.error("error while setting port servo blaster: " + e.message);             return false;         }          log.success("servoblaster set up.");         isrunning = true;          return true;     }      public static void setpwmoutput(int pin, int valuesteps)     {         //byte[] bytes = encoding.ascii.getbytes("p1-" + pin.tostring() + "=" + valuesteps.tostring());          byte[] bytes = encoding.ascii.getbytes("p1-12=175");         devfile.write(bytes, 0, bytes.length);         devfile.flush();          console.writeline("wrote file");     }      public static void shutdown()     {         devfile.close();         isrunning = false;          log.info("servo blaster has been shut down.");     } } 

this code doesn't work. tried streamwriter instead of filestream, crashed exception saying stream not support seeking. have no idea how this. please help.

try replace string array code by:

byte[] bytes = asciiencoding.utf8.getbytes("p1-12=175") ; 

or:

byte[] bytes = asciiencoding.default.getbytes("p1-12=175") ; 

Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -