static void CleanPort(object o) { lock (o) { ChannelFactory <IPortServerContract> factory = new ChannelFactory <IPortServerContract>("IParallelPortAPI"); IPortServerContract client = factory.CreateChannel(); client.WritePortValue(888, 0); factory.Close(); } }
void CAllProcedure() { if (countCalls < 4) { Action d0 = () => { try { ChannelFactory <IPortServerContract> factory = new ChannelFactory <IPortServerContract>("PPort", new EndpointAddress(doCallpportAddress)); IPortServerContract client = factory.CreateChannel(); int readed = client.ReadPortValue(888); client.WritePortValue(888, (readed & 254) + 1); Thread.Sleep(new TimeSpan(0, 0, 20)); readed = client.ReadPortValue(888); client.WritePortValue(888, readed & 254); factory.Close(); } catch (Exception e) { //MessageBox.Show("La aplicación no pudo ejecutar llamada.\n", "Advertencia", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }; Action d1 = () => { try { ChannelFactory <IPortServerContract> factory = new ChannelFactory <IPortServerContract>("PPort", new EndpointAddress(doCallpportAddress)); IPortServerContract client = factory.CreateChannel(); int readed = client.ReadPortValue(888); client.WritePortValue(888, (readed & 253) + 2); Thread.Sleep(new TimeSpan(0, 0, 2)); readed = client.ReadPortValue(888); client.WritePortValue(888, readed & 253); factory.Close(); } catch (Exception e) { //MessageBox.Show("La aplicación no pudo ejecutar llamada.\n", "Advertencia", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }; d0.BeginInvoke(null, null); Thread.Sleep(200); d1.BeginInvoke(null, null); countCalls++; } else { calltimer.Enabled = false; calltimer.Stop(); } }
static void SwitchState(object o) { lock (o) { TimeSpan span; span = DateTime.Now - lastPinch; if (span > new TimeSpan(0, minTimeTilNext, 0)) { lastPinch = DateTime.Now; ChannelFactory <IPortServerContract> factory = new ChannelFactory <IPortServerContract>("IParallelPortAPI"); IPortServerContract client = factory.CreateChannel(); client.WritePortValue(888, 1); Thread.Sleep(2000); client.WritePortValue(888, 0); factory.Close(); StreamWriter s = new StreamWriter(AppDomain.CurrentDomain.BaseDirectory + "Log.txt", true); s.WriteLine(DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToShortTimeString() + " (Cambio de Aire)"); s.WriteLine("----------------------------------------"); s.Flush(); s.Close(); } } }