--- /dev/null
+package mxread
+import "core:bytes"
+import "core:os"
+import "core:time"
+import "core:fmt"
+import "core:sys/windows"
+
+COM_PORT :: "\\\\.\\COM10"
+main :: proc() {
+ fp, errno := os.open(COM_PORT, os.O_RDWR)
+ if errno != 0 {
+ fmt.println("COM port open failure!", errno);
+ return;
+ }
+ fd := cast(windows.HANDLE)os.fd(fp)
+ dcb: windows.DCB
+ dcb.DCBlength = size_of(type_of(dcb))
+ if !windows.GetCommState(fd, &dcb) {
+ fmt.println("GetCommState failure!", windows.GetLastError());
+ return;
+ }
+
+ dcb.BaudRate = 9600
+ dcb.StopBits = .One
+ dcb.Parity = .None
+ if !windows.SetCommState(fd, &dcb) {
+ fmt.println("GetCommState failure!", windows.GetLastError());
+ return;
+ }
+
+ timeouts: windows.COMMTIMEOUTS
+ timeouts.ReadIntervalTimeout = 50
+ timeouts.ReadTotalTimeoutConstant = 10000
+ timeouts.ReadTotalTimeoutMultiplier = 10
+ timeouts.WriteTotalTimeoutConstant = 2000
+ timeouts.WriteTotalTimeoutMultiplier = 10
+ if !windows.SetCommTimeouts(fd, &timeouts) {
+ fmt.println("SetCommTimeouts failure!", windows.GetLastError());
+ return;
+ }
+
+ /*
+ fmt.println("Telling MSR to reset!")
+ RESET := [2]u8 { 0x1b, 0x61 }
+ _, errno = os.write(fp, RESET[:])
+ time.sleep(time.Second)
+ if errno != 0 {
+ fmt.println("Write failed!", errno)
+ }
+ fmt.println("Telling MSR to blink!")
+ LEDS := [2]u8 { 0x1b, 0x81 }
+ _, errno = os.write(fp, LEDS[:])
+ time.sleep(time.Second)
+ if errno != 0 {
+ fmt.println("Write failed!", errno)
+ }
+ */
+ fmt.println("Reading track data!")
+ READ := [2]u8 {0x1b, 0x72}
+ _, errno = os.write(fp, READ[:])
+ if errno != 0 {
+ fmt.println("Write failed!", errno)
+ } else {
+ buffer: [1024]u8
+ N, nread := 0, 0
+ errno = 0
+ for errno == 0 {
+ N += nread
+ if bytes.index_any(buffer[:N], {0x3f, 0x3f}) >= 0 {
+ break;
+ }
+ nread, errno = os.read(fp, buffer[N:])
+ }
+ fmt.println(cast(string)buffer[4:N])
+ }
+ fmt.println("Success!");
+ os.close(fp)
+}