MessagesForMacintosh/SerialHelper.c

85 lines
2.0 KiB
C
Raw Normal View History

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
*/
short serialPort;
OSErr setupDebugSerialPort(short refNum) {
#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;
const unsigned char* nameStr = "\p";
2021-09-11 06:12:19 +00:00
switch (refNum)
{
case aoutRefNum:
nameStr = (const unsigned char*)MODEM_PORT_OUT;
2021-09-11 06:12:19 +00:00
break;
case boutRefNum:
nameStr = (const unsigned char*)PRINTER_PORT_OUT;
2021-09-11 06:12:19 +00:00
break;
default:
return -1;
2021-09-11 06:12:19 +00:00
}
OSErr err;
serialPort = 0;
2021-09-11 06:12:19 +00:00
err = OpenDriver(nameStr, &serialPort);
if (err < 0) return err;
2021-09-11 06:12:19 +00:00
CntrlParam cb2;
cb2.ioCRefNum = serialPort;
cb2.csCode = 8;
cb2.csParam[0] = stop10 | noParity | data8 | baud19200;
err = PBControl ((ParmBlkPtr) & cb2, 0);
if (err < 0) {
return err;
}
return 0;
}
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;
char str2[1024];
2021-09-11 06:12:19 +00:00
sprintf(str2, "%s\n", str);
pb2.ioBuffer = (Ptr) str2;
pb2.ioReqCount = strlen(str2);
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;
}