Hi All,
This is probably a simple question to answer, but some advice would be appreciated. I have a small board with an FTDI input chip and a 16F687 processor. This is intended for controlling some small servos in an optical device and expects to receive blocks of 7 characters at intervals from the PC. These character strings are typically something like 'MN00010' and are decoded to provide direction and speed information. The problem is that I have used some of the GC demo examples, but they all seem to receive single characters, rather than strings. Can I easily receive a 7 character string at each download?
Thanks for any solutions!
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
For receiving the track count from a DfPlayer MP3 module, I use this:
#Chip16F1829,32#DefineSer_InPortA.3#DefineSerDFPortA.5#DefineSendAHighSetSerDFOn'Serial Out (-) Pin2 Pin2 DFPlayer#DefineSendALowSetSerDFOff'Serial Out (-) Pin2 Pin2 DFPlayer#DefineRecAHighSer_InOn'Serial In (-) Pin4 Pin3 DFPlayer#DefineRecALowSer_InOff'Serial In (-) Pin4 Pin3 DFPlayerInitSer1,r9600,1+WaitForStart,8,1,none,normalSendAHigh'Idle HighDimSerData(10)'As ArrayDimReturnTracksAsWordSubSerial_FetchLetReturnTracks=0SerReceive1,SerData(1)'0x7eSerReceive1,SerData(2)'0xffSerReceive1,SerData(3)'0x06SerReceive1,SerData(4)SerReceive1,SerData(5)SerReceive1,SerData(6)'High Byte of track countSerReceive1,SerData(7)'Low Byte of track countSerReceive1,SerData(8)'0xefIfSerData(6)>0ThenLetReturnTracks=SerData(6)LetReturnTracks=ReturnTracks*256'High ByteEndIfIfSerData(7)>0ThenLetReturnTracks=ReturnTracks+SerData(7)'Low ByteEndIfEndSub
As you can see, this returns 8 bytes of data which are placed in the array SerData(), so maybe you could use something similar for your 7 bytes? It has worked reliably for me. The entire code for the program is posted in the finished projects area, as my MP3 mini jukebox project if this doesn't make a deal of sense by itself.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Since your device has a USART, you can use HSerGetString to receive strings. Usage is described in the Help File under: Command Reference >> Serial Communication >> RS232 ( hardware) >> HserGetString. The string being sent must be terminated with a Carriage Return.
There is an example provided in the Help File.
William
Last edit: William Roth 2022-12-11
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi William (and mkstevo),
Thanks for the ideas - it looks like the HSerGetString command will do the trick. I'm now seeing the correct responses from the board.
Many thanks!
Terry
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi All,
This is probably a simple question to answer, but some advice would be appreciated. I have a small board with an FTDI input chip and a 16F687 processor. This is intended for controlling some small servos in an optical device and expects to receive blocks of 7 characters at intervals from the PC. These character strings are typically something like 'MN00010' and are decoded to provide direction and speed information. The problem is that I have used some of the GC demo examples, but they all seem to receive single characters, rather than strings. Can I easily receive a 7 character string at each download?
Thanks for any solutions!
For receiving the track count from a DfPlayer MP3 module, I use this:
As you can see, this returns 8 bytes of data which are placed in the array SerData(), so maybe you could use something similar for your 7 bytes? It has worked reliably for me. The entire code for the program is posted in the finished projects area, as my MP3 mini jukebox project if this doesn't make a deal of sense by itself.
@Terry Platt
Since your device has a USART, you can use HSerGetString to receive strings. Usage is described in the Help File under: Command Reference >> Serial Communication >> RS232 ( hardware) >> HserGetString. The string being sent must be terminated with a Carriage Return.
There is an example provided in the Help File.
William
Last edit: William Roth 2022-12-11
Hi William (and mkstevo),
Thanks for the ideas - it looks like the HSerGetString command will do the trick. I'm now seeing the correct responses from the board.
Many thanks!
Terry