static int prSerialPort_Close(struct VMGlobals *g, int numArgsPushed)
{
	PyrSlot* self = g->sp;
	SerialPort* port = (SerialPort*)getSerialPort(self);
	if (port == 0) return errFailed;
	port->stop();
	return errNone;
}
Example #2
0
static int prSerialPort_RXErrors(struct VMGlobals *g, int numArgsPushed)
{
	PyrSlot* self = g->sp;
	SerialPort* port = (SerialPort*)getSerialPort(self);
	if (port == 0) return errFailed;
	SetInt(self, port->rxErrors());
	return errNone;
}
Example #3
0
static int prSerialPort_Open(struct VMGlobals *g, int numArgsPushed)
{
	PyrSlot *args = g->sp - 1 - SerialPort::kNumOptions;

	int err;

	PyrSlot* self = args+0;

	if (getSerialPort(self) != 0)
		return errFailed;

	char portName[PATH_MAX];
	err = slotStrVal(args+1, portName, sizeof(portName));
	printf("portName %s\n", portName);
	if (err) return err;

	SerialPort::Options options;
	SerialPort* port = 0;

	options.exclusive = IsTrue(args+2);

	int baudrate;
	err = slotIntVal(args+3, &baudrate);
	if (err) return err;
	options.baudrate = baudrate;

	int databits;
	err = slotIntVal(args+4, &databits);
	if (err) return err;
	options.databits = databits;

	options.stopbit = IsTrue(args+5);

	int parity;
	err = slotIntVal(args+6, &parity);
	if (err) return err;
	options.parity = (SerialPort::Parity)parity;

	options.crtscts = IsTrue(args+7);
	options.xonxoff = IsTrue(args+8);

	try {
		port = new SerialPort(slotRawObject(self), portName, options);
	} catch (SerialPort::Error& e) {
		std::ostringstream os;
		os << "SerialPort Error: " << e.what();
		post(os.str().c_str());
		return errFailed;
	}

	SetPtr(slotRawObject(self)->slots+0, port);

	return errNone;
}
static int prSerialPort_Cleanup(struct VMGlobals *g, int numArgsPushed)
{
	PyrSlot* self = g->sp;
	SerialPort* port = (SerialPort*)getSerialPort(self);

	if (port == 0) return errFailed;

	port->cleanup();

	post("SerialPort Cleanup\n");

	delete port;
	SetNil(slotRawObject(self)->slots+0);
	return errNone;
}
Example #5
0
static int prSerialPort_Next(struct VMGlobals *g, int numArgsPushed)
{
	PyrSlot* self = g->sp;
	SerialPort* port = (SerialPort*)getSerialPort(self);
//	printf( "port %i", port );
	if (port == 0) return errFailed;

	uint8_t byte;
	if (port->get(&byte)) {
		SetInt(self, byte);
	} else {
		SetNil(self);
	}

	return errNone;
}
Example #6
0
static int prSerialPort_Cleanup(struct VMGlobals *g, int numArgsPushed)
{
	PyrSlot* self = g->sp;
	SerialPort* port = (SerialPort*)getSerialPort(self);

	if (port == 0) return errFailed;
	if (port->isCurrentThread()) {
		post("Cannot cleanup SerialPort from this thread. Call from AppClock thread.");
		return errFailed;
	}

	port->cleanup();

	post("SerialPort Cleanup\n");

	delete port;
	SetNil(slotRawObject(self)->slots+0);
	return errNone;
}
Example #7
0
static int prSerialPort_Put(struct VMGlobals *g, int numArgsPushed)
{
	PyrSlot *args = g->sp - 1;

	PyrSlot* self = args+0;
	SerialPort* port = (SerialPort*)getSerialPort(self);
	if (port == 0) return errFailed;

	PyrSlot* src = args+1;

	int val;
	if (IsChar(src)) {
		val = slotRawChar(src);
	} else {
		int err = slotIntVal(src, &val);
		if (err) return err;
	}

	bool res = port->put(val & 0xFF);
	SetBool(self, res);

	return errNone;
}
Example #8
0
//Byte empfangen
unsigned int serial_read(unsigned char comport) {
	unsigned short base = getSerialPort(comport);
	
	while (!serial_received(base)) { }
	return inb(base);
}
Example #9
0
//Ob man lesen kann
unsigned int serial_received(unsigned char comport) {
	unsigned short base = getSerialPort(comport);
	
	return inb(base+LSR)&1;
}
Example #10
0
//Byte senden
void serial_write(unsigned char comport, unsigned char chr) {
	unsigned short base = getSerialPort(comport);
	
	while (is_transmit_empty(base)==0) { }
	outb(base, chr);
}