Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to write to the serial port of the arduino simulated program? #34

Open
Vincent14 opened this issue May 10, 2017 · 1 comment
Open

Comments

@Vincent14
Copy link

Vincent14 commented May 10, 2017

I would to send data over the serial port to the simulated Arduino program, how could I do that?

ping @ponty @Premik @SebastianZug (there is some answer without answer!)

@Premik
Copy link
Contributor

Premik commented May 10, 2017

To access the uart module you need to use so called IRQs. IRQ is basically simavr implementation of the observer pattern .

So to push a byte to uart you call the pysimavr.swig.simavr.avr_raise_irq method.
Something like this might work for simple byte (not tested):

from pysimavr.swig.simavr import avr_raise_irq
import pysimavr.swig.utils as utils

uartInIRQ = avr_io_getirq(avr.backend, utils.AVR_IOCTL_UART_GETIRQ("0") , utils.UART_IRQ_INPUT)
#uartInIRQ = avr.irq.getuart(0, utils.UART_IRQ_INPUT) -- Instead of the above. Only after PR #33 is merged
avr_raise_irq(uartInIRQ, dataByteToSend);

There is a pseudo-code sample with some documentation directly in simavr avr_uart.h source. It seems to get it fully working one also have to wait for XOFF/XON events/IRQs not to overfill the avr's buffer.

edit:
Or you can actually use much higher-level api:pysimavr.uart.Uart.send_string. Which you get using the pysimavr.sim.ArduinoSim.get_serial.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants