FullDuplexSerial issue - help needed
stamped
Posts: 68
I am having an issue receiving data with the FullDuplexSerial. I can upload and download data to my prop through a USB2SER (PropStick?) and all is fine. I can call serial.ser(string("hello from prop!") and my PropTerminal receives the data. I cannot however send any data back to the Propeller with any reliability. I type in the PropTerminal, the lights flash on my USB2SER meaning it is receiving the serial data, but my code is having issues.. My code is as follows:
CON
··· _clkmode = xtal1 + pll16x
··· _xinfreq = 5_000_000
OBJ
··· Serial : "FullDuplexSerial"·
PUB main | rxString, okay
··· ' Time to open the PropTerminal
··· WaitCnt(320_000_000 + Cnt)
··· okay := Serial.start(31, 30, 1, 115200)······ ' The LED turns on..
··· if(okay)
····· ledOn(0)
··· Serial.str(string("Hello from Propeller!!"))····· ' PropTerminal receives my "Hello from Propeller!!"
···
··· repeat until (rxString := Serial.rxcheck) => 0·· ' This fires immediately (if in a repeat block, keeps looping with no data returned)
·
··· Serial.str(string(" RX RECEIVED: "))
··· Serial.str(rxString)·································· ' This value is either nothing, or garbage and is output immediately
return·
---
Alternatively I have tried:
rxString := Serial.rx
But I still have the exact same issue.
CON
··· _clkmode = xtal1 + pll16x
··· _xinfreq = 5_000_000
OBJ
··· Serial : "FullDuplexSerial"·
PUB main | rxString, okay
··· ' Time to open the PropTerminal
··· WaitCnt(320_000_000 + Cnt)
··· okay := Serial.start(31, 30, 1, 115200)······ ' The LED turns on..
··· if(okay)
····· ledOn(0)
··· Serial.str(string("Hello from Propeller!!"))····· ' PropTerminal receives my "Hello from Propeller!!"
···
··· repeat until (rxString := Serial.rxcheck) => 0·· ' This fires immediately (if in a repeat block, keeps looping with no data returned)
·
··· Serial.str(string(" RX RECEIVED: "))
··· Serial.str(rxString)·································· ' This value is either nothing, or garbage and is output immediately
return·
---
Alternatively I have tried:
rxString := Serial.rx
But I still have the exact same issue.
Comments
1) Use Serial.tx(rxString) to echo the single character
2) Use the Extended FullDuplexSerial object from the Object Exchange which acts as a "front end" to FullDuplexSerial and adds several receive routines that handle the reception of strings and numbers for you.
I have tried using the Extended_FDSerial with:
strID := string("c") ' I am not sure what this is meant to be, I guess an Identifier char, so it waits for a 'c'
rxString := Serial.Rxstr(@strID)
Serial.str(string(" RX RECEIVED: "))
Serial.str(@strID)
The function constantly outputs junk (no idea how, it is not even in a repeat block..) on the PropTerminal. So I am not really sure where to go to from here. As a second test, I have written to the COM Port from Java and it also gets a constant stream of junk back from the prop. It gets the "Hello from Propeller", but then constant junk.
CON
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000
OBJ
Serial : "Extended_FDSerial"
PUB main | rxString, okay, strID ' NOTE MAY NEED TO MAKE myString[noparse][[/noparse]50]
' Time to open the PropTerminal
WaitCnt(320_000_000 + Cnt)
okay := Serial.start(31, 30, 0, 115200)
if(okay)
ledOn(0) ' This method turns on a LED.
Serial.str(string("Hello from Propeller!!")) ' Outputs just fine to the PropTerminal and Java
WaitCnt(100_000_000 + Cnt)
strID := string("c") ' Still unsure about this character? Is it a "wait for this char" character for Rxstr?
rxString := Serial.Rxstr(@strID)
Serial.str(string(" RX RECEIVED: "))
'Serial.str(strID) { Commented out and the PropTerminal does nothing when typing "c", Java gets garbage data back when sending "cccCR" on the third send exactly.. the Prop pumps back random data }
dira := %1
outa := 1
WaitCnt(320_000_000 + Cnt)
return
Note, that if I comment out the Serial.Rxstr(@strID) Java and the PropTerminal both receive the " RX RECEIVED" message without any issue.
The 'strID := string("c")' is not needed. I don't know why you have it.
The code now looks like:
repeat
rxString := Serial.Rxstr(strID)
Serial.RxFlush
Serial.str(string(" RX RECEIVED: "))
Serial.str(@strID)
The only issue I have now is that I am not receiving the strID back in Java with ease.. I am just getting a single byte calling Serial.str(@strID). Rather than the string "cat" that I am sending it.
I just tried sending the first index of the 16 byte string (strID[noparse][[/noparse]0]) and I get the full String "cat". I am unsure why though? It is not an array as far as I know (with my limited knowledge)?
Parameters can only be "simple" values, thus "strings" are addressed by - their "address".
strID is an "address"!
It makes no sense now to use the address of this address, as you did in the last line (@strID) (except you wanted to change it, but you won't!)
And note that "RxStr" (oficially) returns no value.
Martin gave good descriptions of his routnes BTW
If your PC program is sending a CR/LF pair, the LF will end up at the beginning of the next string since Rxstr just reads
up through the CR and you might want to check to make sure that the extra character is the LF.