reinaldo Crespo
reinaldo Crespo

Reputation: 123

Topaz ActiveX LCDWriteString method causes runtime error when writing past LCD vertical limit

I'm trying to write paragraphs of text on Topaz 1x5 LCD screen. Only a few lines will fit so I show a continue button that the signer can click to show next screen and so on until the end of the text to be displayed before collecting the signature.

I get maximum Topaz LCD screen size by calling Method GetLCDSize(). I store maximum vertical size on yMax. I then use method LCDWriteString() to write a line of text at current yPos. yPos gets incremented by the vertical size of the written line. I obtain the size of the line by calling GetLCDStringSize().

I try to make sure not to attempt to write past the end of the LCD screen by checking yPos against yMax but it will still go past that point causing the runtime error.

Here is the function that writes to the LCD screen:

//-----------------------------------------------------------------------------------
//will display a chuck full of words up to the point where display fills up
//method returns the point in aWords where it stoped.
//aWords is an array of words to be written 
METHOD ShowText( aWords, i )
   Local xSize, ySize := 0
   Local cLine    := ''
   Local cTmp     := ''
   Local yPos     := 0

   While ++i <= Len( aWords ) .and. yPos < ( ::yMax - ySize )

      cTmp += aWords[ i ] + ' '
      xSize := nLoWord( ::SigPlus1:GetLCDStringSize( cTmp ) ) //width in LCD pixels of line to be written
      ySize := nHiWord( ::SigPlus1:GetLCDStringSize( cTmp ) ) //height of line in LCD pixels 

      If xSize < ::xMax //if line width does not exceed LCD width

         cLine := cTmp 

      End 

      //if line exceed LCD width or at last word then write line of text on current at yPos
      if xSize >= ( ::xMax-5 ) .OR. i == Len( aWords )  

         xSize := nLoWord( ::SigPlus1:GetLCDStringSize( cLine ) ) 
         ::SigPlus1:LCDWriteString( 0, 2, 0, yPos, xSize, ySize, 0, cLine )

         //advance yPos to next line
         yPos += nHiWord( ::SigPlus1:GetLCDStringSize( cLine ) )
         cLine := ''
         cTmp  := ''

         i += iif( i == Len( aWords ), 0, -1 ) //if not at end, then go back 1 word.

      End 

   End 

RETURN i 

Upvotes: 1

Views: 37

Answers (1)

reinaldo Crespo
reinaldo Crespo

Reputation: 123

I was able to figure out the problem.

It turns out method GetLCDSize() on the ActiveX does not query the actual Topaz hardware connected to the computer. You have to first tell the ActiveX class the size of the LCD in order to be able to query the size. Yes, that does sound stupid, right. Well, that's how Topaz ActiveX works.

You would think Apple has taught us a thing or two about how software should work. Yet, I'm amazed every time I see things like this coming from hardware manufacturers.

Yes, they do offer sample code that helps but I find it badly written and their documentation is out of sync with what's actually available on the ActiveX.

Take a look, for example, at their C# sample for the 1x5 topaz device. On that sample they show how to display 3 lines of text on the screen. The sample repeats the same code for each line. They don't have any idea what loops are for. The sample won't work for 20 lines of text or any text that is not what they have hard coded and is limited to the 3 lines.

Using their sample code and wanting/needing to show 3 full screens of text, they would have to cut and paste the same code over 50 or 60 times.

Upvotes: 0

Related Questions