June 2018 Update
This commit is contained in:
parent
ba8067c3b7
commit
22f33d4004
5278 changed files with 84726 additions and 14379 deletions
|
|
@ -0,0 +1,23 @@
|
|||
mutable struct NinePinSerialPort
|
||||
pins::BitArray
|
||||
function NinePinSerialPort()
|
||||
this = new()
|
||||
this.pins = BitArray(9)
|
||||
end
|
||||
end
|
||||
|
||||
const CD = 1
|
||||
const RD = 2
|
||||
const TD = 3
|
||||
const SG = 5
|
||||
const DSR = 6
|
||||
const RTS = 7
|
||||
const CTS = 8
|
||||
|
||||
# Here we test the type's code.
|
||||
port = NinePinSerialPort()
|
||||
println("Port is now at defaults, which are $port")
|
||||
port[CTS] = true
|
||||
println("CD pin of port, which is pin $CD, is now $(port[CD])")
|
||||
println("CTS pin of port, which is pin $CTS, is now $(port[CTS])")
|
||||
println("port is now: $port")
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
object Rs232Pins9 extends App {
|
||||
|
||||
val (off: Boolean, on: Boolean) = (false, true)
|
||||
val plug = new Rs232Pins9(carrierDetect = on, receivedData = on) // set first two pins, say
|
||||
|
||||
def toOnOff(b: Boolean) = if (b) "on" else "off"
|
||||
|
||||
class Rs232Pins9(
|
||||
var carrierDetect: Boolean = off,
|
||||
var receivedData: Boolean = off,
|
||||
var transmittedData: Boolean = off,
|
||||
var dataTerminalReady: Boolean = off,
|
||||
var signalGround: Boolean = off,
|
||||
var dataSetReady: Boolean = off,
|
||||
var requestToSend: Boolean = off,
|
||||
var clearToSend: Boolean = off,
|
||||
var ringIndicator: Boolean = off
|
||||
) {
|
||||
def setPin(n: Int, v: Boolean) {
|
||||
(n) match {
|
||||
case 1 => carrierDetect = v
|
||||
case 2 => receivedData = v
|
||||
case 3 => transmittedData = v
|
||||
case 4 => dataTerminalReady = v
|
||||
case 5 => signalGround = v
|
||||
case 6 => dataSetReady = v
|
||||
case 7 => requestToSend = v
|
||||
case 8 => clearToSend = v
|
||||
case 9 => ringIndicator = v
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// println(toOnOff(plug.component2())) // print value of pin 2 by number
|
||||
plug.transmittedData = on // set pin 3 by name
|
||||
plug.setPin(4, on) // set pin 4 by number
|
||||
// println(toOnOff(plug.component3())) // print value of pin 3 by number
|
||||
println(toOnOff(plug.dataTerminalReady)) // print value of pin 4 by name
|
||||
println(toOnOff(plug.ringIndicator)) // print value of pin 9 by name
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue