本文整理汇总了C#中Device.Open方法的典型用法代码示例。如果您正苦于以下问题:C# Device.Open方法的具体用法?C# Device.Open怎么用?C# Device.Open使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Device
的用法示例。
在下文中一共展示了Device.Open方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: LockController
//constructor
//operates on a usb device
public LockController()
{
devices = USBDeviceFactory.Enumerate();
if (devices.Length != 0)
{
device = devices[0];
device.Open();
}
tag = new Tag();
tag.Type = TagType.ISO_18000_6C_AUTO_DETECT;
}
示例2: controller
public controller(int i)
{
errors = 0;
tag = new Tag();
tag.Type = TagType.ISO_18000_6C_AUTO_DETECT;
devices = USBDeviceFactory.Enumerate();
reader_num = i;
device = devices[i];
byteArrayTagList = new List<byte[]>();
device.Open();
}
示例3: Start
/// <summary>
/// Starts processing GPS data from the specified stream.
/// </summary>
/// <param name="device">A device object providing GPS data to process.</param>
/// <remarks>This method will start the <strong>Interpreter</strong> using a separate thread.
/// The <strong>OnReadPacket</strong> is then called repeatedly from that thread to process
/// incoming data. The Pause, Resume and Stop methods are typically called after this
/// method to change the interpreter's behavior. Finally, a call to
/// <strong>Dispose</strong> will close the underlying stream, stop all processing, and
/// shut down the processing thread.</remarks>
public void Start(Device device)
{
// If we're disposed, complain
if (_isDisposed)
throw new ObjectDisposedException("The Interpreter cannot be started because it has been disposed.");
// Prevent state changes while the interpreter is started
#if !PocketPC
if (Monitor.TryEnter(SyncRoot, _commandTimeout))
#else
if (Monitor.TryEnter(SyncRoot))
#endif
{
try
{
// Set the device
_device = device;
// Signal that we're starting
OnStarting();
// If it's not open, open it now
if (!_device.IsOpen)
_device.Open();
// Indicate that we're running
_isRunning = true;
// Signal that the stream has changed
OnDeviceChanged();
// If the thread isn't alive, start it now
if (_parsingThread == null
#if !PocketPC
|| !_parsingThread.IsAlive
#else
|| !_IsParsingThreadAlive
#endif
)
{
_parsingThread = new Thread(ParsingThreadProc)
{
IsBackground = true,
Priority = _threadPriority,
Name = "GPS.NET Parsing Thread (http://dotspatial.codeplex.com)"
};
_parsingThread.Start();
// And signal the start
OnStarted();
}
else
{
// Otherwise, allow parsing to continue
_pausedWaitHandle.Set();
// Signal that we've resumed
OnResumed();
}
}
catch (Exception ex)
{
// Close the device
_device.Close();
// Show that we're stopped
OnStopped();
// Report the problem
throw new InvalidOperationException("The interpreter could not be started. " + ex.Message);
}
finally
{
// Release the lock
Monitor.Exit(SyncRoot);
}
}
else
{
// Signal a stop
OnStopped();
// The interpreter is already busy
throw new InvalidOperationException("The interpreter cannot be started. It appears that another thread is already trying to start, stop, pause, or resume.");
}
}
示例4: DetectAndStartGPS
void DetectAndStartGPS()
{
try
{
if (Common.AppSettings.Instance.EnableGPS && !string.IsNullOrEmpty(Common.AppSettings.Instance.GPSPort) && Common.AppSettings.Instance.GPSPort.Length > 3)
{
string strComNum = Common.AppSettings.Instance.GPSPort.Substring(3);
int iComNum = -1;
if (!int.TryParse(strComNum, out iComNum))
iComNum = -1;
Devices.DeviceDetectionAttemptFailed += (s, e) =>
{
//
};
Devices.DeviceDetectionCompleted += (s, e) =>
{
try
{
foreach (Device dev in Devices.GpsDevices)
{
SerialDevice sd=dev as SerialDevice;
if (sd != null && (sd.Port == Common.AppSettings.Instance.GPSPort || sd.PortNumber == iComNum))
{
_curDevice = sd;
break;
}
}
if (_curDevice == null)
{
_curDevice = new SerialDevice(Common.AppSettings.Instance.GPSPort);
Devices.Add(_curDevice);
}
}
catch
{
_curDevice = null;
}
bool bGoodDevice = false;
if (_curDevice != null)
{
try
{
_curDevice.Connected += (sd, ed) =>
{
Common.DebugHelper.WriteLine("GPS Device Opened: {0}", Common.AppSettings.Instance.GPSPort);
};
_curDevice.Disconnected += (sd, ed) =>
{
Common.DebugHelper.WriteLine("GPS Device Closed: {0}", Common.AppSettings.Instance.GPSPort);
};
if (!_curDevice.IsOpen)
{
_curDevice.Open();
}
NmeaInterpreter nmea = new NmeaInterpreter();
nmea.PositionChanged += nmea_PositionChanged;
nmea.Start(_curDevice);
bGoodDevice = true;
}
catch (Exception ex)
{
Common.DebugHelper.WriteExceptionToLog("DetectAndStartGPS", ex, true, string.Format("Device found, but error setting up: {0}", Common.AppSettings.Instance.GPSPort));
bGoodDevice = false;
}
}
if (!bGoodDevice)
{
ClearCurrentPosition();
}
};
Devices.AllowBluetoothConnections = false;
Devices.AllowExhaustiveSerialPortScanning = false;
Devices.AllowSerialConnections = true;
Devices.BeginDetection();
}
}
catch
{
_curDevice = null;
}
}
示例5: ButtonCaptureClick
private void ButtonCaptureClick(object sender, RoutedEventArgs e)
{
if (!_isRunning)
{
DeviceItem selectedItem = comboBoxDevice.SelectionBoxItem as DeviceItem;
if (selectedItem == null)
{
_activeDevice = null;
return;
}
_isRunning = true;
_activeDevice = selectedItem.Device;
_activeDevice.PacketCaptured += ActiveDevicePacketCaptured;
_activeDevice.Open(true, 20);
_activeDevice.Start();
buttonCapture.Content = "Stop";
}
else
{
if (_activeDevice == null)
return;
if (!_activeDevice.IsOpen)
return;
try
{
_activeDevice.Stop();
_activeDevice.Close();
}
catch
{}
buttonCapture.Content = "Capture";
_isRunning = false;
}
}
示例6: ButtonScanClick
private void ButtonScanClick(object sender, RoutedEventArgs e)
{
if (_isRunning)
{
_activeDevice.Stop();
_activeDevice.Close();
Host.StopDnsResolver();
buttonScan.Content = "Scan";
_isRunning = false;
return;
}
_foundAddresses.Clear();
_hosts.Clear();
DeviceItem selectedItem = comboBoxDevice.SelectionBoxItem as DeviceItem;
if (selectedItem == null)
{
_activeDevice = null;
return;
}
if (_activeDevice != null && _activeDevice.IsOpen)
{
_activeDevice.Stop();
_activeDevice.Close();
_hosts.Clear();
}
_activeDevice = selectedItem.Device;
_activeDevice.Filter = "arp";
_activeDevice.PacketCaptured += ActiveDevicePacketCaptured;
_activeDevice.Open(true, 20);
_activeDevice.Start();
buttonScan.Content = "Stop";
Host.StartDnsResolver();
_isRunning = true;
Address deviceAddress = _activeDevice.Addresses.First(a => a.IpAddress.AddressFamily == AddressFamily.InterNetwork);
foreach (IPAddress ipAddress in deviceAddress.IpAddress.GetPossibleIpAddresses(deviceAddress.NetMask))
_activeDevice.Send(ArpPacket.CreateArpRequest(_activeDevice.MacAddress, deviceAddress.IpAddress, ipAddress));
}