We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpOther Libraries › "enter" as a string
Page Index Toggle Pages: 1
"enter" as a string? (Read 339 times)
"enter" as a string?
Jan 7th, 2009, 12:02pm
 
Hi everyone,

I'm trying to use Processing to make a conection to the propellor chip(parallax). Now, the propellor-object i use is expecting an "enter" signal after a number. This signal would be 13 as a string. well, that's at least what i thought. The Serial answer to it is something like: "$r 1§$!& §
I guess that's kind of a swearing. It's not the baudrate and the programming of the chip, as everything is working with the terminal.
This is the Processing code i'm using for the testing:

import processing.serial.*;

Serial myPort;  // Create object from Serial class
int val;      // Data received from the serial port

void setup()
{
 size(200, 200);

 String portName = Serial.list()[2];
 myPort = new Serial(this, portName, 9600);
 println(Serial.list());
 delay(1000);
 
}

void draw()
{
 String enter = "13";
   while (myPort.available() > 0) {
     
     myPort.write(100);
     myPort.write(enter);
     println("did send it"+ enter);
     
     String inBuffer = myPort.readString();  
     if (inBuffer != null) {
       println(inBuffer);
     }
     delay(1000);
   }
}

so the code starts writing (after lots of delays to make shure that everything is ready). The spin code on the other side is just listening and, when getting something, writing back what it gets. as i said it's working on the terminal, and i guess i just kind of don't send the enter signel correctly.

anybody got ann idea?

cheers
Re: "enter" as a string?
Reply #1 - Jan 7th, 2009, 12:23pm
 
String enter = "13"; doesn't do what you think it does. "enter" or newline is ASCII 13, "13" is the string one three, they're completely different.

What you want is: String enter="\n";
Re: "enter" as a string?
Reply #2 - Jan 7th, 2009, 12:37pm
 
I just figured out that it's not the sending, but seems to be the opening of the port...

if i just simply say:

if (myPort.available() > 0){
  println("gogogo!");
}

it doesn't do anything at the first time. in case i disconnect and connect again i just get just bad things from the chip like:

œ4m”¶h”œ<m”¶h”œ4m”¶h”œ4m”¶h”œ4m”–h”œ<m”–h”œ4m”–h”œ4m”–h”œ4m”–h”¶h”–h”œ4m”–h”œÚ”–
h”œÚ”–

but constantly! (sounds like klingonian)

any idea?
cheers
Re: "enter" as a string?
Reply #3 - Jan 7th, 2009, 12:41pm
 
@ John:

I tried this before but also didn't work. kind of nothing worked. but as i just figured out, it seems to be the opening of the port. i know from arduino, that it allways takes a while till it opens (at least it was like this ~one yeahr ago). but i'm already waiting for 20seconds and when than getting impatient and disconnecting + connecting i get this chaos...
Page Index Toggle Pages: 1