public static ErrorCode DiRead(int port, out byte data) { instantDiCtrl.SelectedDevice = _device; instantDoCtrl.SelectedDevice = _device; data = 0; byte[] datas = new byte[] { 0 }; return(instantDiCtrl.Read(0, 1, datas)); }
/// 读取整个8位数据 /// </summary> /// <returns></returns> public byte ReadByte() { byte data; DiInstance.Read(0, out data); return(data); }
/// <summary> /// Internal Update Loop /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void UpdateLoop(object sender, DoWorkEventArgs e) { do { if (LoopInterval == -1) { return; } try { ErrorCode errorCode = ErrorCode.Success; BoolInput[] boolInputs = RecursiveFilterByType <BoolInput>(); byte[] buffer = new byte[64]; // Step 3: Read DI ports' status and show. errorCode = instantDiCtrl.Read(0, 1, buffer); if (BioFailed(errorCode)) { U.LogError("Advantech DigInput failed"); } //Show ports' status int n = 1; for (int i = 0; i < boolInputs.Length; i++) { boolInputs[i].Value = (buffer[0] & n) != 0; n <<= 1; } } catch (Exception ex) { U.LogError(ex, "Advantech DigInput failed"); } U.SleepWithEvents(LoopInterval); } while (!_destroy); }
/// <summary> /// Подрограмма считывания данных из порта /// </summary> /// <param name="port">Имя порта</param> /// <returns></returns> public byte ReadPort(int port) { byte value; if (!IsInit) { // Модуль не инициализирован throw new Exception <Pci1753ExceptionArgs>(new Pci1753ExceptionArgs(0), "The object of card Pci1753 is not initialized"); } if (port < 0 || port >= ChannelCountMax) { // Номер канала задан неверно throw new Exception <Pci1753ExceptionArgs>(new Pci1753ExceptionArgs(0), $"The port {port} of card Pci1753 is not valid"); } var error_code = InstantDiCtrl.Read(port, out value); if (error_code != ErrorCode.Success) { // Возникла ошибка throw new Exception <Pci1753ExceptionArgs>(new Pci1753ExceptionArgs(0), $"Ошибка чтения байта данных из порта {port:D} интерфейсной платы PCI-1753 - {error_code}"); } return(value); }
public bool Read(int port, out byte currentData, out byte oldData) { oldData = InputPortState[port]; bool ret = _di.Read(port, out currentData) == ErrorCode.Success; InputPortState[port] = currentData; return(ret); }
public byte[] StartDiMode(DAQNaviHelper.DelegateDiChangeEvent e) { ErrorCode err = instantDiCtrlUsb4704.Read(0, out byte portData); if (err != ErrorCode.Success) { ActiveEventError("开启数字输入失败:" + err.ToString()); return(arrDiData); } EventDiChange = e; timerDi.Enabled = true; arrDiData = new byte[8]; for (int i = 0; i < arrDiData.Length; i++) { arrDiData[i] = Convert.ToByte((portData >> i) & 0x01); } return(arrDiData); }
//研华输入卡PCI1754刷新输入 /// <summary> /// 研华输入卡PCI1754刷新输入 /// </summary> /// <returns>返回输入信号数组【数组长度64】:true - ON; false - OFF</returns> public bool[] GetInputStatus() { //initial the return value for (int a = 0; a < 64; a++) { ReadInStatus[a] = false; } if (SuccessBuiltNew == false) { //MessageBox.Show("未成功建立类的新实例,无法开启线程进行输入信号扫描"); ErrorMessage = "未成功建立类的新实例,无法开启线程进行输入信号扫描"; return(ReadInStatus); } try { for (int Port = 0; Port <= 7; Port++) { if (NeedFormControlFlag == true) { TargetPCI1754Card.Read(Port, out PortData); } else { TargetDICard.DiRead(Port, out PortData); } for (int Bit = 0; Bit <= 7; Bit++) { ReadInStatus[Port * 8 + Bit] = ((PortData >> Bit) == 1) ? true : false; } } return(ReadInStatus); } catch (Exception ex) { ErrorMessage = ex.Message; return(ReadInStatus); } }
public async Task <(string, byte[])> ReadInputs() { try { errorCode = await Task <string> .Run(() => advantechDIControl.Read(startPort, portCount, buffer)); OnInputsRead(this, errorCode.ToString(), buffer); } catch (Exception e) { CommunicationLogChanged?.Invoke($"Advantech read exception {e.Message} !\n"); } return(errorCode.ToString(), buffer); }
public LongmenDevice(IPort port, ISerialize serialize) : base(port, serialize) { _device = new DeviceInformation(((PortBase)port).Port); _instantDoCtrl = new InstantDoCtrl(); _instantDoCtrl.SelectedDevice = _device; _instantDiCtrl = new InstantDiCtrl(); _instantDiCtrl.SelectedDevice = _device; byte[] data = new byte[4]; _instantDoCtrl.Write(0, data.Length, data); _option = default(eLongMenOption); _instantDiCtrl.Read(0, data.Length, data); Status = (eLongMenState)BitConverter.ToUInt32(data, 0); }
public override int Read() { if (disposed) { return(0); } ErrorCode ret = ctrl_in.Read(portStart, portCount_in, buf_in); if (ret != ErrorCode.Success) { throw new Exception("Board1730.Read: Ошибка: " + ret.ToString()); } values_in = BitConverter.ToInt32(buf_in, 0); return(values_in); }
void GetStatus() { // read Di port state byte portData = 0; ErrorCode err = ErrorCode.Success; for (int i = 0; (i + m_startPort) < instantDiCtrl1.Features.PortCount && i < m_portCountShow; ++i) { err = instantDiCtrl1.Read(i + m_startPort, out portData); if (err != ErrorCode.Success) { //timer1.Enabled = false; HandleError(err); return; } m_HtDicPortToValue[(i + m_startPort).ToString()] = portData.ToString("X2"); // m_portNum[i].Text = (i + m_startPort).ToString(); //m_portHex[i].Text = portData.ToString("X2"); //加入设备状态变化的列表 if (i == 1) { if (tdrs == null) { VM_TDRSInfo tdrs = new VM_TDRSInfo(); } tdrs.HeadingDirection = (Direction)Enum.Parse(typeof(Direction), Config.TrainDirection); tdrs.PortInfo = portData.ToString("X2"); tdrs.InputDiInfo = tdrs.InputDiInfo; tdrs.CREATED = DateTime.Now; bool flag = false; flag = STSEventLogManage.Instance.AddEventLog(tdrs); tdrs.MSStatus(tdrs.InputDiInfo); if (flag) { //信号产生变化后,通知外部 IDIInputInfo(); } } // Set picture box state for (int j = 0; j < 8; ++j) { //m_pictrueBox[i, j].Image = imageList1.Images[(portData >> j) & 0x1]; //m_pictrueBox[i, j].Invalidate(); } } }
public List <bool> ReadDigitalInputs() { List <bool> output = new List <bool>(); byte data; ErrorCode code = instantDiCtrl.Read(DIGITAL_INTPUT_PORT_NO, out data); if (code != ErrorCode.Success) { Logger.Log(this, String.Format("Reading digital input failed! Error code: {0}", code.ToString()), 3); } for (int i = 0; i < 8; i++) { bool currBit = data % 2 == 1; output.Add(currBit); data >>= 1; } return(output); }
public override Int32 Read(Int32 PORTx) { lock (syscReadObject) { if (!isDoInitialized) { return(0); } try { Byte data = 0; m_di.Read(PORTx, out data); return((Int32)data); } catch { //ex.ToString(); return(0); } } }
//Skeniranje i konverzija stanja I/O modula public void ScanStates() { forceRefresh(); try { #region Inputs byte portData = 0; ErrorCode err = ErrorCode.Success; err = instantDiCtrl1.Read(0, out portData); if (err != ErrorCode.Success) { HandleError(err); return; } ChStates_port0 = convertToArr(portData); InputStateCh0 = convertToString(portData); err = ErrorCode.Success; err = instantDiCtrl1.Read(1, out portData); if (err != ErrorCode.Success) { HandleError(err); return; } ChStates_port1 = convertToArr(portData); InputStateCh1 = convertToString(portData); #endregion Inputs #region Outputs portData = 0; byte portDir = 0xFF; err = ErrorCode.Success; byte[] mask = instantDoCtrl1.Features.DoDataMask; err = instantDoCtrl1.Read(ConstVal.StartPort, out portData); if (err != ErrorCode.Success) { HandleError(err); return; } if (instantDoCtrl1.Ports != null) { portDir = (byte)instantDoCtrl1.Ports[ConstVal.StartPort].DirectionMask; } ChOutputStates_port0 = convertToArr(portData); Array.Reverse(ChOutputStates_port0); string outStats = new string(ChOutputStates_port0); OutputStateCh0 = convertToString(portData); #endregion } catch { //Console.WriteLine("Error scanning states"); Globals.pCol.writeLog(1, "Error scanning states", ""); } }
public byte ReadDiState(int port) { DiReader.Read(port, out stateDIFromRead); return(stateDIFromRead); }
public void UpdateStaticDI() { //----------------------------------------------------------------------------------- // Configure the following parameters before running the demo //----------------------------------------------------------------------------------- //The default device of project is demo device, users can choose other devices according to their needs. string deviceDescription = "PCI-1750,BID#0"; string profilePath = "../../profile/PCI-1750.xml"; int startPort = 0; int portCount = 2; short fullResponse = 0; StaticIO_firstTime = true; ErrorCode errorCode = ErrorCode.Success; // Step 1: Create a 'InstantDiCtrl' for DI function. InstantDiCtrl instantDiCtrl = new InstantDiCtrl(); try { // Step 2: Select a device by device number or device description and specify the access mode. // in this example we use ModeWrite mode so that we can fully control the device, including configuring, sampling, etc. instantDiCtrl.SelectedDevice = new DeviceInformation(deviceDescription); errorCode = instantDiCtrl.LoadProfile(profilePath);//Loads a profile to initialize the device. if (BioFailed(errorCode)) { throw new Exception(); } // read DI ports' status and show. //Console.WriteLine("Reading ports' status is in progress..., any key to quit!\n"); byte[] buffer = new byte[64]; //byte data = 0;//data is used to the API ReadBit. //int bit = 0;//bit is used to the API ReadBit. // Step 3: Read DI ports' status and show. errorCode = instantDiCtrl.Read(startPort, portCount, buffer); //errorCode = instantDiCtrl.ReadBit(startPort, bit, out data); if (BioFailed(errorCode)) { throw new Exception(); } //Show ports' status for (int i = 0; i < portCount; ++i) { if (_showVerboseMessage) { Console.WriteLine(" DI port {0} status : 0x{1:x}\n", startPort + i, buffer[i]); } /************************************************************************/ //Console.WriteLine(" DI port {0} status : 0x{1:x}\n", startPort + i, data); //NOTE: //argument1:which port you want to control? For example, startPort is 0. //argument2:which bit you want to control? You can write 0--7, any number you want. //argument3:data is used to save the result. /************************************************************************/ } fullResponse = (short)(buffer[0] | buffer[1] << 8); extractAndsetNum(fullResponse); //Thread.Sleep(100); } catch (Exception e) { // Something is wrong string errStr = BioFailed(errorCode) ? " Some error occurred. And the last error code is " + errorCode.ToString() : e.Message; Console.WriteLine(errStr); } finally { // Step 4: Close device and release any allocated resource. instantDiCtrl.Dispose(); //Console.ReadKey(false); } }