Example #1
0
/* Open the given serial port using the given port number.
 * "/dev/ttySxx" port name are assumed. */
int serialPortOpen(int portNum, int dataRate, int stopBitsType, int parityType, int dataBits,
		   int inFlowCtrl, int outFlowCtrl, int xOnChar, int xOffChar)
{	
  char serialPortName[PORT_NAME_SIZE];
  make_portname_from_portnum(serialPortName, portNum);
      
  return serialPortOpenByName(serialPortName, dataRate, stopBitsType, parityType, dataBits,
			      inFlowCtrl, outFlowCtrl, xOnChar, xOffChar);
}
Example #2
0
EXPORT(sqInt) primitiveSerialPortOpenByName(void) {
	char * cString;
	char *deviceName;
	sqInt baudRate;
	sqInt stopBitsType;
	sqInt parityType;
	sqInt dataBits;
	sqInt inFlowControl;
	sqInt outFlowControl;
	sqInt xOnChar;
	sqInt xOffChar;
	char *p;
	sqInt len;
	sqInt terminatedString;

	interpreterProxy->success(interpreterProxy->isBytes(interpreterProxy->stackValue(8)));
	deviceName = ((char *) (interpreterProxy->firstIndexableField(interpreterProxy->stackValue(8))));
	baudRate = interpreterProxy->stackIntegerValue(7);
	stopBitsType = interpreterProxy->stackIntegerValue(6);
	parityType = interpreterProxy->stackIntegerValue(5);
	dataBits = interpreterProxy->stackIntegerValue(4);
	inFlowControl = interpreterProxy->stackIntegerValue(3);
	outFlowControl = interpreterProxy->stackIntegerValue(2);
	xOnChar = interpreterProxy->stackIntegerValue(1);
	xOffChar = interpreterProxy->stackIntegerValue(0);
	if (interpreterProxy->failed()) {
		return null;
	}
	/* begin allocateTerminatedString: */
	len = interpreterProxy->sizeOfSTArrayFromCPrimitive(deviceName);
	terminatedString = interpreterProxy->instantiateClassindexableSize(interpreterProxy->classString(), len + 1);
	p = interpreterProxy->arrayValueOf(terminatedString);
	p[len] = 0;
	while (len >= 0) {
		len -= 1;
		p[len] = (deviceName[len]);
	}
	cString = p;
	serialPortOpenByName(
			cString, baudRate, stopBitsType, parityType, dataBits,
			inFlowControl, outFlowControl, xOnChar, xOffChar);
	if (interpreterProxy->failed()) {
		return null;
	}
	interpreterProxy->pop(9);
	return null;
}
primitiveSerialPortOpenByName(void)
{
	// SerialPlugin>>#primitiveSerialPortOpenByName
	sqInt baudRate;
	sqInt dataBits;
	sqInt inFlowControl;
	sqInt outFlowControl;
	sqInt parityType;
	char *port;
	char *portName;
	sqInt portNameSize;
	sqInt stopBitsType;
	sqInt xOffChar;
	sqInt xOnChar;

	success(isBytes(stackValue(8)));
	portName = ((char *) (firstIndexableField(stackValue(8))));
	baudRate = stackIntegerValue(7);
	stopBitsType = stackIntegerValue(6);
	parityType = stackIntegerValue(5);
	dataBits = stackIntegerValue(4);
	inFlowControl = stackIntegerValue(3);
	outFlowControl = stackIntegerValue(2);
	xOnChar = stackIntegerValue(1);
	xOffChar = stackIntegerValue(0);
	if (failed()) {
		return null;
	}
	portNameSize = slotSizeOf(((int) portName) - 4);
	port = calloc(portNameSize+1, sizeof(char));
	memcpy(port, portName, portNameSize);
	serialPortOpenByName(
			port, baudRate, stopBitsType, parityType, dataBits,
			inFlowControl, outFlowControl, xOnChar, xOffChar);
	free(port);
	if (failed()) {
		return null;
	}
	pop(9);
	return null;
}