zpua:
'
Have you figured this out yet?
'
Its pretty simple with the PST.
'
P.S. there is a difference between a single phone # and a Tampa phone book listing.
During the second iteration of the REPEAT loop DataFileCharacter[0] will contain the number 2 from the value of 1234 and DataValueOne will be equal to 1.
So it would be something like this:
DataValueOne := 1(DataValueOne's value form first iteration) * 10 + 2(character within DataFileCharacter[0]) - "0" (NULL terminating character)
DataValueOne := 1 * 10 + (2 - "0")
Since DataFile.dat is compiled, the program is stored in EEPROM (memory). Upon boot, the program is loaded, so in reality, at that point, it is already in the Propeller, but it has not been read by your program. The code below, providing that it works properly, will read DataFile.dat and fill DataFileCharacter[0] which can in turn be used by your program.
I understand what you trying to say. The code is running, but my PST still show nothing. What if I have 0.1234 in my notepad? Any changes needed on the code?
The code is running, but my PST still show nothing.
Like I previously mentioned, I have no way of testing it. I am sure it is something simple. I don't believe that FullDuplexSerial defines the constant CLS, so eliminate the following line:
Debug.Tx(Debug#CLS)
Yes, that decimal point is unaccounted for in the code I provided.
DataFile.dat should contain nothing but numbers upto 2147483647
Make sure the baud rate within the serial terminal is 115200 or alter the source code accordingly to match the baud rate you are using.
CON
_CLKMODE = XTAL1 + PLL16X
_XINFREQ = 5_000_000
DAT
Data FILE "DataFile.dat"
Str byte 0 'If this file is not NULL terminated, we need to add a 0
OBJ
Debug:"FullDuplexSerial"
VAR
LONG DataValueOne
BYTE DataFileCharacter[1]
PUB GetDataAndCompare | Index, ComparisonValue
ComparisonValue := 2_147_483_647 'Maximum value for LONG type declarations
Debug.Start(31, 30, 0, 115_200)
WAITCNT(CLKFREQ * 2 + CNT)
Index := 0
REPEAT
DataFileCharacter[0] := BYTE[Data][Index++] 'This is an individual character
DataValueOne := DataValueOne * 10 + (DataFileCharacter[0] - "0")
WHILE Temp > 0
Debug.Dec(ComparisonValue)
Debug.Tx(13) {Carriage Return}
Debug.Dec(DataValueOne)
Debug.Tx(13) {Carriage Return}
IF DataValueOne == ComparisonValue
Debug.Str(STRING("These values are equal"))
ELSE
Debug.Str(STRING("These values are unequal"))
All of my data in DataFile.dat are in decimal points. Should I need to put in floating point in the code?
My data does not consist 602. So I am not really sure why is it displaying 502.
Like I said, you must start with the basics, you are trying to dive right in. First put one number(without decimals) in the file to see if the code works properly. 2147483647 would be a good number, because if they come out equal, you know the code is working 100%.
The following code will work perfectly. However, there is an easier way to do this, but to be perfectly honest, I forget how it is done. Of course this is just an example of using the FILE directive. I hope this helps.
Bruce
CON
_CLKMODE = XTAL1 + PLL16X
_XINFREQ = 5_000_000
DAT
Data FILE "DataFile.dat"
Str BYTE 0 'If this file is not NULL terminated, we need to add a 0
OBJ
Debug:"FullDuplexSerial"
VAR
LONG DataValueOne
BYTE DataFileCharacter[1]
PUB GetDataAndCompare | Index, ComparisonValue
ComparisonValue := 2_147_483_647 'Maximum value for LONG type declarations
Debug.Start(31, 30, 0, 115_200)
WAITCNT(CLKFREQ * 2 + CNT)
Index := 0
DataValueOne := 0
REPEAT
DataFileCharacter[0] := Data[Index++] 'This is an individual character
IF DataFileCharacter[0] == 48 '0 Character
DataValueOne := (DataValueOne * 10) + 0
IF DataFileCharacter[0] == 49 '1 Character
DataValueOne := (DataValueOne * 10) + 1
IF DataFileCharacter[0] == 50 '2 Character
DataValueOne := (DataValueOne * 10) + 2
IF DataFileCharacter[0] == 51 '3 Character
DataValueOne := (DataValueOne * 10) + 3
IF DataFileCharacter[0] == 52 '4 Character
DataValueOne := (DataValueOne * 10) + 4
IF DataFileCharacter[0] == 53 '5 Character
DataValueOne := (DataValueOne * 10) + 5
IF DataFileCharacter[0] == 54 '6 Character
DataValueOne := (DataValueOne * 10) + 6
IF DataFileCharacter[0] == 55 '7 Character
DataValueOne := (DataValueOne * 10) + 7
IF DataFileCharacter[0] == 56 '8 Character
DataValueOne := (DataValueOne * 10) + 8
IF DataFileCharacter[0] == 57 '9 Character
DataValueOne := (DataValueOne * 10) + 9
WHILE DataFileCharacter > 0
Debug.Dec(ComparisonValue)
Debug.Tx(13) {Carriage Return}
Debug.Dec(DataValueOne)
Debug.Tx(13) {Carriage Return}
IF DataValueOne == ComparisonValue
Debug.Str(STRING("These values are equal"))
ELSE
Debug.Str(STRING("These values are unequal"))
Here is a spin file and a visual basic file that will communicate with each other.
I used an LED on the Demo board to indicate data value matches. The visual basic window is used to send data and to receive data from the demo board. These are very simple files, only a few lines long.
I hoped the visual basic would demonstrate the possibilities for communication between a PC and the demo board.
Having Visual Basic read files (text) off you hard drive and send it out the serial port is not to difficult.
I don't know about using floating point decimals in the propeller.I do every thing with integers.
I'm afraid that the Visual Basic files will not run on your machine.
I don't know how to share VB projects. Perhaps Bruce can shed some light on this.
It was easy as opening an existing project, I just needed to find the right file.
I did include the setup file that will install the communications program on your system. You will find it in the publish folder.
This post contains an attached working example of the FILE directive. Additionally, this example is better than my previous post, because the REPEAT loop utilizes the NEXT command for faster iterations.
In the attachment below, DataFile.dat contains a single whole number which is 2147483647. During execution, the Propeller will compare the value of the number uploaded in DataFile.dat to that of a local variable in the Spin code, being the ComparisonValue, which is also 2147483647.
Did you get the working example run perfectly? I have not yet.
The example assumes a baud rate of 115200. You may have to adjust the baud rate in the example, the Parallax Serial Terminal, or port settings. Additionally, you may have to specify the proper port.
After all my pontificating, I decided I'd better try it myself. 'Turns out, it's not as easy as I thought it would be. The problem is that, even with handshaking turned off, the printer driver toggles DTR, which resets the Propeller. Unfortunately, I know of no way around this problem.
-Phil
Place a switch or button between the propeller and the DTR line. This way you can program the prop by holding down the button. It works great.
Comments
I just went back on found Bean's post.
Phil's post shows how to implement Bean's idea.
This forum is great. I learn a lot use information here.
Duane
Yea, yea, yea.... Just let me know if my code works.
http://forums.parallax.com/showthread.php?133885-Get-data-from-Notepad-into-Propeller&p=1028349&viewfull=1#post1028349
'
Have you figured this out yet?
'
Its pretty simple with the PST.
'
P.S. there is a difference between a single phone # and a Tampa phone book listing.
-Phil
http://forums.parallax.com/showthread.php?133923-DEMO-Microsoft-Word-2010-gt-Propeller-communication
May I know what does this line code trying to do?
DataValueOne := DataValueOne * 10 + (DataFileCharacter[0] - "0")
And is DataFileCharacter[0] is being sent into propeller?
Thank you.
It has actually been a while since I wrote that formula, but I will do my best to explain it.
Let's say that the file DataFile.dat contains the number 1234 and that DataValueOne initially has a value of 0.
During the first iteration of the REPEAT loop DataFileCharacter[0] will contain the number 1 from the value of 1234.
So it would be something like this:
DataValueOne := 0 * 10 + (1 - "0")
So it would be something like this:
DataValueOne := 1 * 10 + (2 - "0")
I understand what you trying to say. The code is running, but my PST still show nothing. What if I have 0.1234 in my notepad? Any changes needed on the code?
Like I previously mentioned, I have no way of testing it. I am sure it is something simple. I don't believe that FullDuplexSerial defines the constant CLS, so eliminate the following line:
DataFile.dat should contain nothing but numbers upto 2147483647
Make sure the baud rate within the serial terminal is 115200 or alter the source code accordingly to match the baud rate you are using.
Additionally, the following line should be changed from:
to:
Attached file is my data and what I got in my Serial Terminal. It seems odd to me. Thanks
My data does not consist 602. So I am not really sure why is it displaying 502.
Like I said, you must start with the basics, you are trying to dive right in. First put one number(without decimals) in the file to see if the code works properly. 2147483647 would be a good number, because if they come out equal, you know the code is working 100%.
Bruce
- Support more than one number in DataFile.dat
- Support decimal points
Hopefully I have provided you with a good starting point.I changed to only 2147483647 in my DataFile but it displayed:
2147483647
1623048008
These values are unequal
Yeah, it's a good starting for me. Thanks a lot.
I have not figured it out completely just yet, but I got it working to a certain extent. It is putting correct ASCII values. I will get back to you.
The following code will work perfectly. However, there is an easier way to do this, but to be perfectly honest, I forget how it is done. Of course this is just an example of using the FILE directive. I hope this helps.
Bruce
I used an LED on the Demo board to indicate data value matches. The visual basic window is used to send data and to receive data from the demo board. These are very simple files, only a few lines long.
I hoped the visual basic would demonstrate the possibilities for communication between a PC and the demo board.
Having Visual Basic read files (text) off you hard drive and send it out the serial port is not to difficult.
I don't know about using floating point decimals in the propeller.I do every thing with integers.
It was easy as opening an existing project, I just needed to find the right file.
I did include the setup file that will install the communications program on your system. You will find it in the publish folder.
The previously Zipped folder was missing the SPIN code.
Propeller to Visual Basic.zip
This post contains an attached working example of the FILE directive. Additionally, this example is better than my previous post, because the REPEAT loop utilizes the NEXT command for faster iterations.
In the attachment below, DataFile.dat contains a single whole number which is 2147483647. During execution, the Propeller will compare the value of the number uploaded in DataFile.dat to that of a local variable in the Spin code, being the ComparisonValue, which is also 2147483647.
Bruce
Did you get the working example run perfectly? I have not yet. I am not sure why. May I know what is number 48, 49, 50 and so on doing?
Thank you.
Yes, that latest example should work perfectly.
The example assumes a baud rate of 115200. You may have to adjust the baud rate in the example, the Parallax Serial Terminal, or port settings. Additionally, you may have to specify the proper port.
Place a switch or button between the propeller and the DTR line. This way you can program the prop by holding down the button. It works great.