本文整理汇总了C#中Port类的典型用法代码示例。如果您正苦于以下问题:C# Port类的具体用法?C# Port怎么用?C# Port使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Port类属于命名空间,在下文中一共展示了Port类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Start
public override void Start()
{
foreach (var potentialSensor in KinectSensor.KinectSensors)
{
if (potentialSensor.Status == KinectStatus.Connected)
{
this.sensor = potentialSensor;
break;
}
}
//Create a new port on the platform.
string kinectStr = moduleInfo.Args()[0];
VPortInfo pInfo = GetPortInfoFromPlatform("kinect" + kinectStr);
List<VRole> roles = new List<VRole>() { RoleCamera.Instance, RoleDepthCam.Instance, RoleMicrophone.Instance, RoleSkeletonTracker.Instance };
kinectPort = InitPort(pInfo);
BindRoles(kinectPort, roles, OnOperationInvoke);
RegisterPortWithPlatform(kinectPort);
/* sensor.ColorStream.Enable();
sensor.DepthStream.Enable();
sensor.SkeletonStream.Enable();*/
logger.Log("Kinect Sensor Rigistered.");
StartKinect();
}
示例2: Run
private static void Run(int n, int threadCount)
{
Dispatcher d = new Dispatcher(threadCount, "ccr pool");
DispatcherQueue dq = new DispatcherQueue("disp", d);
Port<int> p1 = new Port<int>(), p2 = new Port<int>();
EventWaitHandle done1 = new AutoResetEvent(false), done2 = new AutoResetEvent(false);
PingPonger pp1 = new PingPonger(done1, n, p2),
pp2 = new PingPonger(done2, n, p1);
Arbiter.Activate(dq, Arbiter.Interleave(
new TeardownReceiverGroup(),
new ExclusiveReceiverGroup(Arbiter.Receive(true, p1, pp1.Update)),
new ConcurrentReceiverGroup()));
Arbiter.Activate(dq, Arbiter.Interleave(
new TeardownReceiverGroup(),
new ExclusiveReceiverGroup(Arbiter.Receive(true, p2, pp2.Update)),
new ConcurrentReceiverGroup()));
p1.Post(0);
EventWaitHandle.WaitAll(new[] { done1, done2 });
dq.Dispose();
d.Dispose();
}
示例3: SupportsPort
public override bool SupportsPort(Port port)
{
if(port == null)
throw new ArgumentNullException("port");
return port.BusCount == 0 && port.InputSignalCount == port.OutputSignalCount+1;
}
示例4: Mul
static void Mul(InputData data, Port<int> resp)
{
int Result = 0;
int i = 0;
System.Diagnostics.Stopwatch sWatch = new System.Diagnostics.Stopwatch();
Random r = new Random();
for (int j = 0; j < n; j++)
a[j] = r.Next(5);
sWatch.Start();
for (i = data.start; i <= data.stop; i++)
{
Result = Result + a[i];
}
resp.Post(1);
Console.WriteLine("Поток № {0}: Параллельный алгоритм = {1} мс.", Thread.CurrentThread.ManagedThreadId, sWatch.ElapsedMilliseconds.ToString());
sWatch.Stop();
Console.WriteLine("Сумма:");
Console.WriteLine(Result);
}
示例5: FulfillsCondition
public override bool FulfillsCondition(Signal output, Port port)
{
foreach(Condition c in _conditions)
if(!c.FulfillsCondition(output, port))
return false;
return true;
}
示例6: DoTraverse
protected override void DoTraverse(Port rootPort, IScanVisitor visitor, bool ignoreHold)
{
List<Guid> signals = new List<Guid>();
foreach(Signal input in rootPort.InputSignals)
if(!TraverseSignal(signals, input, rootPort, ignoreHold, visitor))
break; // finished
}
示例7: Mul
static void Mul(InputData data, Port<int> resp)
{
int i;
double Pi = 0,dx=0,x=0;
System.Diagnostics.Stopwatch sWatch = new System.Diagnostics.Stopwatch();
sWatch.Start();
dx = 1 / 10000000.0;
x = data.start / 10000000.0;
for (i = data.start; i <= data.stop; i++)
{
Pi += Math.Sqrt(1 - x * x)*4*dx;
x += dx;
}
Console.WriteLine("часть Pi №{0} = {1}", Thread.CurrentThread.ManagedThreadId,Pi);
sWatch.Stop();
resp.Post(1);
Console.WriteLine("Поток № {0}: Параллельный алгоритм = {1} мс.", Thread.CurrentThread.ManagedThreadId, sWatch.ElapsedMilliseconds.ToString());
}
示例8: InputStateEventArgs
public InputStateEventArgs(Port port, Device device, uint index, uint id)
{
Port = port;
Device = device;
Index = index;
Id = id;
}
示例9: Start
public override void Start()
{
logger.Log("Started: {0}", ToString());
string dummyDeviceId = moduleInfo.Args()[0];
serialPortNameforArudino = moduleInfo.Args()[1];
//.... Open the serial port - AJB TODO - error checking on port name
serialPortOpen = OpenSerialPort();
//.................instantiate the port
VPortInfo portInfo = GetPortInfoFromPlatform("arduino-" + dummyDeviceId);
dummyPort = InitPort(portInfo);
// ..... initialize the list of roles we are going to export and bind to the role
List<VRole> listRole = new List<VRole>() { RoleDummy.Instance};
BindRoles(dummyPort, listRole);
//.................register the port after the binding is complete
RegisterPortWithPlatform(dummyPort);
workThread = new SafeThread(delegate() { Work(); } , "ArduinoDriverDummy work thread" , logger);
workThread.Start();
imageServer = new WebFileServer(moduleInfo.BinaryDir(), moduleInfo.BaseURL(), logger);
}
示例10: DispatchEventWithDispatcherQueueExceptionPort
public void DispatchEventWithDispatcherQueueExceptionPort()
{
using (Dispatcher d = new Dispatcher ()) {
var dq = new DispatcherQueue ("foo", d);
var evt = new AutoResetEvent (false);
var port = new Port<Exception> ();
dq.UnhandledExceptionPort = port;
int portPost = 0;
int dispEx = 0;
d.UnhandledException += delegate { ++dispEx; };
var rec = Arbiter.Receive (true, port, (e) => { ++portPost; evt.Set(); });
rec.TaskQueue = dq;
rec.Execute ();
dq.Enqueue (Arbiter.FromHandler (() => { throw new Exception (); }));
Assert.IsTrue (evt.WaitOne (2000), "#1");
Assert.AreEqual (1, portPost, "#2");
Assert.AreEqual (0, dispEx, "#3");
dq.Enqueue (Arbiter.FromHandler (() => { throw new Exception (); }));
Assert.IsTrue (evt.WaitOne (2000), "#4");
Assert.AreEqual (2, portPost, "#5");
Assert.AreEqual (0, dispEx, "#6");
}
}
示例11: Mul
static void Mul(InputData data, Port<int> resp)
{
long Result = 0;
int i = 0;
System.Diagnostics.Stopwatch sWatch = new System.Diagnostics.Stopwatch();
Random r = new Random();
for (int j = 0; j < n; j++)
{
a[j] = r.Next(1, 3);
b[j] = r.Next(1, 3);
}
long ResultA = 1;
long ResultB = 1;
long Res = 0;
sWatch.Start();
for (i = data.start; i <= data.stop; i++)
{
ResultA = ResultA * a[i];
ResultB = ResultB * b[i];
ResultA = ResultA / 25;
ResultArr[i] = ResultA + ResultB;
Res = Res + ResultArr[i];
}
sWatch.Stop();
resp.Post(1);
Console.WriteLine("Поток № {0}: Параллельный алгоритм = {1} мс.", Thread.CurrentThread.ManagedThreadId, sWatch.ElapsedMilliseconds.ToString());
}
示例12: EnterSignal
public override bool EnterSignal(Signal signal, Port parent, bool again, bool root)
{
if(again)
return false;
_signals.Add(signal);
return true;
}
示例13: Start
public override void Start()
{
logger.Log("Started: {0}", ToString());
string airConditionCtrlDevice = moduleInfo.Args()[0];
//.................instantiate the port
VPortInfo portInfo = GetPortInfoFromPlatform(airConditionCtrlDevice);
airConditionCtrlPort = InitPort(portInfo);
// ..... initialize the list of roles we are going to export and bind to the role
List<VRole> listRole = new List<VRole>() { RoleSwitchMultiLevel.Instance };
BindRoles(airConditionCtrlPort, listRole);
//.................register the port after the binding is complete
RegisterPortWithPlatform(airConditionCtrlPort);
workThread = new SafeThread(delegate() { Work(); }, "DriverAirConditionCtrl work thread", logger);
workThread.Start();
imageServer = new WebFileServer(moduleInfo.BinaryDir(), moduleInfo.BaseURL(), logger);
gm.ComPort = "COM6";
gm.BaudRate = 9600;
gm.Open();
gm.SmsRecieved+=new EventHandler(gm_SmsRecieved);
}
示例14: CtorSideEffects
public void CtorSideEffects()
{
int count = 0;
var pa = new Port<int> ();
var pb = new Port<string> ();
var ra = Arbiter.Receive (false, pa, (i) => count += i);
var rb = Arbiter.Receive (false, pb, (s) => count += s.Length);
var c = new Choice (ra, rb);
IPortReceive pra = pa;
IPortReceive prb = pb;
Assert.AreEqual (ArbiterTaskState.Created, c.ArbiterState, "#1");
Assert.AreEqual (0, c.PortElementCount, "#2");
Assert.AreEqual (0, pra.GetReceivers ().Length, "#3");
Assert.AreEqual (0, prb.GetReceivers ().Length, "#4");
Assert.IsNull (ra.Arbiter, "#5");
Assert.IsNull (rb.Arbiter, "#6");
Assert.IsNull (ra.ArbiterContext, "#7");
Assert.IsNull (rb.ArbiterContext, "#8");
Assert.IsNull (ra.ArbiterCleanupHandler, "#9");
Assert.IsNull (rb.ArbiterCleanupHandler, "#10");
}
示例15: Start
public override void Start()
{
string kinectStr = moduleInfo.Args()[0];
foreach (var potentialSensor in KinectSensor.KinectSensors)
{
if (potentialSensor.Status == KinectStatus.Connected)
{
//encode the id string as per the encoding in the scout so the match will work
// '\' and '&' cause problem when the values get written to the config file (XML writer not happy)
string kinectid = "Kinect Sensor:" + potentialSensor.UniqueKinectId.Replace("\\", "-").Replace("&", ".");
if (kinectStr == kinectid)
{
this.sensor = potentialSensor;
break;
}
}
}
//Create a new port on the platform.
VPortInfo pInfo = GetPortInfoFromPlatform("kinect" + kinectStr);
List<VRole> roles = new List<VRole>() { RoleCamera.Instance, RoleDepthCam.Instance, RoleMicrophone.Instance, RoleSkeletonTracker.Instance, RoleSpeechReco.Instance };
kinectPort = InitPort(pInfo);
BindRoles(kinectPort, roles, OnOperationInvoke);
RegisterPortWithPlatform(kinectPort);
logger.Log("Kinect Sensor Registered.");
StartKinect();
}