2021-09-11 06:12:19 +00:00
|
|
|
#include "SerialHelper.h"
|
|
|
|
#include "stdio.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
Read more: http://stason.org/TULARC/os-macintosh/programming/7-1-How-do-I-get-at-the-serial-ports-Communications-and-N.html#ixzz4cIxU3Tob
|
|
|
|
|
|
|
|
Serial implementation:
|
|
|
|
|
|
|
|
https://opensource.apple.com/source/gdb/gdb-186.1/src/gdb/ser-mac.c?txt
|
|
|
|
http://mirror.informatimago.com/next/developer.apple.com/documentation/mac/Devices/Devices-320.html
|
|
|
|
*/
|
2022-02-15 07:23:51 +00:00
|
|
|
|
|
|
|
short serialPort;
|
|
|
|
|
|
|
|
OSErr setupDebugSerialPort(short refNum) {
|
|
|
|
|
2021-12-20 07:54:47 +00:00
|
|
|
#ifdef PROFILING
|
|
|
|
|
|
|
|
// we need to bail on profiling, because the profile watcher will be reading this serial port
|
|
|
|
return;
|
|
|
|
|
|
|
|
#endif
|
2021-09-11 06:12:19 +00:00
|
|
|
#define MODEM_PORT_OUT "\p.AOut"
|
|
|
|
#define PRINTER_PORT_OUT "\p.BOut"
|
|
|
|
// OSErr err;
|
|
|
|
// return err;
|
|
|
|
|
2022-02-07 20:12:50 +00:00
|
|
|
const unsigned char* nameStr = "\p";
|
2021-09-11 06:12:19 +00:00
|
|
|
switch (refNum)
|
|
|
|
{
|
|
|
|
case aoutRefNum:
|
2022-02-07 20:12:50 +00:00
|
|
|
nameStr = (const unsigned char*)MODEM_PORT_OUT;
|
2021-09-11 06:12:19 +00:00
|
|
|
break;
|
|
|
|
case boutRefNum:
|
2022-02-07 20:12:50 +00:00
|
|
|
nameStr = (const unsigned char*)PRINTER_PORT_OUT;
|
2021-09-11 06:12:19 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2022-02-15 07:23:51 +00:00
|
|
|
return -1;
|
2021-09-11 06:12:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
OSErr err;
|
2022-02-15 07:23:51 +00:00
|
|
|
serialPort = 0;
|
2021-09-11 06:12:19 +00:00
|
|
|
err = OpenDriver(nameStr, &serialPort);
|
2022-02-15 07:23:51 +00:00
|
|
|
if (err < 0) return err;
|
|
|
|
|
2021-09-11 06:12:19 +00:00
|
|
|
CntrlParam cb2;
|
|
|
|
cb2.ioCRefNum = serialPort;
|
|
|
|
cb2.csCode = 8;
|
2022-02-24 18:49:33 +00:00
|
|
|
cb2.csParam[0] = stop10 | noParity | data8 | baud19200;
|
2022-02-15 07:23:51 +00:00
|
|
|
|
|
|
|
err = PBControl ((ParmBlkPtr) & cb2, 0);
|
|
|
|
|
|
|
|
if (err < 0) {
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2022-02-17 19:18:44 +00:00
|
|
|
return 0;
|
2022-02-15 07:23:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
OSErr writeSerialPortDebug(short refNum, const char* str)
|
|
|
|
{
|
|
|
|
#ifdef PROFILING
|
|
|
|
|
|
|
|
// we need to bail on profiling, because the profile watcher will be reading this serial port
|
|
|
|
return;
|
|
|
|
|
|
|
|
#endif
|
2021-09-11 06:12:19 +00:00
|
|
|
IOParam pb2;
|
|
|
|
pb2.ioRefNum = serialPort;
|
|
|
|
|
2021-09-21 06:10:57 +00:00
|
|
|
char str2[1024];
|
2021-09-11 06:12:19 +00:00
|
|
|
sprintf(str2, "%s\n", str);
|
|
|
|
pb2.ioBuffer = (Ptr) str2;
|
|
|
|
pb2.ioReqCount = strlen(str2);
|
|
|
|
|
2022-02-15 07:23:51 +00:00
|
|
|
OSErr err = PBWrite((ParmBlkPtr)& pb2, 0);
|
2021-09-11 06:12:19 +00:00
|
|
|
if (err < 0) return err;
|
|
|
|
|
|
|
|
// hangs on Mac512K (write hasn't finished due to slow Speed when we wants to close driver
|
|
|
|
// err = CloseDriver(serialPort);
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|