1

I want to send strings between the raspberry and a windows computer via serial and with c#. This works from the raspberry to the computer as shown below. In the picture you can see that I have sent a string from the raspberry to the computer and that the computer has received this correctly.

String sent from raspberry. Raspberry program. String received on raspberry computer. Computer program.

But if I want to send a string to the raspberry I get back that the command does not exist. And on the raspberry itself I don't see the string as shown below. Send string from computer. Computer program. String not received on the raspberry. Raspberry program.

So my question is how can I send a string from the computer and receive it correctly on the raspberry.

This is the code that the string must receive on the raspberry.

private void serialPort1_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
    dataIN = serialPort1.ReadExisting();
    this.Invoke(new EventHandler(ShowData));
}

EDIT

I am now trying with python but I do not receive it EXCEPT I click send very quickly and I occasionally receive a string. Very strange...

import serial
import sys
from time import sleep

try:
  ser = serial.Serial("/dev/ttyS0", 9600,timeout=0, parity=serial.PARITY_NONE, 
                    stopbits=serial.STOPBITS_ONE, bytesize=serial.EIGHTBITS)
except:
  sys.exit("Error connecting device")

while True:
  queue = ser.inWaiting()
  if queue > 0:
    data = ser.read(1000)
    print data
  sleep(0.2)

Thanks in advance!

  • Comments are not for extended discussion; this conversation has been moved to chat. – goldilocks Jan 27 at 15:48
  • Have you disabled the console on the Pi serial port? If not, you need to do that. – goldilocks Jan 27 at 15:54
  • No, I haven't done that yet. How should I do that? – floriskn Jan 27 at 17:07
  • I also found on the internet that the SerialDataReceivedEventArgs does not work via mono, but I could not find a solution for this. – floriskn Jan 27 at 17:16
0

You need to disable the serial console. It runs a login shell, which is probably what is responding to your string (although you seem to have bypassed the login, and it is odd you are not having junk on the receiving end).

You can do this via raspi-config (under "Interfacing Options" -> "Enable/Disable shell and kernel messages..."), or manually:

https://raspberrypi.stackexchange.com/search?q=disable+serial+console+

| improve this answer | |
  • It was already disabled so that is not the problem. – floriskn Jan 27 at 18:13
  • I'll leave this here so no one else wastes time repeating it. There's then something wrong with the receiver code on the Pi that it somehow ends up engaging a shell. That autoresponse/error is not from the OS or the serial port, it's from bash, meaning at some point the code pipes it to a shell or tries to execute your string in a shell. – goldilocks Jan 27 at 19:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.