Sending a data file over a serial bluetooth

mhewett737

Member
Licensed User
Longtime User
I am very new to basic4android.
I have a folder of .dat files on my pc that contain hex byte values that I can send out in std rs232 format to another device which are recieved and used to control electric trains.

I would like to use my Galaxy 2 to send these data files over bluetooth to a bbluetooth to rs232 adapter to this train device.

I am struggling to read these data files with a RAF and send them out as byte streams through bluetooth.
Can some one get me started how you would attack this problem.

Thanks in advance
 

mhewett737

Member
Licensed User
Longtime User
Erel,

Changed to a different terminal program.

Same result

First button push sends data succesfully. If I try to send another without
closing then reopening the port no data is recieved and I get the following message on the tablet:

" java io.IOexception : socket closed.
Am i possibly unknowingly closing the socket in my code??
 
Upvote 0

mhewett737

Member
Licensed User
Longtime User
' ++++++++++++++++++++ BUTTON CLICKS ARE DIRECTED TO THE FOLLOWING CODE TO READ DATA FROM A FILE AND THEN OUTPUT OVER SERIAL BLUETOOTH++++++

Sub getcommand
Dim vararr(length) As Byte
raf.initialize(File.DirRootExternal,dirname,False)
count = raf.ReadBytes (arr,0,50,raf.CurrentPosition)

For j = offset To count
vararr(j-offset) = arr(j)
If arr(j)= 77 Then
j = count
End If
Next
AStreams.Initialize(Null,serial1.OutputStream,"AStreams")
AStreams.Write(vararr)
raf.flush
raf.close

End Sub
 

Attachments

  • traincontrolrev5.zip
    13.2 KB · Views: 183
Upvote 0

mhewett737

Member
Licensed User
Longtime User
when I put the asyn cinitialize statement any where else in the program
I get a null error exception

Where should I put it ?
 
Upvote 0

mhewett737

Member
Licensed User
Longtime User
Erel,
Sorry for being such a dummy on this .

I have used a couple of rs232 terminals with the same results.
I dont have the hardware yet to test on the train computer so I am using these terminal softwares to ensure I am sending the correct data.

But each time I send a data stream. I need to open and close the port on the PC in the terminal program before I can send the next stream or I get a java io error : socket closed.

I am sending data ie 55 55 85 85 55 4a ........ 4d 4d is the last byte that tells my train computer that it is the end of data.

THe data transmitss perfectly but I cant send the next command until I close and reopen the terminal port.

If this is just a peculurarity of terminal programs ? If the last byte was a "0"
would the terminal program then reconfigure for the next data stream ?


Grasping at straws to understand whats going on.

Mike
 
Upvote 0

mhewett737

Member
Licensed User
Longtime User
Once I figured out what a Serial event was and looked at serial event code on the onlineforum I found the right place to put the async initialize statement . Seems to be working ok.

Thanks for your help
 
Upvote 0

mhewett737

Member
Licensed User
Longtime User
Erel,

Now that I have accomplished sending serial data to a bluetooth device I need to learn how to send it to a WIFI transciever that has a rs232 output.
I am attaching my bluetooth zip file program.

I have been going through your NET tutorials but am significantly overwhelmed.
Can you tell me if where there are simple code changes needed to convert the Async output to Async wifi serial out. I am assuming the best method for me is TCP as opposed to UDP ??
Thanks again in advance.
 

Attachments

  • bluetoothtraincontrol.zip
    13.7 KB · Views: 252
Upvote 0
Top