ISRRX.readstr

Coding and general discussion relating to the compiler

Moderators: David Barker, Jerry Messina

Post Reply
lothar
Posts: 14
Joined: Wed Apr 25, 2007 4:10 pm
Location: Hull

ISRRX.readstr

Post by lothar » Sun Jul 22, 2007 7:33 pm

Hi Guys,

I am trying to display a string of 81 characters on my screen. I am currently trying to use the following:

Code: Select all

While ISRRX.DataAvailable
   
     ISRRX.ReadStr(INPUTSTRING)

'separate variables and display at diffent positions on screen   

Wend
I am then attempting to then seperate the string into the variable lengths i wish to display on the screen within the while wend statement.

Code: Select all

WriteAt(150,1,INPUTSTRING(0),INPUTSTRING(1),INPUTSTRING(2),INPUTSTRING(3),INPUTSTRING(4),INPUTSTRING(5),"       ")
I am getting garbage on the screen and was hopeful someone would spot the flaw in my method. I have successfully used the USART.writebyte(ISRRX.read) and the string is correct. is there a better way to do this?

Thanks for any help

Lothar

User avatar
David Barker
Swordfish Developer
Posts: 1214
Joined: Tue Oct 03, 2006 7:01 pm
Location: Saltburn by the Sea, UK
Contact:

Post by David Barker » Sun Jul 22, 2007 7:54 pm

The RX buffer in ISRRX is by default 64 characters, that may be your problem. Set to a different size by using

Code: Select all

#option RX_BUFFER_SIZE = 82
include "isrrx.bas"
Also, by default readstr() assumes a null terminator char in the input stream. Ensure this is so, or set explicitly

Code: Select all

ISRRX.ReadStr(Str,13)

lothar
Posts: 14
Joined: Wed Apr 25, 2007 4:10 pm
Location: Hull

Post by lothar » Mon Jul 23, 2007 10:51 am

Hi David,

Made the changes to the buffer and tried the following code;

Code: Select all

While ISRRX.DataAvailable
      ISRRX.ReadStr(INPUTSTRING,13) 
      WriteAt(150,1,INPUTSTRING(0),INPUTSTRING(1),INPUTSTRING(2),INPUTSTRING(3),INPUTSTRING(4),INPUTSTRING(5),"       ")         
      WriteAt(150,21,INPUTSTRING(7),INPUTSTRING(8),INPUTSTRING(9),INPUTSTRING(10),INPUTSTRING(11),INPUTSTRING(12),"       ")         
      WriteAt(150,41,INPUTSTRING(14),INPUTSTRING(15),INPUTSTRING(16),INPUTSTRING(17),INPUTSTRING(18),INPUTSTRING(19),"       ")     
      WriteAt(150,61,INPUTSTRING(21),INPUTSTRING(22),INPUTSTRING(23),INPUTSTRING(24),INPUTSTRING(25),"   ",INPUTSTRING(26),"         ")     
      WriteAt(150,81,INPUTSTRING(28),INPUTSTRING(29),INPUTSTRING(30),INPUTSTRING(31),INPUTSTRING(32),"   ",INPUTSTRING(33),"         ")     
      WriteAt(150,101,INPUTSTRING(35),INPUTSTRING(36),INPUTSTRING(37),INPUTSTRING(38),INPUTSTRING(39),INPUTSTRING(40),"       ")    

      WriteAt(150,121,INPUTSTRING(42),INPUTSTRING(43),INPUTSTRING(44),INPUTSTRING(45),INPUTSTRING(46),INPUTSTRING(47),"       ")    

      WriteAt(150,141,INPUTSTRING(49),INPUTSTRING(50),INPUTSTRING(51),INPUTSTRING(52),INPUTSTRING(53),INPUTSTRING(54),"       ")    

      WriteAt(150,161,INPUTSTRING(56),INPUTSTRING(57),INPUTSTRING(58),INPUTSTRING(59),INPUTSTRING(60),INPUTSTRING(61),"       ")    

      WriteAt(150,181,INPUTSTRING(63),INPUTSTRING(64),INPUTSTRING(65),INPUTSTRING(66),INPUTSTRING(67),INPUTSTRING(68),"       ")    

      WriteAt(150,201,INPUTSTRING(70),INPUTSTRING(71),INPUTSTRING(72),INPUTSTRING(73),INPUTSTRING(74),INPUTSTRING(75),"       ")    

      WriteAt(150,221,INPUTSTRING(77),INPUTSTRING(78),INPUTSTRING(79),INPUTSTRING(80),"     ") 
Wend
I am getting garbage on the screen. I have tried to echo the string back without success however I can echo the bytes back using:

Code: Select all

USART.Write(ISRRX.ReadByte)
However if I use this method I must fill the string byte by byte and so far this has not been successful.

I will persist with this one but it is most frustrating, any tips welcome!

Best regards

Lothar

User avatar
David Barker
Swordfish Developer
Posts: 1214
Joined: Tue Oct 03, 2006 7:01 pm
Location: Saltburn by the Sea, UK
Contact:

Post by David Barker » Mon Jul 23, 2007 10:59 am

It's really hard to tell without seeing a more complete code example of the problem - I assume you are dimensioning you string correctly?

lothar
Posts: 14
Joined: Wed Apr 25, 2007 4:10 pm
Location: Hull

Post by lothar » Mon Jul 23, 2007 12:32 pm

I have set up the following code as a smaller test case. The screen outputs information regardless of whether it is good or not, shows as rubbish. However when sent the correct length it shows this data as intended. If I add '#option RX_BUFFER_SIZE = 82 and try again I do not get anything. could the buffer limitations be giving me the headache and is there a way to only write to screen if the data is what I expect to see? I have tried sending a dollar sign and comparing the first bit in the array with "$" if they match then I send the data. As yet this did nothing.

Code: Select all

Device = 18f4620
Clock = 20

#option GLCD_MODEL = S1D13700    // set model 
#option GLCD_MODE = 6800 
#option GLCD_TCR = $2B 
#option GLCD_A0 = PORTB.0'PORTB.2        // A0 pin 
#option GLCD_RW = PORTB.1        // WR pin 
#option GLCD_EN = PORTB.2        // RD pin 
#option GLCD_DATA = PORTD        // data port 
#option GLCD_CS = PORTB.3        // chip select 
#option GLCD_RES = PORTB.5       // reset pin 
'#option RX_BUFFER_SIZE = 82 

Include "glcd.bas"
Include "dungeon.bas"
Include "convert.bas"
Include "utils.bas"
Include "shift.bas"
Include "USART.bas"
Include "ISRRX.bas"

Dim test As String(10)
Dim mode As Byte

// RX OnData() event...
Sub OnData()
   // ignore CR and LF...
   If ISRRX.DataByte = 36 Then'Or ISRRX.DataByte = 10 Then
     mode = 1
   EndIf
End Sub

USART.SetBaudrate(br19200)
ISRRX.Initialize(@OnData)

Initialize()

Cls(1) 
SetFont(Dungeon) 
Pen.Color = 1 
Brush.Color = 0 
Pen.mode = 0 
Brush.Style = 1

initialisation:

WriteAt (50,55,"Initialisation Routine")

MAIN:

USART.Write("S")

Data:
Cls(1)
While ISRRX.DataAvailable
        ISRRX.ReadStr(test,13)
Wend
 
    WriteAt(150,1,test(0),test(1),test(2),test(3),"       ")
    WriteAt(150,40,test(4),test(5),test(6),test(7),"       ")
    WriteAt(150,75,test(8),test(9),"       ")
DelayMS(50)
GoTo Data
As usual any thoughts very welcome.

R/

Lothar

User avatar
David Barker
Swordfish Developer
Posts: 1214
Joined: Tue Oct 03, 2006 7:01 pm
Location: Saltburn by the Sea, UK
Contact:

Post by David Barker » Mon Jul 23, 2007 1:05 pm

The problem here is that the complete string has not been received before you try and read it using 'ReadStr' - the routine never finds the line terminator and so your program will fail. You need to give the ISRRX module time to buffer the data. The following program illustrates how to do this:

Code: Select all

device = 18F452
clock = 20

include "usart.bas"
include "isrrx.bas"
dim Str as string

dim StrReady as boolean
event OnData()
   if ISRRX.DataByte = 13 then
      StrReady = true
   endif   
end event

StrReady = false
SetBaudrate(br19200)
ISRRX.Initialize(OnData)
while true
   if StrReady then
      StrReady = false
      ISRRX.ReadStr(Str,13)
      USART.Write(Str,13)
   endif
wend 
This ensures the line terminator has been received before reading the string. I've also tested the above on a KS0108 and it works as expected.

However, you need to consider your timing requirements for the GLCD you use. If data is coming in at the same time you are outputting to the GLCD, you may encounter problems as the driver timings may be affected when servicing the ISR. In that case, you may need to look at something like

Code: Select all

      ISRRX.Stop
      GLCD.WriteAt(...)
      ISRRX.Start
If data does not arrive when outputting to the GLCD, then you should not have any problems...

lothar
Posts: 14
Joined: Wed Apr 25, 2007 4:10 pm
Location: Hull

Post by lothar » Mon Jul 23, 2007 3:49 pm

Hi David,

I have merged your suggestions into my code and I am pleased to report that it works. I had to stop and start the ISRRX when printing to screen but this seems ok, further tests will follow.

I am also looking for other characters, as mentioned the $ sign. When I have tried this i get the $ sign first in the string. Is there a way to reset the string once I have navigated to the correct part of the code?

best regards

Lothar

User avatar
David Barker
Swordfish Developer
Posts: 1214
Joined: Tue Oct 03, 2006 7:01 pm
Location: Saltburn by the Sea, UK
Contact:

Post by David Barker » Mon Jul 23, 2007 4:02 pm

you could use the on data event to block characters entering the buffer until a $ is seen, if that is what you mean. If you want to clear the buffer, call ISRRX.Reset

Post Reply