public static uint CreateDevice(DEVICE_TYPE mDeviceType, out Device device) { device = null; Device newDevice = new Device(mDeviceType); uint result = newDevice.OpenDevice(); if (result != (uint)CAN_RESULT.SUCCESSFUL) { Logger.Info(string.Format("create device[{0}] failed.", newDevice.GetDeviceName())); return(result); } result = newDevice.ReadBoardInfo(); if (result != (uint)CAN_RESULT.SUCCESSFUL) { Logger.Info(string.Format("create device[{0}] failed.", newDevice.GetDeviceName())); return(result); } newDevice.InitCAN(newDevice.CANNum); device = newDevice; Logger.Info(string.Format("create device[{0}] successful.", newDevice.GetDeviceName())); return(result); }
public static string FindDeviceTypeKey(DEVICE_TYPE mDeviceType) { if (mDeviceType == DEVICE_TYPE.UNKNOWN) { return(DEVICE_TYPE_UNKNOWN); } return(FindKey(mDeviceType, DEVICE_TYPE_LIST)); }
/////////////////////////////////////////////////////////////////////////////////////////// private Device(DEVICE_TYPE mDeviceType) { this.m_DeviceType = mDeviceType; this.m_DeviceTypeDesc = CAN.FindDeviceTypeKey(mDeviceType); this.m_DeviceIndex = DeviceGroup.CreateInstance().GetNewDeviceIndex(mDeviceType); this.m_IsDeviceOpen = false; this.p_DeviceInfo = new BOARD_INFO(); }
private void btnOpenDevice_Click(object sender, EventArgs e) { string deviceTypeDesc = cbxSelectDevice.SelectedValue.ToString(); DEVICE_TYPE deviceType = (DEVICE_TYPE)CAN.DEVICE_TYPE_LIST[deviceTypeDesc]; //DEVICE_TYPE deviceType = (DEVICE_TYPE)Enum.Parse(typeof(DEVICE_TYPE), cbxSelectDevice.SelectedValue.ToString()); Device newDevice = null; if (device == null) { Logger.Info("try to open a new device"); newDevice = CreateDevice(deviceType); if (newDevice == null) { MessageBox.Show("打开设备失败。"); return; } device = newDevice; UpdateControls(); return; } if (device.DeviceType == deviceType) { if (!device.IsDeviceOpen) { Logger.Info(string.Format( "try to re-open an old device: [{0}-{1}]", device.DeviceTypeDesc, device.DeviceIndex)); device.OpenDevice(); return; } Logger.Info(string.Format("device already opened: [{0}-{1}]", device.DeviceTypeDesc, device.DeviceIndex)); return; } if (device.IsDeviceOpen) { Logger.Info(string.Format( "try to open another device, close the old device firstly: [{0}-{1}]", device.DeviceTypeDesc, device.DeviceIndex)); device.CloseDevice(); } Logger.Info("try to open a new device"); newDevice = CreateDevice(deviceType); if (device == null) { MessageBox.Show("打开设备失败。"); return; } device = newDevice; UpdateControls(); }
private static string GetDefaultDeviceName(DEVICE_TYPE deviceType) { if (deviceType == DEVICE_TYPE.VIDEO) { return(Preferences.Instance.mVideoDeviceName); } if (deviceType == DEVICE_TYPE.AUDIO) { return(Preferences.Instance.mAudioDeviceName); } return(null); }
private Device CreateDevice(DEVICE_TYPE deviceType) { Device device = null; // get new device index UInt32 deviceIndex = p_DeviceGroup.GetNewDeviceIndex(deviceType); // create new device if (Device.CreateDevice(deviceType, out device) == (uint)CAN_RESULT.SUCCESSFUL) { return(device); } return(null); }
public Device GetDevice(DEVICE_TYPE deviceType, UInt32 deviceIndex) { if (deviceType == DEVICE_TYPE.UNKNOWN) { return(null); } lock (locker) { foreach (Device device in devices) { if (device.DeviceType == deviceType && device.DeviceIndex == deviceIndex) { return(device); } } return(null); } }
/// <summary> /// Update sensor device information of Ev3 Brick by GetSensors command. /// </summary> /// <param name="Command">GetSensors command.</param> /// <param name="Brick">Object to set data.</param> public override void Update(ACommand Command, Ev3Brick Brick) { Debug.Assert(Command != null); Debug.Assert(Brick != null); if (Command is Command_0E_00) { int Index = 0; int DataTopIndex = 4; for (Index = 0; Index < 4; Index++) { var Device = Brick.SensorDevice(Index); Device.ConnectedPort = (Ev3Device.INPORT)Index; DEVICE_TYPE DeviceType = DEVICE_TYPE.SENSOR_DEVICE_NO_DEVICE; byte Type = Command.ResData[DataTopIndex + Index]; bool HasValue = DeviceTypeDictionary.ContainsKey(Type); if (HasValue) { DeviceType = DeviceTypeDictionary[Type]; } else { DeviceType = DEVICE_TYPE.SENSOR_DEVICE_UNKNOWN; } Device.DeviceType = DeviceType; switch (DeviceType) { case DEVICE_TYPE.SENSOR_DEVICE_ULTRASONIC: case DEVICE_TYPE.SENSOR_DEVICE_GYRO: case DEVICE_TYPE.SENSOR_DEVICE_TOUCH: case DEVICE_TYPE.SENSOR_DEVICE_COLOR: case DEVICE_TYPE.SENSOR_DEVICE_HT_NXT_ACCEL: case DEVICE_TYPE.SENSOR_DEVICE_NXT_TEMP: Device.IsConnected = true; break; default: Device.IsConnected = false; break; } } } }
/// <summary> /// Update motor device information of Ev3 Brick by GetMotors command. /// </summary> /// <param name="Command">GetMotors command.</param> /// <param name="Brick">Object to set data.</param> public override void Update(ACommand Command, Ev3Brick Brick) { Debug.Assert(Command != null); Debug.Assert(Brick != null); if (Command is Command_0C_00) { int Index = 0; int DataTopIndex = 4; for (Index = 0; Index < 4; Index++) { var Device = Brick.MotorDevice(Index); Device.ConnectedPort = (Ev3Device.OUTPORT)Index; DEVICE_TYPE DeviceType = DEVICE_TYPE.MOTOR_DEVICE_NO_DEVICE; byte Type = Command.ResData[DataTopIndex + Index]; bool HasValue = DeviceTypeDictionary.ContainsKey(Type); if (HasValue) { DeviceType = DeviceTypeDictionary[Type]; } else { DeviceType = DEVICE_TYPE.MOTOR_DEVICE_UNKNOWN; } Device.DeviceType = DeviceType; switch (DeviceType) { case DEVICE_TYPE.MOTOR_DEVICE_MEDIUM_MOTOR: case DEVICE_TYPE.MOTOR_DEVICE_LARGE_MOTOR: case DEVICE_TYPE.MOTOR_DEVICE_UNADJUSTED: Device.IsConnected = true; break; default: Device.IsConnected = false; break; } } } }
public static DsDevice GetDevice(Guid FilterCategory, DEVICE_TYPE deviceType) { string[] deviceNames = GetDeviceNameList(FilterCategory); if (deviceNames == null) { return(null); } foreach (string deviceName in deviceNames) { Console.WriteLine(deviceName); } // まずオプションの設定値を取得する string optionDeviceName = ""; foreach (string deviceName in deviceNames) { string defaultDeviceName = GetDefaultDeviceName(deviceType); if (deviceName == defaultDeviceName) { optionDeviceName = deviceName; break; } } if (!string.IsNullOrEmpty(optionDeviceName)) { DsDevice device = GetDeviceByName(FilterCategory, optionDeviceName); if (device != null) { return(device); } } // オプションの設定値が現在の選択肢に無ければ機器選択ウィンドウを表示する ChooseDeviceWindow chooseDeviceWindow = new ChooseDeviceWindow(deviceNames, deviceType); chooseDeviceWindow.ShowDialog(); string choosedDeviceName = chooseDeviceWindow.mDeviceName; return(GetDeviceByName(FilterCategory, choosedDeviceName)); }
public UInt32 GetNewDeviceIndex(DEVICE_TYPE deviceType) { List <UInt32> indexList = new List <uint>(); lock (locker) { foreach (Device device in devices) { if (device.DeviceType == deviceType) { indexList.Add(device.DeviceIndex); } } UInt32 newIndex = 0; while (indexList.Contains(newIndex++)) { ; } return(--newIndex); } }
public Query(DEVICE_TYPE d, string s, string p) { mDeviceType = d; mSelect = s; mProperty = p; }
protected string processInfo(DEVICE_TYPE type, string value) { if (type == DEVICE_TYPE.DT_ORIGINAL_MAC) { return(getNetID()); } else if (type == DEVICE_TYPE.DT_HDD) { if (value.Length == 40) // InterfaceType = "IDE" { // 需要将16进制编码串转换为字符串 byte[] szBuf = new byte[32]; bool ret = true; for (int i = 0; i < 20; ++i) { // 将16进制字符转换为高4位 byte ch = (byte)value[i * 2]; byte b; if ((ch >= '0') && (ch <= '9')) { b = (byte)(ch - '0'); } else if ((ch >= 'A') && (ch <= 'F')) { b = (byte)(ch - 'A' + 10); } else if ((ch >= 'a') && (ch <= 'f')) { b = (byte)(ch - 'a' + 10); } else { // 非法字符 ret = false; break; } b <<= 4; // 将16进制字符转换为低4位 ch = (byte)value[i * 2 + 1]; if ((ch >= '0') && (ch <= '9')) { b += (byte)(ch - '0'); } else if ((ch >= 'A') && (ch <= 'F')) { b += (byte)(ch - 'A' + 10); } else if ((ch >= 'a') && (ch <= 'f')) { b += (byte)(ch - 'a' + 10); } else { // 非法字符 ret = false; break; } szBuf[i] = b; } if (ret) { // 转换成功 szBuf[20] = 0; value = Encoding.Default.GetString(szBuf); } } // 每2个字符互换位置 char[] tempArray = value.ToCharArray(); for (int i = 0; i < tempArray.Length; i += 2) { if (i + 1 >= tempArray.Length) { break; } char temp = tempArray[i]; tempArray[i] = tempArray[i + 1]; tempArray[i + 1] = temp; } value = new string(tempArray); // 去掉空格 value = value.Replace(" ", ""); // 移除末尾所有的0 int len = value.Length; for (int i = 0; i < value.Length; ++i) { if (value[i] == 0) { len = i; break; } } value = value.Substring(0, len); return(value); } else if (type == DEVICE_TYPE.DT_CUR_MAC) { return(value.Replace(":", "")); } else { return(value.Replace(" ", "")); } }
IEnumerator Start() { yield return(null); // VRTKのSDKオートロードはせずに手動セットアップ string vrSystem = ApplicationSetting.Instance.GetString("VRSystem"); int sdkIndex = (int)DEVICE_TYPE.OCULUS; if (vrSystem.ToLower() == "oculus") { Debug.Log("select VR System [ Oculus ]"); sdkIndex = (int)DEVICE_TYPE.OCULUS; deviceType = DEVICE_TYPE.OCULUS; } else if (vrSystem.ToLower() == "vive") { Debug.Log("select VR System [ VIVE ]"); sdkIndex = (int)DEVICE_TYPE.VIVE; deviceType = DEVICE_TYPE.VIVE; } try { VRTK_SDKManager.instance.TryLoadSDKSetup(sdkIndex, true, VRTK_SDKManager.instance.setups); } catch (Exception e) { Debug.LogError(e.Message); yield break; } // デバイス初期化に時間がかかるため、各デバイスのエイリアスが取得できるまで確認ループ while (!AllDeviceIsReady()) { yield return(null); // 初期化完了待機 1フレ後に以下取得を確認 // リグRoot vrRig = VRTK_DeviceFinder.PlayAreaTransform(); // ヘッドセット headset = VRTK_DeviceFinder.HeadsetCamera(); // 初期化時 左コントローラー → 右コントローラー の認識順 leftControllerReference = VRTK_DeviceFinder.GetControllerReferenceLeftHand(); GameObject leftHand = VRTK_DeviceFinder.GetControllerLeftHand(false); if (leftHand != null) { leftControllerEvents = leftHand.GetComponent <VRTK_ControllerEvents>(); } if (leftControllerEvents != null) { leftControllerRoot = leftControllerEvents.transform.parent.gameObject; if (deviceType == DEVICE_TYPE.OCULUS) { leftControllerModel = leftControllerRoot.transform.Find("LeftControllerAnchor").gameObject; } else if (deviceType == DEVICE_TYPE.VIVE) { leftControllerModel = leftControllerRoot.transform.Find("Model").gameObject; } } rightControllerReference = VRTK_DeviceFinder.GetControllerReferenceRightHand(); GameObject rightHand = VRTK_DeviceFinder.GetControllerRightHand(false); if (rightHand != null) { rightControllerEvents = rightHand.GetComponent <VRTK_ControllerEvents>(); } if (rightControllerEvents != null) { rightControllerRoot = rightControllerEvents.transform.parent.gameObject; if (deviceType == DEVICE_TYPE.OCULUS) { rightControllerModel = rightControllerRoot.transform.Find("RightControllerAnchor").gameObject; } else if (deviceType == DEVICE_TYPE.VIVE) { rightControllerModel = rightControllerRoot.transform.Find("Model").gameObject; } } } isReady = true; yield break; }
public static uint CTL_CODE(DEVICE_TYPE deviceType, ushort function, METHOD method, FILE_ACCESS access) { return (uint) ((((((uint) deviceType) << 0x10) | (((byte) access) << 14)) | (function << 2)) | ((long) method)); }
public static uint CTL_CODE(DEVICE_TYPE deviceType, ushort function, IOMethod method, IOAccess access) => CTL_CODE((ushort)deviceType, function, (byte)method, (byte)access);