public bool Write(List <int> outputData) { st = device.Connect(1); RshInitPort p = new RshInitPort(); p.operationType = RshInitPort.OperationTypeBit.Write; for (uint i = 0; i < 3; i++) { var bits = Convert.ToString(outputData[Convert.ToInt32(i)], 2); while (bits.Length < 8) { bits = bits.Insert(0, "0"); } bits = InverseString(bits); var byteToSave = Convert.ToByte(bits, 2); p.portAddress = i; p.portValue = byteToSave; st = device.Init(p); if (st != RSH_API.SUCCESS) { return(false); } } return(true); }
public List <int> Read() { st = device.Connect(2); List <int> InputData = new List <int>(); RshInitPort p = new RshInitPort(); p.operationType = RshInitPort.OperationTypeBit.Read; for (uint i = 0; i < 3; i++) { p.portAddress = i; st = device.Init(p); if (st != RSH_API.SUCCESS) { return new List <int>() { 0, 0, 0, 0 } } ; InputData.Add(Convert.ToInt32(p.portValue)); } p.portAddress = 4; st = device.Init(p); if (st != RSH_API.SUCCESS) { return new List <int>() { 0, 0, 0, 0 } } ; InputData.Add(Convert.ToInt32(p.portValue)); return(InputData); }
public List <int> Read() { st = device.Connect(2); List <int> InputData = new List <int>(); RshInitPort p = new RshInitPort(); p.operationType = RshInitPort.OperationTypeBit.Read; for (uint i = 0; i < 3; i++) { p.portAddress = i; st = device.Init(p); if (st != RSH_API.SUCCESS) { return new List <int>() { 0, 0, 0, 0 } } ; var bits = Convert.ToString(p.portValue, 2); while (bits.Length < 8) { bits = bits.Insert(0, "0"); } bits = InverseString(bits); var byteToSave = Convert.ToByte(bits, 2); InputData.Add(byteToSave); } p.portAddress = 4; st = device.Init(p); if (st != RSH_API.SUCCESS) { return new List <int>() { 0, 0, 0, 0 } } ; var bits2 = Convert.ToString(p.portValue, 2); while (bits2.Length < 8) { bits2 = bits2.Insert(0, "0"); } bits2 = InverseString(bits2); var byteToSave2 = Convert.ToByte(bits2, 2); InputData.Add(byteToSave2); return(InputData); }
public bool Connect() { st = device.OperationStatus; //Коннектимся к первой плате st = device.Connect(1); if (st != RSH_API.SUCCESS) { return(false); } st = device.Get(RSH_GET.DEVICE_PORT_INFO, ref bpi); for (int i = 0; i < bpi.confs.Length; i++) { RshInitPort port = new RshInitPort(); port.operationType = RshInitPort.OperationTypeBit.Write; port.portAddress = bpi.confs[i].address; port.portValue = 0x80; st = device.Init(port); //У первой платы все на вывод } //Сбрасываем все порты в 0, но т.к. у нас инверсия то в ff RshInitPort p = new RshInitPort(); p.operationType = RshInitPort.OperationTypeBit.Write; p.portAddress = 0; p.portValue = 0xff; st = device.Init(p); p.portAddress = 1; p.portValue = 0xff; st = device.Init(p); p.portAddress = 2; p.portValue = 0xff; st = device.Init(p); //------------------- //Коннектимся ко второй плате st = device.Connect(2); if (st != RSH_API.SUCCESS) { return(false); } st = device.Get(RSH_GET.DEVICE_PORT_INFO, ref bpi); for (int i = 0; i < bpi.confs.Length; i++) { RshInitPort port = new RshInitPort(); port.operationType = RshInitPort.OperationTypeBit.Write; port.portAddress = bpi.confs[i].address; port.portValue = 0x9B; st = device.Init(port); //У второй платы все на ввод } return(true); }
public bool Write(List <byte> outputData) { st = device.Connect(1); RshInitPort p = new RshInitPort(); p.operationType = RshInitPort.OperationTypeBit.Write; for (int i = 0; i < 3; i++) { var byteToSave = Inverse(outputData[i]); p.portAddress = Convert.ToUInt16(i); p.portValue = byteToSave; st = device.Init(p); if (st != RSH_API.SUCCESS) { return(false); } } return(true); }
/// <summary> /// Получить RshInitPort, созданный на основе текущего GprFileInfo /// </summary> public RshInitPort GetRshInitPort() { var rshPort = new RshInitPort(); rshPort.operationType = RshInitPort.OperationTypeBit.Write; if (Settings.Instance.BPI != null) rshPort.portAddress = Settings.Instance.BPI.ports[0].address; rshPort.portValue = this.pythonSettings.digitalPort; return rshPort; }
private void TryToInitRshPort(Device device, RshInitPort port) { var st = device.Init(port); if (st != RSH_API.SUCCESS) throw new IOException("RSH_API: " + st.ToString() + " :: " + "device.Init(port)"); }
private void InitRshPort(RshInitPort rshPort) { TryToInitRshPort(device, rshPort); }
public void Init(bool TimerChecked, RshInitMemory rshMemory, RshInitPort rshPort, CalibrationProperties calibrationProperties) { Logging.WriteToLog("Connection.Init(...)"); AddCalibration(calibrationProperties); InitRshMemory(rshMemory); InitRshPort(rshPort); }
/// <summary> /// Выполнить подключение к прибору /// </summary> public bool Connect(bool TimerChecked, RshInitMemory rshMemory, RshInitPort rshPort, CalibrationProperties calibrationProperties) { RSH_API st; //Код выполнения операции. bool res = true; Logging.WriteToLog("Connection.Connect(...)"); try { EstablishConnection(); AddCalibration(calibrationProperties); AddBoardPortInfo(); InitRshMemory(rshMemory); InitRshPort(rshPort); Connected = true; Logging.WriteToLog(" the device is connected!"); } catch (IOException e) { Connected = false; st = RSH_API.NET_TCPSOCKETCONNECTFAILED;//(RSH_API)Enum.Parse(typeof(RSH_API), e.Message.Substring(9)); SayGoodBye(st); res = false; } return res; }
public void Connect(bool TimerChecked, RshInitMemory rshMemory, RshInitPort rshPort, CalibrationProperties calibrationProperties) { Connected = connection.Connect(TimerChecked, rshMemory, rshPort, calibrationProperties); if (Processor.Scenario.Any(x => x.GetType() == typeof(ProcessingSynchro))) InitSynchroOperation(rshMemory); }