title: Sainsmart Usb relay control
body: <p>I have Purchased a <a href="http://www.sainsmart.com/sainsmart-16-channel-controller-usb-hid-programmable-control-relay-module.html" rel="nofollow">SainSmart 16 Channel controller USB HID Programmable Control Relay Module</a> to control the corresponding 16 channel relay board. </p>
  
  <p>The source code provided is quite terrible, but included was an cmd line program that works quite well to control the relays. I'm trying to make a GUI using C# to send commands to the program. I Did a bit of reading on this site, but I didn't get too far. </p>
  
  <p>Ultimately I need to send the argument "afEd5 open 01" to CommandApp.exe then pause for a few milliseconds then send argument "afEd5 close 01". </p>
  
  <p>Any help would be greatly appreciated, thanks.</p>
  
  <p>UPDATE: Figured out most of the coding thus far, only small issue I have now is the location of the CommandApp.exe. I'd prefer it was located with the the primary exe of the application rather than in the root of C.</p>
  
  <pre><code>using System;
  using System.Threading.Tasks;
  using System.Collections.Generic;
  using System.ComponentModel;
  using System.Data;
  using System.Drawing;
  using System.Linq;
  using System.Text;
  using System.Windows.Forms;
  using System.Diagnostics;
  
  namespace GenesisDigitalInterface
  {
      public partial class Form1 : Form
      {
          public Form1()
          {
              InitializeComponent();
          }
  
      // Toggle Power Button relay
      private void PowerButton_Click(object sender, EventArgs e)
      {
          Process controlusb = new Process();
          controlusb.StartInfo = new ProcessStartInfo("C:\\CommandApp.exe");
          controlusb.StartInfo.Arguments = "afEd5 open 01";
          controlusb.StartInfo.UseShellExecute = false;
          controlusb.StartInfo.LoadUserProfile = true;
          controlusb.StartInfo.RedirectStandardInput = true;
          controlusb.StartInfo.RedirectStandardOutput = true;
          controlusb.StartInfo.RedirectStandardError = true;
          controlusb.Start();
          Thread.Sleep(100);
          controlusb.StartInfo = new ProcessStartInfo("C:\\CommandApp.exe");
          controlusb.StartInfo.Arguments = "afEd5 close 01";
          controlusb.StartInfo.UseShellExecute = false;
          controlusb.StartInfo.LoadUserProfile = true;
          controlusb.StartInfo.RedirectStandardInput = true;
          controlusb.StartInfo.RedirectStandardOutput = true;
          controlusb.StartInfo.RedirectStandardError = true;
          controlusb.Start();
      }
          }
  
      }
  }
  </code></pre>