Re: RS-232 receive data
Posted: Sat Feb 20, 2016 4:16 pm
Ok, sorry: RTFM - the "*" stands for pointer. While I still do not understand why the name of an AllocatedMemory should be a pointer instead of a name of the allocated memory. Anyway, I used NewList in order to save the data received. And it works 50 % but there are two reasons why it should not work.
The µController is sending Printbin 88;x; whereas the 88 stands for "X" and the variable (byte) X contains the Accelerometer value from a MPU9250 sensor which is read by the µController through I2B bus. Weird enough: RxByte receives negative values (how that - being a byte ??) and the "88" should actually be displayed by the Trackbar (it should flicker between 88 and the x-value), but it doesn't !
Now the compiler is happy, but me not !
<Thomas>
Code: Select all
EnableExplicit
#WindowColor=$F0F0F0
Procedure rs232()
Protected RxByte.b
NewList uavdata.b()
While AvailableSerialPortInput(0)
If ReadSerialPortData(0,@RxByte,1) = 1
AddElement(uavdata())
uavdata()=RxByte
EndIf
Wend
ForEach uavdata()
SetGadgetState(1,uavdata())
Debug uavdata()
Next
EndProcedure
Define flags = #PB_Window_ScreenCentered|#PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_MaximizeGadget|#PB_Window_SizeGadget
OpenWindow(0,0,0,450,350,"RS-232",flags)
WindowBounds(0,150,150, #PB_Ignore, #PB_Ignore)
SetWindowColor(0,#WindowColor)
TextGadget(0,5,10,48,20, "rx-data:", #PB_Text_Center)
TrackBarGadget (1, 55, 10, 305, 30, 0, 255)
If OpenSerialPort(0,"COM17", 57600,#PB_SerialPort_NoParity,8,1,#PB_SerialPort_NoHandshake,512,512)=0
MessageRequester("ComPortError","ComPort not initialized")
End
EndIf
AddWindowTimer(0,0,50)
Repeat
Select WaitWindowEvent()
Case #PB_Event_Timer: rs232()
Case #PB_Event_CloseWindow:CloseSerialPort(0):End
EndSelect
ForEver
Now the compiler is happy, but me not !
<Thomas>