clinkerman32
Posts: 3
Joined: Thu May 31, 2007 4:27 am

NSBASIC-CE Ascii > 127 how? pls hlp!!

Thu May 31, 2007 4:31 am

I need to recieve and send serial data typically a string like this -
"S3À-²±0.²00ª-±5" So you see this contains standard characters
(ascii 0-127) and Extended characters(ascii 128-255).

With my main program I am struggling to receive the characters
correctly even with NO parity and 8 data bits.
I can send them back out ok from a file transferred thru activesync
to the device but receiving them them via RS232 is proving a problem.
I have not used 'StringtoByteArray' or reverse in any of my coding
yet but I suspect I need this, but I really dont understand how a
byte array is contructed so I put this test code together which just
receives on com1 and displays to a text box.

I'm really struggling to get the received data into a format that I
can save to file.

Has anybody done this before? I searched the form without anything
conclusive.
I'll post the result if I can get this into a little demo file to
send/receive binary.

Sorry about the long post.....Thanks Anybody

Sub CommandButton1_Click
Dim myvar,newinputdata,mybyte,mystr
'setup port here
objport.noevents = True
ObjPort.ComPort = 1
objport.Baudrate = 4800
objport.bytesize = 8 '8 databits
ObjPort.Parity = 0 'Parity None
ObjPort.StopBits = 0 '1stop bit
ObjPort.Handshake = 0 ' no handshake
'objport.buffersize = 1
'open the port
objport.enabled = True

Do
DoEvents
newinputdata = objport.read(1,0)
textbox1.Text = textbox1.Text & newinputdata
'REALLY GOT LOST IN THIS BIT
'mybyte = objport.stringtobytearray(newinputdata)
'
'textbox1.Text = textbox1.Text & Asc(mybyte(0))
'
'mystr = objport.bytearraytostring(mybyte)
'textbox1.Text= textbox1.Text & mystr
Loop
End Sub

clinkerman32
Posts: 3
Joined: Thu May 31, 2007 4:27 am

RE: NSBASIC-CE Ascii > 127 how? pls hlp!!

Fri Jun 01, 2007 7:07 pm

Managed to sort it in a way that contradicts the way I understand the documentation.
Converted Input Data to Byte array using StringToByteArray then built a string from the array using chr() in a loop and I get the extended characters I expected to see.
Switched to using Events bye the way for this next sub code.
Since no help was forthcoming here I hope this helps others with the same issue.
Regards Keith

Sub objport_OnRead(NewInputData)
Dim i, mybyte,mystr

'convert to Byte array otherwise characters>127 are lost
mybyte = objport.stringtobytearray(newinputdata)

'change to extended character set string
'ByteArrayToString does not do this the same way
'Don't quite understand why but I can see whats happening my way!!

For i = 0 To UBound(mybyte)
mystr = mystr & Chr(mybyte(i))
Next

'add to text box
textbox1.Text = textbox1.Text & mystr

End Sub

Return to “SerialTools”