public virtual void setDirection(PORT_NUMBER port, DIRECTION_ALL direction) { lock (this) { string portStr = string.Empty; switch (port) { case PORT_NUMBER.PORTA: portStr = "!A"; break; case PORT_NUMBER.PORTB: portStr = "!B"; break; case PORT_NUMBER.PORTC: portStr = "!C"; break; } if (direction == DIRECTION_ALL.OUTPUT) { m_direction[0] = 0x0; } else { m_direction[0] = 0xFF; } _serialPort.Write(portStr); _serialPort.Write(m_direction, 0, 1); } }
public virtual void setDirection(PORT_NUMBER portNum, byte direction) { for (int i = 0; i < 3; i++) { if (((1 << i) & (int)portNum) == (int)portNum) { int pnum = (int)portNum; pnum = (pnum >> i) & 0x1; switch (i) { case 0: WriteDirection('A', direction); //set Port A to initialise A/D Board break; case 1: WriteDirection('B', direction); //set Port B to input break; case 2: WriteDirection('C', direction); //set Port C to input break; } } } }
unsafe public virtual void Write(PORT_NUMBER portNum, byte value) { try { switch (portNum) { case PORT_NUMBER.PORTA: m_writeValue[0] = value; WriteValue('A', value); //set Port A to initialise A/D Board break; case PORT_NUMBER.PORTB: m_writeValue[1] = value; WriteValue('B', value); //set Port B to input break; case PORT_NUMBER.PORTC: m_writeValue[2] = value; WriteValue('C', value); //set Port C to input break; } } catch (Exception err) { throw (new SystemException(err.Message)); } }
void SetAllInput(PORT_NUMBER port) { int _port = (int)port; if ((_port & 0x1) == 0x1) { CheckBox[] portaChecks = { checkBox32, checkBox31, checkBox30, checkBox29, checkBox28, checkBox27, checkBox26, checkBox25 }; foreach (CheckBox c in portaChecks) { c.Checked = false; } m_ttl.setDirection(PORT_NUMBER.PORTA, DIRECTION.INPUT, 0xFF); } if ((_port & 0x2) == 0x2) { CheckBox[] portbChecks = { checkBox35, checkBox37, checkBox34, checkBox38, checkBox40, checkBox39, checkBox36, checkBox33 }; foreach (CheckBox c in portbChecks) { c.Checked = false; } m_ttl.setDirection(PORT_NUMBER.PORTB, DIRECTION.INPUT, 0xFF); } if ((_port & 0x4) == 0x4) { CheckBox[] portcChecks = { checkBox43, checkBox35, checkBox42, checkBox46, checkBox48, checkBox47, checkBox44, checkBox41 }; foreach (CheckBox c in portcChecks) { c.Checked = false; } m_ttl.setDirection(PORT_NUMBER.PORTC, DIRECTION.INPUT, 0xFF); } }
void SetDirection(CheckBox c, PORT_NUMBER port, byte pin) { if (c.Checked == true) { m_ttl.setDirection(port, DIRECTION.OUTPUT, 0x2); } else { m_ttl.setDirection(port, DIRECTION.INPUT, 0x2); } }
public virtual bool Read(PORT_NUMBER port, byte InputPins, out byte valueRead) { valueRead = 0; string portStr = string.Empty; switch (port) { case PORT_NUMBER.PORTA: portStr = "a"; break; case PORT_NUMBER.PORTB: portStr = "a"; break; case PORT_NUMBER.PORTC: portStr = "a"; break; } _serialPort.Write(portStr); setDirection(port, DIRECTION.INPUT, InputPins); int timeout = 0; while (_serialPort.BytesToRead == 0) { Thread.Sleep(10); if (timeout == 100) { return(false); } timeout++; } if (_serialPort.BytesToRead == 1) { _serialPort.Read(buf, 0, 1); valueRead = buf[0]; Console.WriteLine(buf[0].ToString()); return(true); } else { return(false); } }
unsafe public override void Write(PORT_NUMBER portNum, byte value) { switch (portNum) { case PORT_NUMBER.PORTA: m_writeValue[0] = value; break; case PORT_NUMBER.PORTB: m_writeValue[1] = value; break; case PORT_NUMBER.PORTC: m_writeValue[2] = value; break; } }
public virtual bool Read(PORT_NUMBER port, out byte valueRead) { valueRead = 0; string portStr = string.Empty; switch (port) { case PORT_NUMBER.PORTA: portStr = "a"; break; case PORT_NUMBER.PORTB: portStr = "b"; break; case PORT_NUMBER.PORTC: portStr = "c"; break; } _serialPort.Write(portStr); int timeout = 0; while (_serialPort.BytesToRead == 0) { Thread.Sleep(10); if (timeout == 100) { return(false); } timeout++; } if (_serialPort.BytesToRead == 1) { _serialPort.Read(buf, 0, 1); valueRead = buf[0]; return(true); } else { return(false); } }
public virtual void Write(PORT_NUMBER port, byte value) { string portStr = string.Empty; switch (port) { case PORT_NUMBER.PORTA: portStr = "A"; break; case PORT_NUMBER.PORTB: portStr = "B"; break; case PORT_NUMBER.PORTC: portStr = "C"; break; } _serialPort.Write(portStr); _serialPort.Write(buf, 0, 1); }
public virtual void Write(PORT_NUMBER port, byte writePins, byte value) { setDirection(port, DIRECTION.OUTPUT, writePins); string portStr = string.Empty; switch (port) { case PORT_NUMBER.PORTA: portStr = "A"; break; case PORT_NUMBER.PORTB: portStr = "B"; break; case PORT_NUMBER.PORTC: portStr = "C"; break; } _serialPort.Write(portStr); _serialPort.Write(buf, 0, 1); }
public byte getValue(PORT_NUMBER portNum) { return(m_writeValue[(int)portNum]); }
public override void setDirection(PORT_NUMBER port, DIRECTION_ALL direction) { }
public override void setDirection(PORT_NUMBER port, DIRECTION direction, byte inputPins) { }
public override void Write(PORT_NUMBER port, byte writePins, byte value) { }
public override void setDirection(PORT_NUMBER portNum, byte direction) { }
public override bool ReadPort(PORT_NUMBER port, out byte valueRead) { valueRead = 1; return(true); }
public override bool Read(PORT_NUMBER port, byte InputPins, out byte valueRead) { valueRead = 1; return(true); }