Need to look look at Character instead of Strings

apstrojny2

Member
Licensed User
Longtime User
Hi Folks,

I listed 4 items below I'm confused on?

I borrowed the network stream code from the Chit Chat Demo...
And I have tried to figure out the way to do the following but it is not happening...

1) Problem:
I need a way to look at the network stream data I receive on a characters by character or bytes by byte basis instead of looking at the buffer as a string???

See the server I'm connecting with sends out a Username: and Password: requests that I have to reply "Write" to... It also will send .png graphic files that have to be stored in cRandom binary mode but I need to find a certain flag 'PNG' and switch over to save mode...
How do I access the data and look for a U S E R N A M E : see depending on the time tick the first time I look and search the buffer as a string I could get
U S E R.... and the next tick I look at the buffer I get N A M E :.. Hence I miss the USERNAME: That is why I'd like to sift though the receive buffer on a character by character basis...
Also the system sends extra text back that is really not necessary to view I would like to sift the return and save to a file only the important info I want...


-------Start of Code Fragment----------

MY Code in SubTICK
Sub Timer1_Tick

'Stop Timer event as we are in Timer event'
timer1.Enabled = False

'Test if Data is available from Duats Server'
If client.DataAvailable = True Then

'Got Data from Duats Server reset TimeOut'
LnkToutTmr = LnkToutMax 'Decrement Link Time Out Timer

'Since Data is available

'HelpHere I really Don't understand why I cant Parse This buffer'
'bufferbits Character by Character byte by Byte...'
'vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv'
count = stream.ReadBytes(bufferbits(),8192)
buffer = bit.BytesToString(bufferbits(),0,count)
'^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^'

Select RcvState

'If State = 1 Look for Nam(e:)
Case 0
RcvState = 0

Case 1
'Since State = 1 Test if Buffer contains String name(e:)'
If -1 < StrIndexOf (buffer, "e:",0) Then
'Since it Does Write Access Name to Duats Sever'
txtACode.Text = AccessCode
stream.WriteBytes (stream.StringToBytes(txtACode.text & Chr(10)))

'Change State to 2 = Look For Passwor(d:)'
RcvState = 2
End If

------------End Code Fragment--------------

2) Problem:
I'd like to be-able to flush the Stream receive buffer etc???

3) Problem:

Could someone explain what the following items do???
'HelpHere Not Sure what this is doing but doing it'
bit.new1

'HelpHere Not sure what this does but Doing it'
client.New1

'HelpHere Not Sure what this is doing but doing it'
stream.New1(client.GetStream,False)
 

apstrojny2

Member
Licensed User
Longtime User
Hi Taximania,
To answer your question...

[Do you know how to add b4p libraries to a project and access the
properties from the libraries ?]

I did include the network.dll, binaryfile.dll and bit.dll both for the desk top and device for this project... But to be honest I don't really know much about objects accessing properties or these dll's or why I need to initialize the object type.... And I really don't know where to get an explaination about what I'm doing... Most of the Help or Tutorials assumes the highly informed user and just seems to explains syntax... If I try to get the additional library .zips I get no access allowed not sure why... So I'm left with cutting and pasting code from examples and demos...

I'm open to any suggestions...

Andy
Newbie
 

taximania

Well-Known Member
Licensed User
Longtime User
1. Additional libraries are for registered paid members only.

2. B4p has a lot of built in features. 'Serial' for instance, isn't built in.

To use serial features.
Add the serial2 library, Tools /Components
and give it a name, Tools/Add Object eg: ser

Now in your application App_Start sub, you can type 'ser' and a list of serial
options will be available.

'New1' will be an option. Click it.

Your code will now read ser.New1
That is a new instance of the serial library.
All the other 'ser' options can now be used in your code.

Just for the record, serial2 also has a New2, that is
ser.New2(port as int32, BitRate as int32, parity as string, databits as int32, stopbits as single) eg:
ser.New2(1,4800,"N",8,0)

Using this option saves you 5 lines of code, eg:
ser.new1
ser.port=1
ser.BitRate=4800
ser.parity="N"
ser.databits=8
ser.stopbits=0

Lot's of other libraries may be similiar. New1, New2, New3 etc


All other libraries, Hardware, Network etc need to be added this way if
you want to use the features in that library.

Hope this helps a bit :)
 
Last edited:
Top