Did you ever get this working with prefix mode? I am struggling with the exact same thing. I can view the data with prefix disabled, but it crashes (doesn't like the prefix) when using prefix mode. Any tips appreciated.
Did you ever get this working with prefix mode? I am struggling with the exact same thing. I can view the data with prefix disabled, but it crashes (doesn't like the prefix) when using prefix mode. Any tips appreciated.
Shawn
I did get it working. The one thing that was kicking my ass if I remember right was the True/False for BigEndian.
Also I had to look around to set the BPS right. I am sending at 9600 currentlyCode:AStream.InitializePrefix(Main.serial1.InputStream, True, Main.serial1.OutputStream, "AStream")
Here is the PBP side of the Bluetooth TXCode:Incoming= BytesToString(Buffer, 0, Buffer.Length, "ISO8859_1")
Here is the Bluetooth RX side on the Xoom/B4ACode:Send_BT: 'Sends data assembled from control boards and outputs to the XOOM RPM1R=RPM1R+1000 RPM2R=RPM2R+1000',2 RPM3R=RPM3R+1000'1 RPM4R=RPM4R+1000'0 RPM5R=RPM5R+1000 RPM6R=RPM6R+1000 RPM7R=RPM7R+1000 RPM8R=RPM8R+1000 RPM9R=RPM9R+1000 RPM10R=RPM10R+1000 RPM11R=RPM11R+1000 RPM12R=RPM12R+1000 RPM13R=RPM13R+1000 RPM14R=RPM14R+1000 RPM15R=RPM15R+1000 RPM16R=RPM16R+1000 RPM17R=RPM17R+1000 RPM18R=RPM18R+1000 RPM19R=RPM19R+1000 RPM20R=RPM20R+1000 RPM21R=RPM21R+1000 RPM22R=RPM22R+1000 RPM23R=RPM23R+1000 RPM24R=RPM24R+1000 Prefix1=248 Prefix2=0 Prefix3=0 Prefix4=0 RadarTotal=radartotal+1000 debug Prefix1,Prefix2,Prefix3,Prefix4,"R,",dec4 RadarTotal,",",dec4 RPM1R,",",dec4 RPM2R,",",dec4 RPM3R,",",dec4 RPM4R,",",dec4 RPM5R,",",dec4 RPM6R,",",dec4 RPM7R,",",dec4 RPM8R,",",dec4 RPM9R,",",dec4 RPM10R,_ ",",dec4 RPM11R,",",dec4 RPM12R,",",dec4 RPM13R,",",dec4 RPM14R,",",dec4 RPM15R,",",dec4 RPM16R,",",dec4 RPM17R,",",dec4 RPM18R,_ ",",dec4 RPM19R,",",dec4 RPM20R,",",dec4 RPM21R,",",dec4 RPM22R,",",dec4 RPM23R,",",dec4 RPM24R,",",dec4 RPM1R,",",dec4 RPM2R,_ ",",dec4 RPM3R,",",dec4 RPM4R,",",dec4 RPM5R,",",dec4 RPM6R,",",dec4 RPM7R,",",dec4 RPM8R,",",dec4 RPM9R,",",dec4 RPM10R,_ ",",dec4 RPM11R,",",dec4 RPM12R,",",dec4 RPM13R,",",dec4 RPM14R,",",dec4 RPM15R,",",dec4 RPM16R,",",dec4 RPM17R,",",dec4 RPM18R,_ ",",dec4 RPM19R,",",dec4 RPM20R,",",dec4 RPM21R,",",dec4 RPM22R,",",dec4 RPM23R,",",dec4 RPM24R,",","E" 'serout2 lcd,16468,[Prefix,CursorPS,0,dec RPM1T,",",dec RPM2T,",",dec RPM3T,",",dec RPM4T] Return
To make sure I was calculating the Prefix right I found this website that allowed me to type in data and it would calculate the size for meCode:Sub AStream_NewData (Buffer() As Byte) 'Log( BytesToString(Buffer, 0, Buffer.Length, "ISO8859_1")) Dim Incoming As String Dim Start As Int Dim Stop As Int 'sAmount As Int 'LogMessage("INTERFACE", BytesToString(Buffer, 0, Buffer.Length, "ISO8859_1")) Log( BytesToString(Buffer, 0, Buffer.Length, "ISO8859_1")) Incoming= BytesToString(Buffer, 0, Buffer.Length, "ISO8859_1") Start = Incoming.IndexOf("R") Stop = Incoming.IndexOf("E") If ScrId>3 Then '''''''''' If SimSpeedYN="Yes" Then MPH = SimSpeed MaxRPM=(30/PC)*(RS/30)*(MPH)*0.168*(txtMasterPop.text/1000) txtRPM.Text = NumberFormat(MaxRPM,0,1) Else MPH = (Incoming.SubString2(Start +2,Stop -241)) 'If MPH>0 Then MPH=(MPH-1000) '''''''''THis is for hard coded MPH MPH=Radar/MPH txtMPH.Text=NumberFormat(MPH,0,1) MaxRPM=(30/PC)*(RS/30)*(MPH)*0.168*(txtMasterPop.text/1000) txtRPM.Text = NumberFormat(MaxRPM,0,1) 'MPH="0" 'txtMPH.Text=0 ' Else ' MPH="0" ' txtMPH.Text=0 ' txtRPM.Text = 0 'End If End If Log("MPH " & MPH) If EPD>0 Then If MPH>0 Then Row1 = (Incoming.SubString2(Start +7,Stop -236)) Row2 = (Incoming.SubString2(Start +12,Stop -231)) Row3 = (Incoming.SubString2(Start +17,Stop -226)) Row4 = (Incoming.SubString2(Start +22,Stop -221)) txtRow1.Text = NumberFormat(((Row1-1000)/(((30/PC)*(RS/30)*MPH*0.168)*10)),0,2) txtMR1.Text= NumberFormat((((txtRow1.Text*1000)/txtMasterPop.Text)),1,3) txtRow2.Text = NumberFormat(((Row2-1000)/(((30/PC)*(RS/30)*MPH*0.168)*10)),0,2) txtMR2.Text= NumberFormat((((txtRow2.Text*1000)/txtMasterPop.Text)),1,3) txtRow3.Text = NumberFormat(((Row3-1000)/(((30/PC)*(RS/30)*MPH*0.168)*10)),0,2) txtMR3.Text= NumberFormat((((txtRow3.Text*1000)/txtMasterPop.Text)),1,3) txtRow4.Text = NumberFormat(((Row4-1000)/(((30/PC)*(RS/30)*MPH*0.168)*10)),0,2) txtMR4.Text= NumberFormat((((txtRow4.Text*1000)/txtMasterPop.Text)),1,3) Else txtRow1.Text=0 txtMR1.Text=0 txtRow2.Text=0 txtMR2.Text=0 txtRow3.Text=0 txtMR3.Text=0 txtRow4.Text=0 txtMR4.Text=0 End If Dim MPHTest As Short MPHTest=0 txtMPHZ.Text=MPHTest End If If EPD>1 Then Row5 = (Incoming.SubString2(Start +27,Stop -216)) Row6 = (Incoming.SubString2(Start +32,Stop -211)) Row7 = (Incoming.SubString2(Start +37,Stop -206)) Row8 = (Incoming.SubString2(Start +42,Stop -201)) txtRow5.Text = NumberFormat(((Row5-1000)/(((30/PC)*(RS/30)*MPH*0.168)*10)),0,2) txtMR5.Text= NumberFormat((((txtRow5.Text*1000)/txtMasterPop.Text)),1,3) txtRow6.Text = NumberFormat(((Row6-1000)/(((30/PC)*(RS/30)*MPH*0.168)*10)),0,2) txtMR6.Text= NumberFormat((((txtRow6.Text*1000)/txtMasterPop.Text)),1,3) txtRow7.Text = NumberFormat(((Row7-1000)/(((30/PC)*(RS/30)*MPH*0.168)*10)),0,2) txtMR7.Text= NumberFormat((((txtRow7.Text*1000)/txtMasterPop.Text)),1,3) txtRow8.Text = NumberFormat(((Row8-1000)/(((30/PC)*(RS/30)*MPH*0.168)*10)),0,2) txtMR8.Text= NumberFormat((((txtRow8.Text*1000)/txtMasterPop.Text)),1,3) End If end sub
http://mothereff.in/byte-counter
Last edited by Tobias; - 16th March 2013 at 01:22.
Thank You! I will plug away at this and see if I can get it to work.
Shawn
I can't get this to workHoping you can help me! When I run this very simple android program with prefix I get an almost immediate error "Unfortunately, Bluetooth Example has stopped" and the program closes. I am using the Bluetooth chat example to simply display my data in the chat window. I have very limited serial communication experience. With the prefix disabled I get the data as expected, so the communication is good.
This is the Android routine where I switch between prefix or no prefix mode.
I tried a few variations here with no luckCode:Sub Activity_Create(FirstTime As Boolean) Activity.LoadLayout("2") If AStream.IsInitialized = False Then AStream.InitializePrefix(Main.serial1.InputStream, True, Main.serial1.OutputStream, "AStream") ' AStream.Initialize(Main.Serial1.InputStream, Main.Serial1.OutputStream, "AStream") 'NO PREFIX MODE End If txtLog.Width = 100%x End Sub
My code on an 18F4620 with internal 8mhz osc. I assume I have the prefix correct.Code:Sub AStream_NewData (Buffer() As Byte) LogMessage("You", BytesToString(Buffer, 0, Buffer.Length, "UTF8")) ' Incoming= BytesToString(Buffer, 0, Buffer.Length, "ISO8859_1") ' LogMessage("You", BytesToString(Buffer, 0, Buffer.Length, "ISO8859_1")) End Sub
Code:define DEBUG_REG PORTC define DEBUG_BIT 6 define DEBUG_BAUD 9600 define DEBUG_MODE 0 A1 var byte A2 var byte A3 var byte A4 var byte prefix1 var byte prefix2 var byte prefix3 var byte prefix4 var byte A1=11 A2=22 A3=33 A4=44 Prefix1=23 'http://mothereff.in/byte-counter 11,22,33,44,11,22,33,44 Prefix2=0 Prefix3=0 Prefix4=0 main: pause 1000 debug Prefix1,Prefix2,Prefix3,Prefix4,dec2 A1,",",dec2 A2,",",dec2 A3,",",dec2 A4,",",dec2 A1,",",dec2 A2,",",dec2 A3,",",dec2 A4 pause 1000 goto main end
Shawn
Use this line
AStream.InitializePrefix(serial1.InputStream, False, serial1.OutputStream, "AStream")
instead of
AStream.InitializePrefix(Main.serial1.InputStream, True, Main.serial1.OutputStream, "AStream")
The False part I bet fixes your problem.
My very simple working code:
Code:OSCCON=%01110000 ' SET TO 8 MHZ internal oscillator DEFINE OSC 08 ' 8MHZ clock speed DEFINE HSER_BAUD 9600 ' Set baud rate DEFINE HSER_RCSTA 90h DEFINE HSER_CLROERR 1 ' Clear overrun error upon DEFINE HSER_TXSTA 24h ' Set transmit status and control register DEFINE HSER_SPBRG 51 ' 9600 Bauds RPM var word SPEED var word TPS var byte volts var byte adc1 var word adc2 var word prefix1 var byte prefix2 var byte prefix3 var byte prefix4 var byte rpm = 3800 speed = 60 tps = 10 volts = 122 ADC1 = 512 ADC2 = 200 Prefix1 = 22 Prefix2 = 0 Prefix3 = 0 Prefix4 = 0 main: pause 500 hserout [Prefix1,Prefix2,Prefix3,Prefix4,dec5 rpm, dec3 speed, dec3 TPS, dec3 volts, dec4 adc1, dec4 adc2] goto main endCode:Sub Process_Globals Dim AStream As AsyncStreams Dim Incoming As String Dim RPM As Int Dim SPEED As Int Dim TPS As Double Dim VOLTS As Int Dim ADC1 As Int Dim ADC2 As Int End Sub Sub Activity_Create(FirstTime As Boolean) Activity.LoadLayout("2") If AStream.IsInitialized = False Then AStream.InitializePrefix(Main.Serial1.InputStream, False, Main.Serial1.OutputStream, "AStream") End If Update_Display End Sub Sub AStream_NewData (Buffer() As Byte) Log( BytesToString(Buffer, 0, Buffer.Length, "ISO8859_1")) Incoming = BytesToString(Buffer, 0, Buffer.Length, "ISO8859_1") RPM = (Incoming.SubString2(0,5)) SPEED = (Incoming.SubString2(5,8)) TPS = (Incoming.SubString2(8,11)) VOLTS = (Incoming.SubString2(11,14)) ADC1 = (Incoming.SubString2(14,18)) ADC2 = (Incoming.SubString2(18,22)) Update_Display End Sub
Shawn
Bookmarks