title: Märklin Model Railway Control: ComPort - read dumped bytes from track detection modules / Win Power Shell
body: <p>I would like to test some functions of my Märklin Digital model railway system. Basically it consists of a (Märklin) Central Unit and an (Märklin) Interface. This is the minimum configuration to send system commands from PC via ComPort to the Interface to set solenoids or control trains. Also information can be sent back from track detection modules via Interface ComPort to the PC. In this case two bytes are sent back. For this case an example in Basic is given in the instructions and I tried to translate it to Win Power Shell.</p>
  <p>Basic example:</p>
  <pre><code>10 OPEN &quot;COM1:2400,N,8,2&quot;FOR OUTPUT AS #1
  20 OPEN &quot;COM1:2400,N,8,2&quot;FOR INPUT AS #2
  10 OPEN &quot;COM1:2400,N,8,2&quot;FOR OUTPUT AS #1
  20 OPEN &quot;COM1:2400,N,8,2&quot;FOR INPUT AS #2
  30 PRINT #1,CHR$(193);:a$=INPUT$(2,#2)
  30 PRINT #1,CHR$(193);:a$=INPUT$(2,#2)
  40 contact=ASC(LEFT$(a$,1)):PRINT contact
  50 contact2=ASC(RIGHT$(a$,1)):PRINT contact2
  </code></pre>
  <p>My &quot;translation&quot;:</p>
  <p><code>$connectionproxy = new-object System.IO.Ports.SerialPort com1</code></p>
  <p><code>$connectionproxy.BaudRate = 2400</code></p>
  <p><code>$connectionproxy.stopbits = &quot;two&quot;</code></p>
  <p><code>$connectionproxy.DataBits = 8</code></p>
  <p><code>$connectionproxy.Parity = &quot;None&quot;</code></p>
  <p><code>$connectionproxy.open()</code></p>
  <p><code>do { $connectionproxy.write([char]([int]193)) $ShowBytes = $connectionproxy.ReadLine() Write-Host $ShowBytes } while($connectionproxy.IsOpen)</code></p>
  <p>Problem: I am not able to safe in a file / show data which has been requested from the detection modules.</p>
  <p>What is wrong / missing in my translation?</p>